-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Add Tags and Baggage to LogScope using ActivityTrackingOptions #46571
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
area label: area-Extensions-Logging |
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsBackground and MotivationSince .NET 5 the In our use case, we implement a own Proposed APIusing System;
namespace Microsoft.Extensions.Logging
{
[Flags]
public enum ActivityTrackingOptions
{
+ Tags = ...
+ Baggage = ...
}
} Usage Examplesnamespace Microsoft.Extensions.Hosting
{
public static class Host
{
public static IHostBuilder CreateDefaultBuilder(string[] args)
{
var builder = new HostBuilder();
builder.UseContentRoot(Directory.GetCurrentDirectory());
builder.ConfigureAppConfiguration((hostingContext, config) =>
{
//...
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.Configure(options =>
{
options.ActivityTrackingOptions = ActivityTrackingOptions.SpanId
| ActivityTrackingOptions.TraceId
| ActivityTrackingOptions.ParentId
+ | ActivityTrackingOptions.Baggage
+ | ActivityTrackingOptions.Tags;
});
})
return builder;
}
}
} Alternative Designs
RisksNo risks.
|
Tagging subscribers to this area: @maryamariyan Issue DetailsBackground and MotivationSince .NET 5 the In our use case, we implement a own Proposed APIusing System;
namespace Microsoft.Extensions.Logging
{
[Flags]
public enum ActivityTrackingOptions
{
+ Tags = ...
+ Baggage = ...
}
} Usage Examplesnamespace Microsoft.Extensions.Hosting
{
public static class Host
{
public static IHostBuilder CreateDefaultBuilder(string[] args)
{
var builder = new HostBuilder();
builder.UseContentRoot(Directory.GetCurrentDirectory());
builder.ConfigureAppConfiguration((hostingContext, config) =>
{
//...
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.Configure(options =>
{
options.ActivityTrackingOptions = ActivityTrackingOptions.SpanId
| ActivityTrackingOptions.TraceId
| ActivityTrackingOptions.ParentId
+ | ActivityTrackingOptions.Baggage
+ | ActivityTrackingOptions.Tags;
});
})
return builder;
}
}
} Alternative Designs
RisksNo risks.
|
CC: @tarekgh @shirhatti |
Tags now are string-object pairs and not string-string. What you suggest in formatting the tags? just call |
CC @davidfowl |
In our use case we attach only strings as tags. Thus, its fine to just use |
@davidfowl @shirhatti the proposal looks reasonable to me. Do you have any concern bout it before we move forward? |
As long as it's not on by default, looks good. |
namespace Microsoft.Extensions.Logging
{
public partial enum ActivityTrackingOptions
{
Tags = 0x0020,
Baggage = 0x0040,
}
} |
I would love to contribute this tiny part to .NET |
@msallin go ahead and submit the PR and tag me there. Thanks for willing to help with that. |
@msallin please let me know if you need any help or have any question. Thanks! |
Fixed by #48722 |
Background and Motivation
Since .NET 5 the
LoggerFactoryScopeProvider
can be configured using theActivityTrackingOptions
, to add the SpanId, TraceId, ParentId, TraceStateString and TraceFlags to the scope. The SpanId, TraceId and ParentId are added by default when usingHost.CreateDefaultBuilder()
.In our use case, we implement a own
ConsoleFormatter
which writes the log lines as key-value-pairs, to be able to easy search them with Splunk. We want to add the SpandId, TraceId, ParentId and all items from baggage and tags to each log line.2021-55-05 08:01:01.075 level=INFO eventName=RequestFinished eventId=2 sourceContext="Microsoft.AspNetCoreHosting.Diagnostics" message="Request finished HTTP/1.1 GET http://localhost/ - - - 200- - 101.8717ms" ElapsedMilliseconds="101.8717" StatusCode="200" ContentType="" ContentLength="" Protocol="HTTP/1.1" Method="GET" Scheme="http" Host="localhost" PathBase="" Path="/" QueryString="" SpanId="976b6fa436d88a4e" TraceId="a23f2582c9522c42bce68662015ed2f1" ParentId="0000000000000000" RequestId="0HM5HAUAVSI9J" RequestPath="/"
added some more text to the proposal code by @tarekgh
Proposed API
Usage Examples
Alternative Designs
LoggerFactoryScopeProvider
and add the behavior this way.ActivityTrackingOptions
currently represents only parts of the W3C specRisks
No risks.
The text was updated successfully, but these errors were encountered: