I have an ASP.NET Core Web API running in k8. The pipeline is configured to use OpenTelemetry injecting AutoInstrumentation
.
I need to add extra information about the user in every log of the requests. I created a middleware that add it something similar to this:
using (_logger.BeginScope(new Dictionary<string, object>
{
{ "username", "some username" }
}))
{
await _next(context);
}
The problem is that the attribute is not sent to the OT collector when running in k8.
I tested locally adding the OT nuget packages and the middleware works well, I can see the value in the console (using ConsoleExporter
). The OpenTelemetry documentation explains that you need set IncludeScope
logging property at registration time like this:
builder.Logging.AddOpenTelemetry(logging =>
{
...
logging.IncludeScopes = true;
logging.IncludeFormattedMessage = true;
}
The issue is that there is no documentation for the AutoInstrumentation
. Someone can point me on how to do it?