asp.netopen-telemetryopen-telemetry-collector

Template the body for OpenTelemetry log events


I'm running a ASP .NET core application, using the dotnet opentelemetry client.

The application sends all events to an instance of OpenTelemetry Collector, that in its turn store the events in ElasticSearch and Prometheus.

Now, I get the log events in ElasticSearch and thus visible in Kibana.

One ES document body attribute could look like this

Executed action method {ActionName}, returned result {ActionResult} in {ElapsedMilliseconds}ms.

Can something in this chain be configured to apply this template with the attributes from the event, IE so I can read Executed action method Corp.Service.Controllers.Controller.StoreEvent (Corp.Service), returned result Microsoft.AspNetCore.Mvc.NoContentResult in 4.32ms. in the logs as well?


Solution

  • You need to configure the IncludeFormattedMessage parameter when setting up OpenTelemetry.

    For example:

    builder.Logging.AddOpenTelemetry(configure =>
    {
        configure.IncludeFormattedMessage = true;
        
        configure.AddConsoleExporter();
    });