Skip to content

amqplib add option/hook for base span #3008

@vabatta

Description

@vabatta

Is it possible to add an option or an hook for the default span created in

if (self._config.useLinksForConsume) {
const parentSpanContext = parentContext
? trace.getSpan(parentContext)?.spanContext()
: undefined;
parentContext = undefined;
if (parentSpanContext) {
links = [
{
context: parentSpanContext,
},
];
}
}
const span = self.tracer.startSpan(
`${queue} process`,
{
kind: SpanKind.CONSUMER,
attributes: {
...channel?.connection?.[CONNECTION_ATTRIBUTES],
[SEMATTRS_MESSAGING_DESTINATION]: exchange,
[SEMATTRS_MESSAGING_DESTINATION_KIND]:
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: msg.fields?.routingKey,
[SEMATTRS_MESSAGING_OPERATION]: MESSAGINGOPERATIONVALUES_PROCESS,
[SEMATTRS_MESSAGING_MESSAGE_ID]: msg?.properties.messageId,
[SEMATTRS_MESSAGING_CONVERSATION_ID]:
msg?.properties.correlationId,
},
links,
},
parentContext
);
as passing undefined as the parentContext makes it pick up the current active context, and an option to control that would be great.

If one uses useLinksForConsume, the span gets created under the previously active spanContext which might make things very hard for understanding where the span gets added (despite the links). It would be nice to add control over it, for example to set root: true so that the span creates a new trace that it is linked to the publish one.

For example, using @opentelemetry/instrumentation-nestjs-core all consumers with useLinksForConsume will end up in the Create Nest App (

const span = tracer.startSpan('Create Nest App', {
attributes: {
...NestInstrumentation.COMMON_ATTRIBUTES,
[AttributeNames.TYPE]: NestType.APP_CREATION,
[AttributeNames.VERSION]: moduleVersion,
[AttributeNames.MODULE]: nestModule.name,
},
});
) which doesn't really make sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions