Skip to content

Commit d64f8ef

Browse files
committed
refactor(telemetry): move span builder helpers from CommandedAttributes to Helpers
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1 parent f5c3452 commit d64f8ef

4 files changed

Lines changed: 49 additions & 48 deletions

File tree

lib/commanded/opentelemetry/commanded_attributes.ex

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
defmodule Commanded.OpenTelemetry.CommandedAttributes do
2-
alias OpenTelemetry.SemConv.Incubating.MessagingAttributes
3-
42
@moduledoc """
53
OpenTelemetry span attribute names for Commanded.
64
@@ -202,48 +200,4 @@ defmodule Commanded.OpenTelemetry.CommandedAttributes do
202200
@spec eventstore_stream_delete_type() :: :"eventstore.stream.delete_type"
203201
def eventstore_stream_delete_type, do: :"eventstore.stream.delete_type"
204202

205-
def maybe_add_operation_type(attrs, nil), do: attrs
206-
207-
def maybe_add_operation_type(attrs, type),
208-
do: [{MessagingAttributes.messaging_operation_type(), type} | attrs]
209-
210-
def maybe_add_destination_name(attrs, nil), do: attrs
211-
212-
def maybe_add_destination_name(attrs, name),
213-
do: [{MessagingAttributes.messaging_destination_name(), name} | attrs]
214-
215-
def maybe_add_stream_uuid(attrs, nil), do: attrs
216-
217-
def maybe_add_stream_uuid(attrs, uuid),
218-
do: [{commanded_stream_uuid(), uuid} | attrs]
219-
220-
def maybe_add_expected_version(attrs, nil), do: attrs
221-
222-
def maybe_add_expected_version(attrs, version),
223-
do: [{commanded_expected_version(), version} | attrs]
224-
225-
def maybe_add_event_count(attrs, nil), do: attrs
226-
227-
def maybe_add_event_count(attrs, count),
228-
do: [{commanded_event_count(), count} | attrs]
229-
230-
def maybe_add_subscription_name(attrs, nil), do: attrs
231-
232-
def maybe_add_subscription_name(attrs, name) do
233-
[
234-
{MessagingAttributes.messaging_destination_subscription_name(), name},
235-
{commanded_subscription_name(), name}
236-
| attrs
237-
]
238-
end
239-
240-
def maybe_add_source_uuid(attrs, nil), do: attrs
241-
242-
def maybe_add_source_uuid(attrs, uuid),
243-
do: [{commanded_source_uuid(), uuid} | attrs]
244-
245-
def to_destination_name(nil), do: nil
246-
def to_destination_name(name) when is_binary(name), do: name
247-
def to_destination_name(name) when is_atom(name), do: inspect(name)
248-
def to_destination_name(_), do: nil
249203
end

lib/commanded/opentelemetry/event_store.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule Commanded.OpenTelemetry.EventStore do
99
alias OpenTelemetry.SemConv.Incubating.MessagingAttributes
1010
alias OpenTelemetry.Span
1111

12-
import CommandedAttributes,
12+
import Helpers,
1313
only: [
1414
maybe_add_operation_type: 2,
1515
maybe_add_destination_name: 2,

lib/commanded/opentelemetry/event_store/adapters/event_store.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule Commanded.OpenTelemetry.EventStore.Adapters.EventStore do
88
alias OpenTelemetry.SemConv.Incubating.MessagingAttributes
99
alias OpenTelemetry.Span
1010

11-
import CommandedAttributes,
11+
import Helpers,
1212
only: [
1313
maybe_add_operation_type: 2,
1414
maybe_add_destination_name: 2,

lib/commanded/opentelemetry/helpers.ex

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule Commanded.OpenTelemetry.Helpers do
22
@moduledoc false
33

4+
alias Commanded.OpenTelemetry.CommandedAttributes
5+
alias OpenTelemetry.SemConv.Incubating.MessagingAttributes
46
alias OpenTelemetry.Span
57

68
def extract_propagated_ctx(nil), do: {[], :undefined}
@@ -108,4 +110,49 @@ defmodule Commanded.OpenTelemetry.Helpers do
108110

109111
def struct_name(%name{}), do: inspect(name)
110112
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
111158
end

0 commit comments

Comments
 (0)