@@ -128,26 +128,10 @@ func (e *Event) SubscribeLinkCreated(ctx context.Context, log logger.Logger, reg
128128 }
129129
130130 // Handle event - event is already typed as *linkpb.LinkCreated
131- // Create consumer span for event processing from Kafka message
132- // This span will be child of the parent span from Kafka headers (extracted by msg.Context())
133- consumerCtx , consumerSpan := otel .Tracer ("metadata.mq" ).Start (msgCtx , linkCreatedEvent + " receive" ,
134- trace .WithSpanKind (trace .SpanKindConsumer ),
135- )
136- defer consumerSpan .End ()
137-
138- consumerSpan .SetAttributes (
139- attribute .String ("messaging.system" , "kafka" ),
140- attribute .String ("messaging.destination.name" , linkCreatedEvent ),
141- attribute .String ("messaging.destination.kind" , "topic" ),
142- attribute .String ("messaging.message.id" , msg .UUID ),
143- attribute .String ("messaging.operation" , "receive" ),
144- attribute .String ("link.hash" , event .GetHash ()),
145- attribute .String ("link.url" , event .GetUrl ()),
146- )
147-
148- // Create metadata.process span as child of consumer span
149- // This ensures proper trace hierarchy: consumer span -> metadata.process -> saga
150- processCtx , processSpan := otel .Tracer ("metadata.uc" ).Start (consumerCtx , "metadata.process" ,
131+ // msgCtx already contains the consumer span created automatically by otelsarama
132+ // Create metadata.process span as child of the automatic consumer span
133+ // This ensures proper trace hierarchy: automatic consumer span -> metadata.process -> saga
134+ processCtx , processSpan := otel .Tracer ("metadata.uc" ).Start (msgCtx , "metadata.process" ,
151135 trace .WithSpanKind (trace .SpanKindInternal ),
152136 )
153137 defer processSpan .End ()
@@ -157,12 +141,12 @@ func (e *Event) SubscribeLinkCreated(ctx context.Context, log logger.Logger, reg
157141 attribute .String ("link.hash" , event .GetHash ()),
158142 )
159143
160- // Pass processCtx (which contains both consumer and process spans ) to handleLinkCreated
144+ // Pass processCtx (which contains the automatic consumer span and process span ) to handleLinkCreated
161145 handleErr := e .handleLinkCreated (processCtx , event , log ) //nolint:contextcheck // metadata handling depends on message context
162146 if handleErr != nil {
163147 processSpan .RecordError (handleErr )
164148 processSpan .SetStatus (otelcodes .Error , handleErr .Error ())
165- // consumerSpan will automatically reflect error status from child span
149+ // Automatic consumer span will automatically reflect error status from child span
166150 var domainErr * domainerrors.Error
167151 if errors .As (handleErr , & domainErr ) {
168152 dto := infraerrors .FromDomainError ("metadata.mq.link_created" , domainErr )
@@ -193,7 +177,7 @@ func (e *Event) SubscribeLinkCreated(ctx context.Context, log logger.Logger, reg
193177 }
194178
195179 processSpan .SetStatus (otelcodes .Ok , "Metadata processed successfully" )
196- // consumerSpan status is automatically derived from child span
180+ // Automatic consumer span status is automatically derived from child span
197181 msg .Ack ()
198182 }
199183 }(ctx )
@@ -203,8 +187,8 @@ func (e *Event) SubscribeLinkCreated(ctx context.Context, log logger.Logger, reg
203187
204188// handleLinkCreated processes LinkCreated events
205189// Event is typed as *linkpb.LinkCreated
206- // Note: metadata.process span is already created in SubscribeLinkCreated as child of consumer span
207- // This function receives ctx that contains both consumer and metadata.process spans
190+ // Note: metadata.process span is already created in SubscribeLinkCreated as child of automatic consumer span
191+ // This function receives ctx that contains the automatic consumer span and metadata.process span
208192func (e * Event ) handleLinkCreated (ctx context.Context , event * linkpb.LinkCreated , log logger.Logger ) error {
209193 linkURL := event .GetUrl ()
210194 if linkURL == "" {
0 commit comments