-
Notifications
You must be signed in to change notification settings - Fork 765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Lack of baggage in Logs #5943
[bug] Lack of baggage in Logs #5943
Comments
After a quick investigation the issue comes from this code : When not using enrichment/compliance, scope containing Baggage is of type However, when using enrichment/compliance, scope containing Baggage is of type Therefore, we're falling on the else case and it adds a weird key/value pairs with an empty key. There are two solutions possible:
|
Woops, sorry, forgot to add a title. |
Opened both solution PR |
I tested with the example at https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/examples/AspNetCore. by adding a baggage. The problem does not reproduce there, and I could see the baggage being exported successfully. What versions of .NET and the OpenTelemetry SDK were used for this test?
|
There is a link above which points out the issue: https://github.com/dotnet/extensions/blob/e18a05582e64603a0f2e2871bcf555e476570102/src/Libraries/Microsoft.Extensions.Telemetry/Logging/Import/LoggerFactoryScopeProvider.cs#L239
Interestingly there is one a few lines up which does it correctly: https://github.com/dotnet/extensions/blob/e18a05582e64603a0f2e2871bcf555e476570102/src/Libraries/Microsoft.Extensions.Telemetry/Logging/Import/LoggerFactoryScopeProvider.cs#L150 If you want to reproduce, do this: using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(logging =>
{
logging.IncludeScopes = true;
logging.AddConsoleExporter();
});
});
var logger = loggerFactory.CreateLogger<Program>();
using var scope1 = logger.BeginScope(new MyCustomScope1());
using var scope2 = logger.BeginScope(new MyCustomScope2());
logger.LogInformation("hello world");
internal sealed class MyCustomScope1 : IEnumerable<KeyValuePair<string, string?>>
{
private readonly Dictionary<string, string?> values = new() { ["value1"] = "value1" };
public IEnumerator<KeyValuePair<string, string?>> GetEnumerator()
=> this.values.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> this.GetEnumerator();
}
internal sealed class MyCustomScope2 : IReadOnlyList<KeyValuePair<string, object?>>
{
private readonly List<KeyValuePair<string, object?>> values = new() { new("value2", "value2") };
public int Count => this.values.Count;
public KeyValuePair<string, object?> this[int index]
=> this.values[index];
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
=> this.values.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> this.GetEnumerator();
} That being said, unclear to me whether we should do anything at all. Here is the scope handling code from It also won't handle this custom scope using Wouldn't a better solution be There is no contract in |
Yes, you're right ! That's why I've opened PRs in both repos. |
@CodeBlanch Do we know why it worked with ASP.NET Core apps? |
@rajkumar-rangaraj Oh no idea! You actually used |
I just used the sample in our repo and added |
The sample you're talking about does not use Microsoft.Extension.Telemetry that's why you can't repro. |
Deep dived into the code (https://github.com/dotnet/extensions/blob/main/src/Libraries/Microsoft.Extensions.Telemetry/Logging/Import/LoggerFactoryScopeProvider.cs) and I found that the file was borrowed from : https://github.com/dotnet/runtime/blame/main/src/libraries/Microsoft.Extensions.Logging/src/LoggerFactoryScopeProvider.cs |
Package
OpenTelemetry
Package Version
Runtime Version
net8.0
Description
We would like to enable log enrichment + compliance (from Microsoft.Extensions.* packages) on our logs and then use OpenTelemetry to export them.
We would also like to log Baggage from our incoming requests.
Steps to Reproduce
The following minimal program :
With the following request:
Expected Result
The following output from ConsoleExporter:
Actual Result
The following output from ConsoleExporter:
It's missing the baggage values :
Additional Context
No response
The text was updated successfully, but these errors were encountered: