Search code examples
c#.netloggingopen-telemetry

Should I replace logging by ActivitySource AddEvent using opentelemetry?


I have a ASP.NET MVC web application which logs with EventSource as input and ElasticSearch or application insights as output based on configuration with azure/eventflow library.

I am going to add tracing with opentelemetry.

What is difference between log.information and ActivitySource.AddEvent ?

Should I log messages with AddEvent ?


Solution

  • There are advantages therefore it comes down to what you're trying to do with observing these in production, system load and you observability backends capabilities.

    Activity/Span events are part of the tracing signal and are transmitted when those are sent. That means a few things:

    • they can only be sent when you have a span
    • they're discarded as part of sampling

    They are however:

    • Structured first (not built for human readability)
    • lightweight
    • explicitly part of a trace

    Logs are a separate signal, with their own pipeline, and therefore outside of the sampling decisions of the traces.

    They

    • are built for humans to read
    • have trace context fields where available

    However not being structured first means that you end up with lighter context, since all the fields you want to include need to be part of the message. It's not easy to include semantic conventions around the naming of your fields so you end up with more work downstream to sanitize and normalise that data.

    My experience is that you can move to ActivityEvent for everything, however, it does require that you change the way you develop locally (using things like the aspire dashboard for debugging locally). If you don't want to make those workflow changes, you should think about putting all you production information in your Activity/ActivityEvent, and reserve logging for mostly local visibility.