You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Runtime version (e.g. net462, net48, netcoreapp3.1, net6.0 etc. You can
find this information from the *.csproj file):
net7.0
Symptom
While using 'AttachLogsToActivityEvent' to attach ILogger messages to Activity Events, actual formatted message or scopes or state values are not getting attached.
What is the expected behavior?
All the ILogger log messages should include actual formatted message or scopes or state is those are enabled as part of OpenTelemetryLoggerOptions
What is the actual behavior?
I can only see the default 3 CategoryName, LogLevel & EventId getting logged in console as part of the events
Reproduce
Here is the full Program.cs file (along with the csproj above)
using ApiVersioning.Examples;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OpenTelemetry;
using OpenTelemetry.Exporter;
using OpenTelemetry.Instrumentation.AspNetCore;
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
services.AddProblemDetails();
services.AddEndpointsApiExplorer();
services.AddApiVersioning(
options =>
{
options.ReportApiVersions = true;
})
.AddApiExplorer(
options =>
{
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
})
.EnableApiVersionBinding();
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
services.AddSwaggerGen(options => options.OperationFilter<SwaggerDefaultValues>());
builder.Services.Configure<AspNetCoreInstrumentationOptions>(options => options.RecordException = true);
var resource = ResourceBuilder.CreateDefault().AddService("MyService");
builder.Services
.AddOpenTelemetry()
.ConfigureResource(ConfigureResource)
.WithTracing(o =>
{
o.SetSampler(new TraceIdRatioBasedSampler(1.0))
.AddSource("MyService")
.AddAspNetCoreInstrumentation(option =>
{
option.RecordException = true;
})
.AddHttpClientInstrumentation();
o.AddConsoleExporter(o => o.Targets = ConsoleExporterOutputTargets.Console);
})
.StartWithHost();
builder.Logging.ClearProviders();
builder.Logging.Configure(o => o.ActivityTrackingOptions = ActivityTrackingOptions.SpanId
| ActivityTrackingOptions.TraceId
| ActivityTrackingOptions.ParentId);
builder.Logging.AddFilter<OpenTelemetryLoggerProvider>("*", LogLevel.Information);
builder.Logging
.AddOpenTelemetry(loggerOptions =>
{
loggerOptions.SetResourceBuilder(resource);
loggerOptions.IncludeFormattedMessage = true;
loggerOptions.IncludeScopes = true;
loggerOptions.ParseStateValues = true;
loggerOptions.AddConsoleExporter();
loggerOptions.AttachLogsToActivityEvent();
});
var app = builder.Build();
var common = app.NewVersionedApi("Common");
var commonV1 = common.MapGroup("/api/v{version:apiVersion}/common").HasApiVersion(1.0);
commonV1.MapGet("/", (ILogger<Program> logger) =>
{
logger.LogInformation("Calling hello worls api!");
return Results.Ok("Hello World common v1!");
});
app.UseSwagger();
app.UseSwaggerUI(
options =>
{
var descriptions = app.DescribeApiVersions();
foreach (var description in descriptions)
{
var url = $"/swagger/{description.GroupName}/swagger.json";
var name = description.GroupName.ToUpperInvariant();
options.SwaggerEndpoint(url, name);
}
});
app.Run();
static void ConfigureResource(ResourceBuilder r) => r.AddService(
serviceName: "MyService",
serviceVersion: "1.0.0",
serviceInstanceId: Environment.MachineName);
We will close this issue if:
The repro project you share with us is complex. We can't investigate custom
projects, so don't point us to such, please.
If we can not reproduce the behavior you're reporting.
Bug Report
List of all OpenTelemetry NuGet
packages and version that you are
using (e.g.
OpenTelemetry 1.0.2
):Runtime version (e.g.
net462
,net48
,netcoreapp3.1
,net6.0
etc. You canfind this information from the
*.csproj
file):Symptom
While using 'AttachLogsToActivityEvent' to attach ILogger messages to Activity Events, actual formatted message or scopes or state values are not getting attached.
What is the expected behavior?
All the ILogger log messages should include actual formatted message or scopes or state is those are enabled as part of OpenTelemetryLoggerOptions
What is the actual behavior?
I can only see the default 3 CategoryName, LogLevel & EventId getting logged in console as part of the events
Reproduce
Here is the full Program.cs file (along with the csproj above)
We will close this issue if:
projects, so don't point us to such, please.
Additional Context
Add any other context about the problem here.
Attached is the full project.
MinimalOpenApiWithOTLogger.zip
The text was updated successfully, but these errors were encountered: