Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/commanded/aggregates/aggregate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ defmodule Commanded.Aggregates.Aggregate do
aggregate_state: struct(),
aggregate_version: non_neg_integer(),
caller: pid(),
execution_context: Commanded.Aggregates.ExecutionContext.t()}
execution_context: Commanded.Aggregates.ExecutionContext.t(),
registry_adapter: module()}
"""
})

Expand All @@ -28,6 +29,7 @@ defmodule Commanded.Aggregates.Aggregate do
aggregate_version: non_neg_integer(),
caller: pid(),
execution_context: Commanded.Aggregates.ExecutionContext.t(),
registry_adapter: module(),
events: [map()],
error: nil | any(),
wrong_expected_version_count: non_neg_integer()}
Expand Down Expand Up @@ -769,13 +771,16 @@ defmodule Commanded.Aggregates.Aggregate do

{pid, _ref} = from

{registry_adapter, _} = Commanded.Application.registry_adapter(application)

%{
application: application,
aggregate_uuid: aggregate_uuid,
aggregate_state: aggregate_state,
aggregate_version: aggregate_version,
caller: pid,
execution_context: context,
registry_adapter: registry_adapter,
wrong_expected_version_count: wrong_expected_version_count
Comment thread
yordis marked this conversation as resolved.
}
end
Expand Down
4 changes: 3 additions & 1 deletion lib/commanded/opentelemetry/aggregate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ defmodule Commanded.OpenTelemetry.Aggregate do
{CommandedAttributes.commanded_aggregate_version(), meta.aggregate_version},
{CommandedAttributes.commanded_command(), Helpers.struct_name(context.command)},
{CommandedAttributes.commanded_correlation_id(), context.correlation_id},
{CommandedAttributes.commanded_causation_id(), context.causation_id}
{CommandedAttributes.commanded_causation_id(), context.causation_id},
{CommandedAttributes.commanded_registry_adapter(),
Helpers.module_name(meta.registry_adapter)}
]

# OTel semconv: span name = "{operation.name} {destination.name}"
Expand Down
6 changes: 6 additions & 0 deletions lib/commanded/opentelemetry/commanded_attributes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,10 @@ defmodule Commanded.OpenTelemetry.CommandedAttributes do
"""
@spec commanded_handler_lag() :: :"commanded.handler.lag"
def commanded_handler_lag, do: :"commanded.handler.lag"

@doc """
The process registry adapter module (e.g. Commanded.Registration.GlobalRegistry).
"""
@spec commanded_registry_adapter() :: :"commanded.registry.adapter"
def commanded_registry_adapter, do: :"commanded.registry.adapter"
end
8 changes: 8 additions & 0 deletions test/opentelemetry/aggregate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ defmodule Commanded.OpenTelemetry.AggregateTest do
"commanded.command": "Commanded.TestSupport.TestDomain.OpenAccount",
"commanded.correlation_id": correlation_id,
"commanded.causation_id": causation_id,
"commanded.registry.adapter": "Commanded.Registration.LocalRegistry",
"commanded.event.count": 0
}
end
Expand Down Expand Up @@ -161,6 +162,7 @@ defmodule Commanded.OpenTelemetry.AggregateTest do
"commanded.command": "Commanded.Middleware.Commands.IncrementCount",
"commanded.causation_id": causation_id,
"commanded.correlation_id": correlation_id,
"commanded.registry.adapter": "Commanded.Registration.LocalRegistry",
"commanded.event.count": 1
}
end
Expand Down Expand Up @@ -223,6 +225,7 @@ defmodule Commanded.OpenTelemetry.AggregateTest do
"commanded.command": "Commanded.Middleware.Commands.IncrementCount",
"commanded.causation_id": causation_id1,
"commanded.correlation_id": correlation_id1,
"commanded.registry.adapter": "Commanded.Registration.LocalRegistry",
"commanded.event.count": 1
}

Expand Down Expand Up @@ -256,6 +259,7 @@ defmodule Commanded.OpenTelemetry.AggregateTest do
"commanded.command": "Commanded.Middleware.Commands.IncrementCount",
"commanded.causation_id": causation_id2,
"commanded.correlation_id": correlation_id2,
"commanded.registry.adapter": "Commanded.Registration.LocalRegistry",
"commanded.event.count": 1
}
end
Expand Down Expand Up @@ -314,6 +318,7 @@ defmodule Commanded.OpenTelemetry.AggregateTest do
"commanded.command": "Commanded.TestSupport.TestDomain.OpenAccount",
"commanded.correlation_id": correlation_id,
"commanded.causation_id": causation_id,
"commanded.registry.adapter": "Commanded.Registration.LocalRegistry",
"commanded.event.count": 0,
"error.type": "validation_failed"
}
Expand Down Expand Up @@ -359,6 +364,7 @@ defmodule Commanded.OpenTelemetry.AggregateTest do
"commanded.command": "Commanded.TestSupport.TestDomain.OpenAccount",
"commanded.correlation_id": context.correlation_id,
"commanded.causation_id": context.causation_id,
"commanded.registry.adapter": "Commanded.Registration.LocalRegistry",
"erlang.exception.kind": :error,
"error.type": "Elixir.ArgumentError"
}
Expand Down Expand Up @@ -404,6 +410,7 @@ defmodule Commanded.OpenTelemetry.AggregateTest do
"commanded.command": "Commanded.TestSupport.TestDomain.OpenAccount",
"commanded.correlation_id": context.correlation_id,
"commanded.causation_id": context.causation_id,
"commanded.registry.adapter": "Commanded.Registration.LocalRegistry",
"erlang.exception.kind": :error,
"error.type": "Elixir.RuntimeError"
}
Expand Down Expand Up @@ -596,6 +603,7 @@ defmodule Commanded.OpenTelemetry.AggregateTest do
"commanded.command": "Commanded.TestSupport.TestDomain.OpenAccount",
"commanded.correlation_id": correlation_id,
"commanded.causation_id": causation_id,
"commanded.registry.adapter": "Commanded.Registration.LocalRegistry",
"commanded.event.count": 0
}
end
Expand Down
3 changes: 2 additions & 1 deletion test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ defmodule Commanded.TestSupport.Factory do
aggregate_state: Keyword.fetch!(opts, :aggregate_state),
aggregate_version: Keyword.fetch!(opts, :aggregate_version),
caller: Keyword.fetch!(opts, :caller),
execution_context: Keyword.fetch!(opts, :execution_context)
execution_context: Keyword.fetch!(opts, :execution_context),
registry_adapter: Keyword.get(opts, :registry_adapter, Commanded.Registration.LocalRegistry)
}
end

Expand Down
Loading