-
Notifications
You must be signed in to change notification settings - Fork 281
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
Allow access to the operation id #1338
Comments
OperationId in application insights will be activity.traceid. If you use the SDK with default settings, then all traces (including ilogger ones) should get automatically tagged with correct parentid. Is this not what you see already? Perhaps you are hitting this issue (https://github.com/microsoft/ApplicationInsights-dotnet-logging/issues/305) ? @lmolkova is the expert here to help more. |
@GeeWee you should always make sure you configure OperationCorrelationTelemetryInititalizer and never stamp operation_Id, parentId or id on your own.
|
That makes sense. The reason I'm asking about this, is because the Serilog AI Sink doesn't seem to properly instrument the log calls with However, what you're saying is that there's potentially something more fundamental wrong in the sink, that should be fixed instead of monkeypatched? |
Looking into the sink, it seems it uses |
Yes, let's try to explore the sink issue. Perhaps this is more of an issue over there - if we manage to resolve this, I'll make a PR over there. While the documentation says to use Telemetry.Active, there's also a different constructor that people have been playing around with in #121. Digging a little deeper in the different constructors, I find I've been using the following one in the sink // Inject IOptionsMonitor<TelemetryConfiguration> inside Startup.Configure
var loggerConfiguration = LoggerConfiguration
// other stuff
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces); This leads to the following code. As alternatives, I've just now tried the sink constructor that uses the ASP.Net Core |
Do not use Active if you can avoid it. AI SDK attempts to initialize it in the same way as one in DI, but any customization may lead to discrepancies. With logger adapters it's not always possible NOT to use it though.
This is the proper way to initialize
This is also a reasonable workaround. Let me know if it anwsers your question. Thanks! |
Alright, so I think I've tried to dig up the problem. The instance owns the sink, but there's a mismatch in the TelemetryInitializers between the ASP.Net core injected TelemetryClient and the TelemetryConfiguration. If In
And the following on the TelemetryClient
So the Configuration is missing the OperationCorrelationTelemetryInitializer, that is attached to the client. |
This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
I'm doing some Serilog integration currently in ASP.NET Core 3, where it would be really nice to be able to access the current operation_id and operation_ParentId, to ship that off along with the traces sent to Application Insights. Particularly in a situation where we use
telemetryClient.StartOperation<RequestTelemetry>()
An earlier issue , suggested System.Diagnostics.Activity.Current?.RootId - but that's not accurate anymore. Looking through the codebase it seems like the
operation_Id is equivalent to
Activity.TraceId
and the operation_ParentId is constructed via$"|{activity.TraceId}.{activity.Parent.SpanId}."
insideW3CUtilities.FormatTelemetryId
Is this:
a) Correct?
b) Guaranteed to be stable, if I end up creating this logic into my logging integration
c) Or it is perhaps possible to expose the functionality for getting these ID's, so we don't have to go through all of these hoops
The text was updated successfully, but these errors were encountered: