|
1 | 1 | defmodule Commanded.OpenTelemetry.Helpers do |
2 | 2 | @moduledoc false |
3 | 3 |
|
| 4 | + alias Commanded.OpenTelemetry.CommandedAttributes |
| 5 | + alias OpenTelemetry.SemConv.Incubating.MessagingAttributes |
4 | 6 | alias OpenTelemetry.Span |
5 | 7 |
|
6 | 8 | def extract_propagated_ctx(nil), do: {[], :undefined} |
@@ -108,4 +110,49 @@ defmodule Commanded.OpenTelemetry.Helpers do |
108 | 110 |
|
109 | 111 | def struct_name(%name{}), do: inspect(name) |
110 | 112 | def struct_name(_), do: nil |
| 113 | + |
| 114 | + def maybe_add_operation_type(attrs, nil), do: attrs |
| 115 | + |
| 116 | + def maybe_add_operation_type(attrs, type), |
| 117 | + do: [{MessagingAttributes.messaging_operation_type(), type} | attrs] |
| 118 | + |
| 119 | + def maybe_add_destination_name(attrs, nil), do: attrs |
| 120 | + |
| 121 | + def maybe_add_destination_name(attrs, name), |
| 122 | + do: [{MessagingAttributes.messaging_destination_name(), name} | attrs] |
| 123 | + |
| 124 | + def maybe_add_stream_uuid(attrs, nil), do: attrs |
| 125 | + |
| 126 | + def maybe_add_stream_uuid(attrs, uuid), |
| 127 | + do: [{CommandedAttributes.commanded_stream_uuid(), uuid} | attrs] |
| 128 | + |
| 129 | + def maybe_add_expected_version(attrs, nil), do: attrs |
| 130 | + |
| 131 | + def maybe_add_expected_version(attrs, version), |
| 132 | + do: [{CommandedAttributes.commanded_expected_version(), version} | attrs] |
| 133 | + |
| 134 | + def maybe_add_event_count(attrs, nil), do: attrs |
| 135 | + |
| 136 | + def maybe_add_event_count(attrs, count), |
| 137 | + do: [{CommandedAttributes.commanded_event_count(), count} | attrs] |
| 138 | + |
| 139 | + def maybe_add_subscription_name(attrs, nil), do: attrs |
| 140 | + |
| 141 | + def maybe_add_subscription_name(attrs, name) do |
| 142 | + [ |
| 143 | + {MessagingAttributes.messaging_destination_subscription_name(), name}, |
| 144 | + {CommandedAttributes.commanded_subscription_name(), name} |
| 145 | + | attrs |
| 146 | + ] |
| 147 | + end |
| 148 | + |
| 149 | + def maybe_add_source_uuid(attrs, nil), do: attrs |
| 150 | + |
| 151 | + def maybe_add_source_uuid(attrs, uuid), |
| 152 | + do: [{CommandedAttributes.commanded_source_uuid(), uuid} | attrs] |
| 153 | + |
| 154 | + def to_destination_name(nil), do: nil |
| 155 | + def to_destination_name(name) when is_binary(name), do: name |
| 156 | + def to_destination_name(name) when is_atom(name), do: inspect(name) |
| 157 | + def to_destination_name(_), do: nil |
111 | 158 | end |
0 commit comments