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
Trace enrichment can be achieved by calling EnrichWithHttpRequestMessage/EnrichWithHttpRequest , EnrichWithHttpResponseMessage/EnrichWithHttpResponse , EnrichWithException/EnrichWithException callbacks. These callbacks, however, do not provide access to IServiceProvider, so I can't take some service(-s) from the Dependency Injection container and pass the Activity object to them.
Describe the solution you'd like:
The callbacks mentioned above should have an additional argument - IServiceProvider, so that it would be possible to get services from the Dependency Injection container and use them to enrich traces.
Describe alternatives you've considered.
Another way to do enrichment is by using a custom processor. But this does not help when I need to enrich traces at the OnStart event, because the instrumentation is run AFTER the OnStart event, so the processor can deal with non-instrumented activities only.
The text was updated successfully, but these errors were encountered:
@evgenyfedorov2 Are you using OpenTelemetry.Extensions.Hosting? If yes, you should be able to use the Options API to accomplish this. Try something like this...
// Build a class for each options type you want to modify and implement IConfigureOptions<T>internalsealedclassConfigureAspNetCoreInstrumentationOptions:IConfigureOptions<AspNetCoreInstrumentationOptions>{privatereadonlyIServiceProviderserviceProvider;publicConfigureAspNetCoreInstrumentationOptions(IServiceProviderserviceProvider){// In this example I injected IServiceProvider but you could also just// inject MyService directly and avoid having to interact with the// provider.this.serviceProvider=serviceProvider;}publicvoidConfigure(AspNetCoreInstrumentationOptionsoptions){varmyService=this.serviceProvider.GetRequiredService<MyService>();// Attach the options delegates/callbacks here using whatever services you need!options.EnrichWithHttpRequest=(activity,request)=>myService.EnrichWithHttpRequest(activity,request);}}// Startup code// Register the IConfigureOptions<T> as singletons. They will be executed when// options are requested. The key is the class implementing the interface (eg// ConfigureAspNetCoreInstrumentationOptions) will be requested via the// IServiceProvider so any ctor parameter services will be injected into it!appBuilder.Services.AddSingleton<IConfigureOptions<AspNetCoreInstrumentationOptions>,ConfigureAspNetCoreInstrumentationOptions>();// Nothing special here just make sure you turn on instrumentation.appBuilder.Services.AddOpenTelemetryTracing(builder =>builder.AddAspNetCoreInstrumentation());
Is your feature request related to a problem?
Trace enrichment can be achieved by calling
EnrichWithHttpRequestMessage/EnrichWithHttpRequest
,EnrichWithHttpResponseMessage/EnrichWithHttpResponse
,EnrichWithException/EnrichWithException
callbacks. These callbacks, however, do not provide access toIServiceProvider
, so I can't take some service(-s) from the Dependency Injection container and pass theActivity
object to them.Describe the solution you'd like:
The callbacks mentioned above should have an additional argument -
IServiceProvider
, so that it would be possible to get services from the Dependency Injection container and use them to enrich traces.Describe alternatives you've considered.
Another way to do enrichment is by using a custom processor. But this does not help when I need to enrich traces at the
OnStart
event, because the instrumentation is run AFTER theOnStart
event, so the processor can deal with non-instrumented activities only.The text was updated successfully, but these errors were encountered: