zarusz / SlimMessageBus

Lightweight message bus interface for .NET (pub/sub and request-response) with transport plugins for popular message brokers.
Apache License 2.0
447 stars 75 forks source link

Tracing / OpenTelemetry #149

Open Juandavi1 opened 1 year ago

Juandavi1 commented 1 year ago

Hi ! Do you know how to implement distributed tracing with slim ?

zarusz commented 1 year ago

Hi @Juandavi1 could you please elaborate?

Juandavi1 commented 1 year ago

Hi ! We are working with OpenTelemetry and we need to create the spans when consume and publish events. For example en Go we have otelsarama to do it ! There is an option to add an interceptor to add this functionality ?

zarusz commented 1 year ago

Now it is more clear, thanks. I assume you are using Kafka transport, is that correct?

There is nothing available out of box, ideally tracing/metrics/instrumentation could be done as a producer/consumer interceptors which would add the necessary spans (or other instrumentation) to the consumers or producer. The interceptor implementation could use one of these:

Regarding otelsarama I do not know it, but it looks like it's meant for Go client application. Not sure if this could be used in .NET.

I am happy to review a contribution/PR for a tracing plugin to make this part of SMB, or provide help.

Juandavi1 commented 1 year ago

Hi ! Awesome ! I was wondering whether there's a global interceptor 🤔 The currently interface requires a message type 🥲

zarusz commented 1 year ago

Actually, you can make a generic message interceptor as explained here https://github.com/zarusz/SlimMessageBus/blob/master/docs/intro.md#generic-interceptors

You can see this working for the outbox plugin https://github.com/zarusz/SlimMessageBus/blob/master/src/SlimMessageBus.Host.Outbox/Configuration/ServiceCollectionExtensions.cs#L12

Juandavi1 commented 1 year ago

I will try it! Thank you very much!

zarusz commented 10 months ago

The feature should be generating instrumentation using: https://www.nuget.org/packages/System.Diagnostics.DiagnosticSource https://learn.microsoft.com/en-us/dotnet/core/diagnostics/diagnosticsource-diagnosticlistener

When the extension is built it needs to follow this: https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/docs/trace/extending-the-sdk/README.md#instrumentation-library

zarusz commented 1 week ago

Another useful link https://github.com/prometheus-net/prometheus-net/blob/master/Benchmark.NetCore/SdkComparisonBenchmarks.cs