0

By following the .NET Getting started of OpenTelemetry documention I'm able to catch every traces in my Grafana Tempo docker. I can see my HTTP calls, my crashes and my database queries in my Grafana Tempo explorer.

To test it, I created 4 routes in my swagger.

routes

tempo

My problem is that I'm not able to see my manual logs sent with _logger.LogInformation("hello") while I see it in my console.

// My SendLogs endpoint
[HttpGet("SendLogs")]
public void SendLogs()
{
    _logger.LogInformation("Info log");
    _logger.LogTrace("Trace log");
    _logger.LogDebug("Debug log");
    _logger.LogWarning("Warning log");
    _logger.LogError("Error log");
    _logger.LogCritical("Critical log");
}
// Program.cs
//...
builder.Services.AddOpenTelemetry()
    .WithTracing(tracerProviderBuilder =>
        tracerProviderBuilder
            .AddSource(DiagnosticsConfig.ActivitySource.Name)
            .ConfigureResource(resource => resource.AddService(DiagnosticsConfig.ServiceName))
            .AddAspNetCoreInstrumentation(options =>
            {
                options.RecordException = true;
            })
            .AddConsoleExporter()
            .AddOtlpExporter()
            .AddNpgsql()
    )
    .WithMetrics(metricsProviderBuilder => 
        metricsProviderBuilder
            .ConfigureResource(resource => resource.AddService(DiagnosticsConfig.ServiceName))
            .AddAspNetCoreInstrumentation()
            //.AddConsoleExporter()
            .AddOtlpExporter()
    );

builder.Services.AddEntityFrameworkNpgsql().AddDbContext<ApiDbContext>(opt =>
{
    opt.UseNpgsql(builder.Configuration.GetConnectionString("SampleDbConnection"));
});

builder.Logging.ClearProviders();

ResourceBuilder resourceBuilder = ResourceBuilder.CreateDefault().AddService(DiagnosticsConfig.ServiceName);

builder.Logging.AddOpenTelemetry(options =>
{
    options
    .SetResourceBuilder(resourceBuilder)
    .AddConsoleExporter()
    .AddOtlpExporter();
});

builder.Services.Configure<OpenTelemetryLoggerOptions>(opt =>
{
    opt.IncludeScopes = true;
    opt.ParseStateValues = true;
    opt.IncludeFormattedMessage = true;
});
//...

My console correctly display my manual log, but I can't retrieve it in my Tempo

console

thibsc
  • 3,747
  • 2
  • 18
  • 38

1 Answers1

0

Tempo is trace storage/backend, so you can't push log (or metric) there. Anyway, Opentelemetry logging is in still in experimental stage, so majority implementations use still some older logging solutions.

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
  • By creating a `class TempoLogRecordProcessor : BaseProcessor`, I'm able to log it in the events section of the trace my `ILogger` calls by adding my class as a Processor in the `Program.cs` – thibsc Mar 27 '23 at 18:33
  • @thibsc that is not a `log` - that's a `span event` - https://opentelemetry.io/docs/concepts/signals/traces/#span-events Are you sure that is supported feature in the Tempo/Grafana UI? – Jan Garaj Mar 27 '23 at 22:36
  • No, I think a possible solution could be to send log to Grafana Loki and make the link between the loki log and tempo – thibsc Mar 28 '23 at 12:51
  • @thibsc Logs to Loki sounds much more better https://grafana.com/blog/2021/02/11/instrumenting-a-.net-web-api-using-opentelemetry-tempo-and-grafana-cloud/ – Jan Garaj Mar 28 '23 at 13:40