Skip to content

Commit

Permalink
Best guess so far with attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
leggebroten committed Mar 16, 2022
1 parent 4a3aafb commit 87115bf
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 113 deletions.
21 changes: 11 additions & 10 deletions lib/commanded/aggregate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ defmodule OpentelemetryCommanded.Aggregate do
safe_context_propagation(context.metadata["trace_ctx"])

attributes = [
"messaging.system": "commanded",
"messaging.protocol": "cqrs",
"messaging.destination_kind": "aggregate",
"messaging.operation": "receive",
"commanded.aggregate_uuid": meta.aggregate_uuid,
"commanded.aggregate_version": meta.aggregate_version,
"commanded.application": meta.application,
"commanded.causation_id": context.causation_id,
"commanded.command": struct_name(context.command),
"commanded.correlation_id": context.correlation_id,
"commanded.function": context.function,
"messaging.conversation_id": context.correlation_id,
"messaging.destination": context.handler,
"messaging.destination_kind": "aggregate",
"messaging.message_id": context.causation_id,
"messaging.conversation_id": context.correlation_id,
"messaging.commanded.aggregate_uuid": meta.aggregate_uuid,
"messaging.commanded.aggregate_version": meta.aggregate_version,
"messaging.commanded.application": meta.application,
"messaging.commanded.command": struct_name(context.command),
"messaging.commanded.function": context.function
"messaging.operation": "receive",
"messaging.system": "commanded"
]

OpentelemetryTelemetry.start_telemetry_span(
Expand Down
17 changes: 9 additions & 8 deletions lib/commanded/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ defmodule OpentelemetryCommanded.Application do
safe_context_propagation(context.metadata["trace_ctx"])

attributes = [
"messaging.system": "commanded",
"messaging.protocol": "cqrs",
"messaging.destination_kind": "command_handler",
"messaging.operation": "receive",
"commanded.application": meta.application,
"commanded.causation_id": context.causation_id,
"commanded.command": struct_name(context.command),
"commanded.correlation_id": context.correlation_id,
"commanded.function": context.function,
"messaging.conversation_id": context.correlation_id,
"messaging.destination": context.handler,
"messaging.destination_kind": "command_handler",
"messaging.message_id": context.causation_id,
"messaging.conversation_id": context.correlation_id,
"messaging.commanded.application": meta.application,
"messaging.commanded.command": struct_name(context.command),
"messaging.commanded.function": context.function
"messaging.operation": "receive",
"messaging.system": "commanded"
]

OpentelemetryTelemetry.start_telemetry_span(
Expand Down
25 changes: 13 additions & 12 deletions lib/commanded/event_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,21 @@ defmodule OpentelemetryCommanded.EventHandler do
safe_context_propagation(recorded_event.metadata["trace_ctx"])

attributes = [
"messaging.system": "commanded",
"messaging.protocol": "cqrs",
"messaging.destination_kind": "event_handler",
"messaging.operation": "receive",
"messaging.message_id": recorded_event.causation_id,
"commanded.application": meta.application,
"commanded.causation_id": recorded_event.causation_id,
"commanded.correlation_id": recorded_event.correlation_id,
"commanded.event": recorded_event.event_type,
"commanded.event_id": recorded_event.event_id,
"commanded.event_number": recorded_event.event_number,
"commanded.handler_name": meta.handler_name,
"commanded.stream_id": recorded_event.stream_id,
"commanded.stream_version": recorded_event.stream_version,
"messaging.conversation_id": recorded_event.correlation_id,
"messaging.destination": meta.handler_module,
"messaging.commanded.application": meta.application,
"messaging.commanded.event": recorded_event.event_type,
"messaging.commanded.event_id": recorded_event.event_id,
"messaging.commanded.event_number": recorded_event.event_number,
"messaging.commanded.stream_id": recorded_event.stream_id,
"messaging.commanded.stream_version": recorded_event.stream_version,
"messaging.commanded.handler_name": meta.handler_name
"messaging.destination_kind": "event_handler",
"messaging.message_id": recorded_event.causation_id,
"messaging.operation": "receive",
"messaging.system": "commanded"
# TODO add back
# consistency: meta.consistency,
# TODO add this back into commanded
Expand Down
24 changes: 9 additions & 15 deletions lib/commanded/event_store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,22 @@ defmodule OpentelemetryCommanded.EventStore do
safe_context_propagation(event.metadata["trace_ctx"])

attributes = [
"messaging.system": "commanded",
"messaging.protocol": "cqrs",
"messaging.destination_kind": "event_store",
# TODO does this need to change based on the event? Or maybe `internal`?
"messaging.operation": "receive",
"messaging.message_id": event.causation_id,
"messaging.conversation_id": event.correlation_id,
# "messaging.destination": meta.handler_module,
"messaging.commanded.application": meta.application,
"messaging.commanded.event": event.event_type,
"messaging.commanded.event_id": event.event_id,
"messaging.commanded.event_number": event.event_number,
"messaging.commanded.stream_id": event.stream_id,
"messaging.commanded.stream_version": event.stream_version
"commanded.application": meta.application,
"commanded.causation_id": event.causation_id,
"commanded.correlation_id": event.correlation_id,
"commanded.event": event.event_type,
"commanded.event_id": event.event_id,
"commanded.event_number": event.event_number,
"commanded.stream_id": event.stream_id,
"commanded.stream_version": event.stream_version
]

OpentelemetryTelemetry.start_telemetry_span(
@tracer_id,
"commanded.event_store.#{action}",
meta,
%{
kind: :consumer,
kind: :internal,
attributes: attributes
}
)
Expand Down
27 changes: 14 additions & 13 deletions lib/commanded/process_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ defmodule OpentelemetryCommanded.ProcessManager do
safe_context_propagation(recorded_event.metadata["trace_ctx"])

attributes = [
"messaging.system": "commanded",
"messaging.protocol": "cqrs",
"messaging.destination_kind": "process_manager",
"messaging.operation": "receive",
"messaging.message_id": recorded_event.causation_id,
"commanded.application": meta.application,
"commanded.causation_id": recorded_event.causation_id,
"commanded.correlation_id": recorded_event.correlation_id,
"commanded.event": recorded_event.event_type,
"commanded.event_id": recorded_event.event_id,
"commanded.event_number": recorded_event.event_number,
"commanded.handler_name": meta.process_manager_name,
"commanded.process_uuid": meta.process_uuid,
"commanded.stream_id": recorded_event.stream_id,
"commanded.stream_version": recorded_event.stream_version,
"messaging.conversation_id": recorded_event.correlation_id,
"messaging.destination": meta.process_manager_module,
"messaging.commanded.application": meta.application,
"messaging.commanded.event": recorded_event.event_type,
"messaging.commanded.event_id": recorded_event.event_id,
"messaging.commanded.event_number": recorded_event.event_number,
"messaging.commanded.process_uuid": meta.process_uuid,
"messaging.commanded.stream_id": recorded_event.stream_id,
"messaging.commanded.stream_version": recorded_event.stream_version,
"messaging.commanded.handler_name": meta.process_manager_name
"messaging.destination_kind": "process_manager",
"messaging.message_id": recorded_event.causation_id,
"messaging.operation": "receive",
"messaging.system": "commanded"
# TODO add back
# consistency: meta.consistency,
# TODO add this back into commanded
Expand Down
19 changes: 10 additions & 9 deletions test/commanded/aggregate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule OpentelemetryCommanded.AggregateTest do

assert match?(
%{
"messaging.commanded.command": OpentelemetryCommanded.DummyApp.Commands.Ok
"commanded.command": OpentelemetryCommanded.DummyApp.Commands.Ok
},
attributes
)
Expand Down Expand Up @@ -66,7 +66,7 @@ defmodule OpentelemetryCommanded.AggregateTest do

assert match?(
%{
"messaging.commanded.command": OpentelemetryCommanded.DummyApp.Commands.Error
"commanded.command": OpentelemetryCommanded.DummyApp.Commands.Error
},
attributes
)
Expand Down Expand Up @@ -96,7 +96,7 @@ defmodule OpentelemetryCommanded.AggregateTest do

assert match?(
%{
"messaging.commanded.command":
"commanded.command":
OpentelemetryCommanded.DummyApp.Commands.RaiseException
},
attributes
Expand Down Expand Up @@ -130,17 +130,18 @@ defmodule OpentelemetryCommanded.AggregateTest do
defp has_basic_attributes!(attributes, correlation_id) do
assert match?(
%{
"messaging.commanded.aggregate_uuid": "ACC123",
"messaging.commanded.aggregate_version": 0,
"messaging.commanded.application": OpentelemetryCommanded.DummyApp.App,
"messaging.commanded.command": _,
"messaging.commanded.function": :handle,
"commanded.aggregate_uuid": "ACC123",
"commanded.aggregate_version": 0,
"commanded.application": OpentelemetryCommanded.DummyApp.App,
"commanded.causation_id": _,
"commanded.command": _,
"commanded.correlation_id": ^correlation_id,
"commanded.function": :handle,
"messaging.conversation_id": ^correlation_id,
"messaging.destination": OpentelemetryCommanded.DummyApp.Handler,
"messaging.destination_kind": "aggregate",
"messaging.message_id": _,
"messaging.operation": "receive",
"messaging.protocol": "cqrs",
"messaging.system": "commanded"
},
attributes
Expand Down
15 changes: 7 additions & 8 deletions test/commanded/application_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule OpentelemetryCommanded.ApplicationTest do
has_basic_attributes!(attributes, context.correlation_id)

assert match?(
%{"messaging.commanded.command": DummyApp.Commands.Ok},
%{"commanded.command": DummyApp.Commands.Ok},
attributes
)
end
Expand All @@ -61,7 +61,7 @@ defmodule OpentelemetryCommanded.ApplicationTest do
has_basic_attributes!(attributes, context.correlation_id)

assert match?(
%{"messaging.commanded.command": DummyApp.Commands.Error},
%{"commanded.command": DummyApp.Commands.Error},
attributes
)
end
Expand Down Expand Up @@ -107,7 +107,7 @@ defmodule OpentelemetryCommanded.ApplicationTest do
has_basic_attributes!(attributes, context.correlation_id)

assert match?(
%{"messaging.commanded.command": DummyApp.Commands.RaiseException},
%{"commanded.command": DummyApp.Commands.RaiseException},
attributes
)
end
Expand All @@ -116,14 +116,13 @@ defmodule OpentelemetryCommanded.ApplicationTest do
defp has_basic_attributes!(attributes, correlation_id) do
assert match?(
%{
"messaging.commanded.function": :handle,
"messaging.commanded.application": DummyApp.App,
"messaging.message_id": _,
"commanded.application": DummyApp.App,
"commanded.function": :handle,
"messaging.conversation_id": ^correlation_id,
"messaging.destination": DummyApp.Handler,
"messaging.destination_kind": "command_handler",
"messaging.conversation_id": ^correlation_id,
"messaging.message_id": _,
"messaging.operation": "receive",
"messaging.protocol": "cqrs",
"messaging.system": "commanded"
},
attributes
Expand Down
23 changes: 12 additions & 11 deletions test/commanded/event_handler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule OpentelemetryCommanded.EventHandlerTest do

assert match?(
%{
"messaging.commanded.event":
"commanded.event":
"Elixir.OpentelemetryCommanded.DummyApp.Events.OkEvent"
},
attributes
Expand Down Expand Up @@ -70,7 +70,7 @@ defmodule OpentelemetryCommanded.EventHandlerTest do

assert match?(
%{
"messaging.commanded.event":
"commanded.event":
"Elixir.OpentelemetryCommanded.DummyApp.Events.ErrorInEventHandlerEvent"
},
attributes
Expand Down Expand Up @@ -104,7 +104,7 @@ defmodule OpentelemetryCommanded.EventHandlerTest do

assert match?(
%{
"messaging.commanded.event":
"commanded.event":
"Elixir.OpentelemetryCommanded.DummyApp.Events.ExceptionInEventHandlerEvent"
},
attributes
Expand Down Expand Up @@ -138,19 +138,20 @@ defmodule OpentelemetryCommanded.EventHandlerTest do
defp has_basic_attributes!(attributes, correlation_id) do
assert match?(
%{
"messaging.commanded.application": OpentelemetryCommanded.DummyApp.App,
"commanded.application": OpentelemetryCommanded.DummyApp.App,
"commanded.causation_id": _,
"commanded.correlation_id": ^correlation_id,
"commanded.event_id": _,
"commanded.event_number": 1,
"commanded.handler_name": "EventHandler",
"commanded.stream_id": "ACC123",
"commanded.stream_version": 1,
"messaging.conversation_id": ^correlation_id,
"messaging.destination": OpentelemetryCommanded.DummyApp.EventHandler,
"messaging.destination_kind": "event_handler",
"messaging.message_id": _,
"messaging.operation": "receive",
"messaging.protocol": "cqrs",
"messaging.system": "commanded",
"messaging.commanded.event_id": _,
"messaging.commanded.event_number": 1,
"messaging.commanded.handler_name": "EventHandler",
"messaging.commanded.stream_id": "ACC123",
"messaging.commanded.stream_version": 1
"messaging.system": "commanded"
},
attributes
)
Expand Down
24 changes: 10 additions & 14 deletions test/commanded/event_store_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule OpentelemetryCommanded.EventStoreTest do
assert_receive {:span,
span(
name: "commanded.event_store.ack_event",
kind: :consumer,
kind: :internal,
parent_span_id: parent_span_id,
attributes: attributes
)}
Expand All @@ -36,7 +36,7 @@ defmodule OpentelemetryCommanded.EventStoreTest do

assert match?(
%{
"messaging.commanded.event":
"commanded.event":
"Elixir.OpentelemetryCommanded.DummyApp.Events.OkEvent"
},
attributes
Expand All @@ -47,18 +47,14 @@ defmodule OpentelemetryCommanded.EventStoreTest do
defp has_basic_attributes!(attributes, correlation_id) do
assert match?(
%{
"messaging.commanded.application": OpentelemetryCommanded.DummyApp.App,
"messaging.commanded.event_id": _,
"messaging.commanded.event_number": 1,
"messaging.commanded.stream_id": "ACC123",
"messaging.commanded.stream_version": 1,
"messaging.conversation_id": ^correlation_id,
"messaging.destination_kind": "event_store",
"messaging.message_id": _,
"messaging.operation": "receive",
"messaging.protocol": "cqrs",
"messaging.system": "commanded",
"messaging.commanded.event": _
"commanded.application": OpentelemetryCommanded.DummyApp.App,
"commanded.causation_id": _,
"commanded.correlation_id": ^correlation_id,
"commanded.event": _,
"commanded.event_id": _,
"commanded.event_number": 1,
"commanded.stream_id": "ACC123",
"commanded.stream_version": 1
},
attributes
)
Expand Down
Loading

0 comments on commit 87115bf

Please sign in to comment.