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

2
  • Try using put instead of get : HttpGet Commented Mar 27, 2023 at 15:57
  • @jdweng Same result Commented Mar 27, 2023 at 16:02

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

By creating a class TempoLogRecordProcessor : BaseProcessor<LogRecord>, 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 that is not a log - that's a span event - opentelemetry.io/docs/concepts/signals/traces/#span-events Are you sure that is supported feature in the Tempo/Grafana UI?
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 Logs to Loki sounds much more better grafana.com/blog/2021/02/11/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.