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

Add CorrelationId to distributed events #16773

Closed
5 tasks done
hikalkan opened this issue Jun 7, 2023 · 0 comments · Fixed by #16795
Closed
5 tasks done

Add CorrelationId to distributed events #16773

hikalkan opened this issue Jun 7, 2023 · 0 comments · Fixed by #16795

Comments

@hikalkan
Copy link
Member

hikalkan commented Jun 7, 2023

The purpose is to attach current correlation id to distributed events, so we can relate events with HTTP requests and can trace all the related activities.

  • Attach the current correlation id (get using ICorrelationIdProvider.Get()) to distributed events as an additional property. This can be added to header of the message with provider's API. For example, RabbitMQ's BasicPublish method gets IBasicProperties which contains Headers while sending/receiving events. We can define a header and transfer the value with that header. Header name can be X-Correlation-Id as we already use it in HTTP headers.
  • Add correlation id to IncomingEventInfo and OutgoingEventInfo as an extra property (to the ExtraProperties collection) with the same header name (X-Correlation-Id).
  • Change current ICorrelationIdProvider implementations, so we can use the ambient context pattern (implemented with with AsyncLocal<T> internally) to set an arbitrary correlation id value with a using statement, just like we did at ICurrentPrincipalAccessor.Change. In this way, we can temporary override the current correlation id (it sets back to previous value after the using statement).
  • We will use the ICorrelationIdProvider.Change method while executing an incoming event. In this way, if we get the correlation id value inside our distributed event handler, we can get the value that is attached to the event. Also, if we make an HTTP call to another microservice, it will use the same correlation id value that is originally attached to the event by the sender.
  • We should also be able to get the correlation id value in global DistributedEventSent and DistributedEventReceived events. It should already work if we use ICorrelationIdProvider.Change before executing that local event (in the event handler, we can get from ICorrelationIdProvider.Get, no need to add value to the DistributedEventSent and DistributedEventReceived classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants