Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventBus.publish() does not propagate context #300

Open
damianopezzotti opened this issue Jul 14, 2022 · 0 comments
Open

EventBus.publish() does not propagate context #300

damianopezzotti opened this issue Jul 14, 2022 · 0 comments

Comments

@damianopezzotti
Copy link

Basic information

  • Axon Framework version: 4.5.9
  • JDK version: 11.0.13
  • Tracing Extension version: 4.5.2
  • Complete executable reproducer if available (e.g. GitHub Repo):

Steps to reproduce

We have Application A that has its tracing context that publish an event using EventBus.
This event is handled by Application B, that does not continue with Application A context but starts a new tracing context.

The problem is that the OpenTraceDispatchInterceptor doesn't intercept the EventBus.publish() call and then does not extract
tracingId from tracing context and does not add metadata to published event.

As workaround, we insert manually the header in the published message.

Our code below:

@AllArgsConstructor
public class SyncEventPublisherAxon implements SyncEventPublisher {

   private final EventBus eventBus;
   private final Tracer tracer;

   @Override
   public void publish( final SyncEvent event ) {
      eventBus.publish( message( event ) );

   }

   protected GenericEventMessage<SyncEvent> message( final SyncEvent syncEvent ) {
      final ScopeManager scopeManager = tracer.scopeManager();
      final Optional<SpanContext> spanContextOptional = Optional.ofNullable( scopeManager )
            .map( ScopeManager::activeSpan )
            .map( Span::context );

      final GenericEventMessage<SyncEvent> message = new GenericEventMessage<>( syncEvent );
      return spanContextOptional.map( ( spanContext ) -> {
         MapInjector injector = new MapInjector();
         this.tracer.inject( spanContext, Format.Builtin.TEXT_MAP, injector );
         return message.andMetaData( injector.getMetaData() );
      } ).orElseGet( () -> message );
   }

}

Expected behaviour

We expect that OpenTracing context 'continues' between applications.

Actual behaviour

Event published in the EventStore by Application A does not contains jaeger uber-trace-id metadata and then Application B starts a new context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant