/// <summary> /// Initializes a new instance of the <see cref="DependenciesCollector"/> class. /// </summary> /// <param name="options">Configuration options for dependencies collector.</param> /// <param name="tracer">Tracer to record traced with.</param> /// <param name="sampler">Sampler to use to sample dependnecy calls.</param> public DependenciesCollector(DependenciesCollectorOptions options, ITracer tracer, ISampler sampler) { this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber( new Dictionary <string, Func <ITracer, Func <HttpRequestMessage, ISampler>, ListenerHandler> >() { { "HttpHandlerDiagnosticListener", (t, s) => new HttpHandlerDiagnosticListener(t, s) } }, tracer, x => { ISampler s = null; try { s = options.CustomSampler(x); } catch (Exception e) { s = null; DependenciesCollectorEventSource.Log.ExceptionInCustomSampler(e); } return(s ?? sampler); }); this.diagnosticSourceSubscriber.Subscribe(); }
/// <summary> /// Initializes a new instance of the <see cref="DependenciesCollector"/> class. /// </summary> /// <param name="options">Configuration options for dependencies collector.</param> /// <param name="tracerFactory">TracerFactory to create a Tracer to record traced with.</param> /// <param name="sampler">Sampler to use to sample dependency calls.</param> public DependenciesCollector(DependenciesCollectorOptions options, ITracerFactory tracerFactory, ISampler sampler) { this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber <HttpRequestMessage>( new Dictionary <string, Func <ITracerFactory, Func <HttpRequestMessage, ISampler>, ListenerHandler <HttpRequestMessage> > >() { { "HttpHandlerDiagnosticListener", (tf, s) => { var tracer = tracerFactory.GetTracer("OpenTelemetry.Collector.Dependencies.HttpHandlerDiagnosticListener"); return(new HttpHandlerDiagnosticListener(tracer, s)); } }, { "Azure.Clients", (tf, s) => { var tracer = tracerFactory.GetTracer("OpenTelemetry.Collector.Dependencies.Azure.Clients"); return(new AzureSdkDiagnosticListener("Azure.Clients", tracer, sampler)); } }, { "Azure.Pipeline", (tf, s) => { var tracer = tracerFactory.GetTracer("OpenTelemetry.Collector.Dependencies.Azure.Pipeline"); return(new AzureSdkDiagnosticListener("Azure.Pipeline", tracer, sampler)); } }, }, tracerFactory, x => { ISampler s = null; try { s = options.CustomSampler(x); } catch (Exception e) { s = null; CollectorEventSource.Log.ExceptionInCustomSampler(e); } return(s ?? sampler); }); this.diagnosticSourceSubscriber.Subscribe(); }