/// <summary>
        /// Initializes a new instance of the <see cref="RequestsCollector"/> 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 dependency calls.</param>
        /// <param name="propagationComponent">Wire context propagation component.</param>
        public RequestsCollector(RequestsCollectorOptions options, ITracer tracer, ISampler sampler, IPropagationComponent propagationComponent)
        {
            this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(
                new Dictionary <string, Func <ITracer, Func <HttpRequest, ISampler>, ListenerHandler> >()
            {
                { "Microsoft.AspNetCore", (t, s) => new HttpInListener(t, s, propagationComponent) },
            },
                tracer,
                x =>
            {
                ISampler s = null;
                try
                {
                    s = options.CustomSampler(x);
                }
                catch (Exception e)
                {
                    s = null;
                    AspNetCoreCollectorEventSource.Log.ExceptionInCustomSampler(e);
                }

                return(s == null ? sampler : s);
            });
            this.diagnosticSourceSubscriber.Subscribe();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RequestsCollector"/> class.
        /// </summary>
        /// <param name="options">Configuration options for dependencies collector.</param>
        /// <param name="tracerFactory">TracerFactory which creates the Tracer to record traced with.</param>
        /// <param name="sampler">Sampler to use to sample dependency calls.</param>
        public RequestsCollector(RequestsCollectorOptions options, ITracerFactory tracerFactory, ISampler sampler)
        {
            const string name = "Microsoft.AspNetCore";

            this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber <HttpRequest>(
                new Dictionary <string, Func <ITracerFactory, Func <HttpRequest, ISampler>, ListenerHandler <HttpRequest> > >()
            {
                {
                    name, (t, s) =>
                    {
                        var version = typeof(RequestDelegate).Assembly.GetName().Version;
                        var tracer  = tracerFactory.GetTracer(typeof(RequestsCollector).Namespace, "semver:" + version.ToString());
                        return(new HttpInListener(name, tracer, s));
                    }
                },
            },
                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();
        }