Skip to content
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

Use IOptions<T> for DI options #101

Closed
AlexeiScherbakov opened this issue Jun 11, 2019 · 4 comments
Closed

Use IOptions<T> for DI options #101

AlexeiScherbakov opened this issue Jun 11, 2019 · 4 comments

Comments

@AlexeiScherbakov
Copy link

For example StackExchangeRedisCallsCollectorOptions can be be injected as

var options=new StackExchangeRedisCallsCollectorOptions();
services.Configure<StackExchangeRedisCallsCollectorOptions>(options);

and StackExchangeRedisCallsCollector must have ctor with IOptions or IOptionsMonitor(for reloading options dynamically) for example:

public StackExchangeRedisCallsCollector(IOptions<StackExchangeRedisCallsCollectorOptions> options, ITracer tracer, ISampler sampler, IExportComponent exportComponent)
        {
...
        }

link: https://docs.microsoft.com/en-US/aspnet/core/fundamentals/configuration/options?view=aspnetcore-2.2

@SergeyKanzhelev SergeyKanzhelev added this to the Basic exporters and adapters milestone Jun 11, 2019
@SergeyKanzhelev SergeyKanzhelev modified the milestones: Basic exporters and adapters, v0.3 Oct 28, 2019
@SergeyKanzhelev
Copy link
Member

@pakrym do you have suggestion on how IOptions can be used alongside this style of configuring:

https://github.com/open-telemetry/opentelemetry-dotnet#configuration-with-microsoftextensionsdependencyinjection

Where the constructor of zipkin collector will get the options from?

services.AddOpenTelemetry(b => b
            .UseZipkin(o => o.ServiceName = "my-service")

I'm a bit lost in injections =)

@pakrym
Copy link
Contributor

pakrym commented Nov 8, 2019

You can add a T GetOptions<T>() to TracerBuilder (with default implementation being just new T()) and in AddOpenTelemetry extension method create a derived TracerBuilder that would implement GetOptions via IOptions<> resolution.

Then in UseZipkin method would become something like:

return builder.AddProcessorPipeline(b =>
            {
              var options  = b.GetOptions<ZipkinTraceExporterOptions>();

                b.SetExporter(new ZipkinTraceExporter(options  ));
                processorConfigure.Invoke(b);
            });

@SergeyKanzhelev
Copy link
Member

I just realized that this will mean that all packages will have a reference to IOptions (Microsoft.Extensions.Options) from everywhere except OpenTelemetry.Api. It may not work for net45. And in general looks excessive. Is it by design or I'm missing something?

@pakrym
Copy link
Contributor

pakrym commented Nov 11, 2019

I think you can design it in a way where only OpenTelemetry.Hosting would have a dependency on IOptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants