@@ -48,28 +48,18 @@ defmodule OpentelemetryCommanded.EventStore do
4848 end
4949
5050 def handle_start ( [ _ , _ , action , _type ] , _measurements , meta , _ ) do
51- event = meta . event
52-
53- safe_context_propagation ( event . metadata [ "trace_ctx" ] )
54-
55- attributes = [
56- "commanded.application": meta . application ,
57- "commanded.causation_id": event . causation_id ,
58- "commanded.correlation_id": event . correlation_id ,
59- "commanded.event": event . event_type ,
60- "commanded.event_id": event . event_id ,
61- "commanded.event_number": event . event_number ,
62- "commanded.stream_id": event . stream_id ,
63- "commanded.stream_version": event . stream_version
64- ]
51+ # TODO: how do we keep the trace context for telemetry events that don't have this value?
52+ if trace_ctx = get_in ( meta , [ :event , Access . key! ( :metadata ) , "trace_ctx" ] ) do
53+ safe_context_propagation ( trace_ctx )
54+ end
6555
6656 OpentelemetryTelemetry . start_telemetry_span (
6757 @ tracer_id ,
6858 "commanded.event_store.#{ action } " ,
6959 meta ,
7060 % {
7161 kind: :internal ,
72- attributes: attributes
62+ attributes: attributes ( action , meta )
7363 }
7464 )
7565 end
@@ -101,4 +91,26 @@ defmodule OpentelemetryCommanded.EventStore do
10191
10292 OpentelemetryTelemetry . end_telemetry_span ( @ tracer_id , meta )
10393 end
94+
95+ def attributes ( :ack_event , meta ) do
96+ event = meta . event
97+ [
98+ "commanded.application": meta . application ,
99+ "commanded.causation_id": event . causation_id ,
100+ "commanded.correlation_id": event . correlation_id ,
101+ "commanded.event": event . event_type ,
102+ "commanded.event_id": event . event_id ,
103+ "commanded.event_number": event . event_number ,
104+ "commanded.stream_id": event . stream_id ,
105+ "commanded.stream_version": event . stream_version
106+ ]
107+ end
108+
109+ def attributes ( telemetry_event , meta ) do
110+ # Generic default: put all scalar metadata in span attributes
111+ for { meta_key , meta_val } <- meta , is_binary ( meta_val ) or is_number ( meta_val ) , into: [ ] do
112+ { "commanded.#{ meta_key } " , meta_val }
113+ end
114+ end
115+
104116end
0 commit comments