-
Notifications
You must be signed in to change notification settings - Fork 773
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
Pass the IServiceProvider in ConfigureResource, WithTracing & WithMetrics #4228
Comments
Just for anyone landing on this issue see #4139 (comment) for some code you can use to accomplish these tasks today using the 1.4 API. |
@cijothomas Can we please re-open this as #4261 doesn't appear to fix this issue (in the way #4228 attempted)? |
We won't be adding top-level extensions which expose If you want to use appBuilder.Services.AddOpenTelemetry()
.ConfigureResource(b => b.AddDetector(sp => new MyResourceDetector(sp)));
internal sealed class MyResourceDetector : IResourceDetector
{
private readonly IServiceProvider serviceProvider;
public MyResourceDetector(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}
public Resource Detect()
{
var options = this.serviceProvider.GetRequiredService<IOptions<MyOptions>>().Value;
Dictionary<string, object> values = new();
if (options.AddSomeResourceInfo)
{
// add keys
}
if (options.AddSomeOtherResourceStuff)
{
// add keys
}
return new(values);
}
} If you want to access services.AddOpenTelemetry().WithTracing();
services.ConfigureOpenTelemetryTracerProvider((sp, builder) => {
// Configure TracerProviderBuilder using IServiceProvider but watch out IServiceCollection is no longer available...
}); Do those work for your use case? |
Thanks @CodeBlanch for the detailed response. I was actually already using |
- EnableGrpcAspNetCoreSupport was replaced by environment variable OTEL_DOTNET_EXPERIMENTAL_ASPNETCORE_ENABLE_GRPC_INSTRUMENTATION, see https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs - Replace usage of IDeferredTracerProviderBuilder, see open-telemetry/opentelemetry-dotnet#4228
* Update OpenTelemetry packages - EnableGrpcAspNetCoreSupport was replaced by environment variable OTEL_DOTNET_EXPERIMENTAL_ASPNETCORE_ENABLE_GRPC_INSTRUMENTATION, see https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs - Replace usage of IDeferredTracerProviderBuilder, see open-telemetry/opentelemetry-dotnet#4228 * Update src/Management/src/Wavefront/Exporters/TagExtensions.cs Co-authored-by: Tim Hess <[email protected]> --------- Co-authored-by: Tim Hess <[email protected]>
Feature Request
Is your feature request related to a problem?
We need an
IServiceProvider
inConfigureResource
andWithTracing
(andWithMetrics
if we'd use it) for stuff like the options pattern.Describe the solution you'd like:
A service provider being provided (as an option) to the respective callbacks.
Describe alternatives you've considered.
For
ConfigureResource
you could maybe get it done with an extension method, but you're basically rewriting library code at that point. ForWithTracing
I don't see a solution, without accessing private stuff via reflection.Additional Context
The text was updated successfully, but these errors were encountered: