opentracing-contrib / java-spring-rabbitmq

OpenTracing RabbitMQ instrumentation
Apache License 2.0
18 stars 21 forks source link

Should it be possible to setBaggageItem in decorator? #49

Closed mcrmfc closed 4 years ago

mcrmfc commented 4 years ago

Hi, I was attempting to do span.setBaggageItem("foo", "bar") in an extended decorator but noticed the header was not sent in the amqp message.

I see in the code this wouldn't work because of the ordering in doBefore (the tracer.inject happens before the spanDecorator.onSend is invoked).

  private Message doBefore(String exchange, String routingKey, Object message) {
    Message convertedMessage = convertMessageIfNecessary(message);

    final MessageProperties messageProperties = convertedMessage.getMessageProperties();

    // Add tracing header to outgoing AMQP message
    // so that new spans created on the AMQP message consumer side could be associated with span of current trace
    scope = RabbitMqTracingUtils.buildSendSpan(tracer, messageProperties);
    tracer.inject(
        scope.span().context(),
        Format.Builtin.TEXT_MAP,
        new RabbitMqInjectAdapter(messageProperties));

    // Add AMQP related tags to tracing span
    spanDecorator.onSend(messageProperties, exchange, routingKey, scope.span());

Is this intentional - and have I missed something?

Any help appreciated. Thanks.

ask4gilles commented 4 years ago

@mcrmfc Did you manage to fix it finally?