Example #1
0
        /// <summary>
        /// Registers Jaeger exporter.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <param name="configure">Exporter configuration options.</param>
        /// <param name="processorConfigure">Span processor configuration.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder UseJaeger(this TracerBuilder builder, Action <JaegerExporterOptions> configure, Action <SpanProcessorPipelineBuilder> processorConfigure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            if (processorConfigure == null)
            {
                throw new ArgumentNullException(nameof(processorConfigure));
            }

            var options = new JaegerExporterOptions();

            configure(options);
            return(builder.AddProcessorPipeline(b =>
            {
                b.SetExporter(new JaegerTraceExporter(options));
                processorConfigure.Invoke(b);
            }));
        }
        /// <summary>
        /// Enables the outgoing requests automatic data collection.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <param name="configureHttpInstrumentationOptions">Http configuration options.</param>
        /// <param name="configureSqlInstrumentationOptions">Sql configuration options.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder AddDependencyInstrumentation(
            this TracerBuilder builder,
            Action <HttpClientInstrumentationOptions> configureHttpInstrumentationOptions = null,
            Action <SqlClientInstrumentationOptions> configureSqlInstrumentationOptions   = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var httpOptions = new HttpClientInstrumentationOptions();

            configureHttpInstrumentationOptions?.Invoke(httpOptions);

            var sqlOptions = new SqlClientInstrumentationOptions();

            configureSqlInstrumentationOptions?.Invoke(sqlOptions);

            return(builder
                   .AddInstrumentation((t) => new AzureClientsInstrumentation(t))
                   .AddInstrumentation((t) => new AzurePipelineInstrumentation(t))
                   .AddInstrumentation((t) => new HttpClientInstrumentation(t, httpOptions))
                   .AddInstrumentation((t) => new HttpWebRequestInstrumentation(t, httpOptions))
                   .AddInstrumentation((t) => new SqlClientInstrumentation(t, sqlOptions)));
        }
        public static TracerFactory Create(Action <TracerBuilder> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var builder = new TracerBuilder();

            configure(builder);
            var factory = new TracerFactory(builder);

            if (builder.CollectorFactories != null)
            {
                foreach (var collector in builder.CollectorFactories)
                {
                    var tracer = factory.GetTracer(collector.Name, collector.Version);

                    var collectorInstance = collector.Factory(tracer);
                    if (collectorInstance is IDisposable disposableCollector)
                    {
                        factory.disposables.Add(disposableCollector);
                    }
                }
            }

            return(factory);
        }
        private TracerFactory(TracerBuilder builder)
        {
            this.sampler = builder.Sampler ?? Samplers.AlwaysSample;

            // TODO separate sampler from options
            this.configurationOptions =
                builder.TracerConfigurationOptions ?? new TracerConfiguration(this.sampler);

            // TODO log warning (or throw?) if there is no exporter
            this.exporter = builder.SpanExporter ?? new NoopSpanExporter();

            this.spanProcessor = builder.ProcessorFactory != null?
                                 builder.ProcessorFactory(this.exporter) :
                                     new BatchingSpanProcessor(this.exporter);

            this.binaryFormat = builder.BinaryFormat ?? new BinaryFormat();
            this.textFormat   = builder.TextFormat ?? new TraceContextFormat();

            this.defaultTracer = new Tracer(
                this.spanProcessor,
                this.configurationOptions,
                this.binaryFormat,
                this.textFormat,
                Resource.Empty);
        }
        /// <summary>
        /// Enables Application Insights exporter.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <param name="applicationInsightsConfigure">Configuration options.</param>
        /// <param name="processorConfigure">Span processor configuration.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder UseApplicationInsights(this TracerBuilder builder, Action <TelemetryConfiguration> applicationInsightsConfigure, Action <
                                                               SpanProcessorPipelineBuilder> processorConfigure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (applicationInsightsConfigure == null)
            {
                throw new ArgumentNullException(nameof(applicationInsightsConfigure));
            }

            if (processorConfigure == null)
            {
                throw new ArgumentNullException(nameof(processorConfigure));
            }

            var options = new TelemetryConfiguration();

            applicationInsightsConfigure(options);
            return(builder.AddProcessorPipeline(b =>
            {
                b.SetExporter(new ApplicationInsightsTraceExporter(options));
                processorConfigure.Invoke(b);
            }));
        }
Example #6
0
        /// <summary>
        /// Enables the incoming requests automatic data collection.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder AddRequestCollector(this TracerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AddCollector(t => new AspNetCoreCollector(t)));
        }
        /// <summary>
        /// Enables the incoming requests automatic data collection.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder AddRequestInstrumentation(this TracerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AddInstrumentation(t => new AspNetInstrumentation(t)));
        }
        /// <summary>
        /// Enables the outgoing requests automatic data collection.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder AddDependencyCollector(this TracerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder
                   .AddCollector((t) => new AzureClientsCollector(t))
                   .AddCollector((t) => new AzurePipelineCollector(t))
                   .AddCollector((t) => new HttpClientCollector(t)));
        }
        /// <summary>
        /// Enables the outgoing requests automatic data collection.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder AddDependencyInstrumentation(this TracerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder
                   .AddInstrumentation((t) => new AzureClientsInstrumentation(t))
                   .AddInstrumentation((t) => new AzurePipelineInstrumentation(t))
                   .AddInstrumentation((t) => new HttpClientInstrumentation(t))
                   .AddInstrumentation((t) => new HttpWebRequestInstrumentation(t))
                   .AddInstrumentation((t) => new SqlClientInstrumentation(t)));
        }
        public static TracerBuilder UseApplicationInsights(this TracerBuilder builder, Action <TelemetryConfiguration> configure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var configuration = new TelemetryConfiguration();

            configure(configuration);
            return(builder.SetExporter(new ApplicationInsightsTraceExporter(configuration)));
        }
        public static TracerBuilder UseZipkin(this TracerBuilder builder, Action <ZipkinTraceExporterOptions> configure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var options = new ZipkinTraceExporterOptions();

            configure(options);
            return(builder.SetExporter(new ZipkinTraceExporter(options)));
        }
Example #12
0
        /// <summary>
        /// Enables the incoming requests automatic data collection.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <param name="configure">Configuration options.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder AddRequestCollector(this TracerBuilder builder, Action <AspNetCoreCollectorOptions> configure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var options = new AspNetCoreCollectorOptions();

            configure(options);

            return(builder.AddCollector(t => new AspNetCoreCollector(t, options)));
        }
        private TracerFactory(TracerBuilder builder)
        {
            this.sampler         = builder.Sampler ?? Samplers.AlwaysSample;
            this.defaultResource = builder.Resource;

            this.configurationOptions =
                builder.TracerConfigurationOptions ?? new TracerConfiguration();

            if (builder.ProcessingPipelines == null || !builder.ProcessingPipelines.Any())
            {
                // if there are no pipelines are configured, use noop processor
                this.spanProcessor = new NoopSpanProcessor();
            }
            else if (builder.ProcessingPipelines.Count == 1)
            {
                // if there is only one pipeline - use it's outer processor as a
                // single processor on the tracer.
                var processorFactory = builder.ProcessingPipelines[0];
                this.spanProcessor = processorFactory.Build();
            }
            else
            {
                // if there are more pipelines, use processor that will broadcast to all pipelines
                var processors = new SpanProcessor[builder.ProcessingPipelines.Count];

                for (int i = 0; i < builder.ProcessingPipelines.Count; i++)
                {
                    processors[i] = builder.ProcessingPipelines[i].Build();
                }

                this.spanProcessor = new BroadcastProcessor(processors);
            }

            this.binaryFormat = builder.BinaryFormat ?? new BinaryFormat();
            this.textFormat   = builder.TextFormat ?? new TraceContextFormat();

            this.defaultTracer = new Tracer(
                this.spanProcessor,
                this.sampler,
                this.configurationOptions,
                this.binaryFormat,
                this.textFormat,
                this.defaultResource);
        }
Example #14
0
        /// <summary>
        /// Registers a Jaeger exporter.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <param name="configure">Exporter configuration options.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder UseJaeger(this TracerBuilder builder, Action <JaegerExporterOptions> configure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var options = new JaegerExporterOptions();

            configure(options);
            return(builder.AddProcessorPipeline(b => b
                                                .SetExporter(new JaegerTraceExporter(options))
                                                .SetExportingProcessor(e => new BatchingSpanProcessor(e))));
        }
        /// <summary>
        /// Enables Application Insights exporter.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <param name="configure">Configuration options.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder UseApplicationInsights(this TracerBuilder builder, Action <TelemetryConfiguration> configure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var configuration = new TelemetryConfiguration();

            configure(configuration);
            return(builder.AddProcessorPipeline(b => b
                                                .SetExporter(new ApplicationInsightsTraceExporter(configuration))
                                                .SetExportingProcessor(e => new BatchingSpanProcessor(e))));
        }
        /// <summary>
        /// Enables the outgoing requests automatic data collection.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <param name="configure">Configuration options.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder AddDependencyCollector(this TracerBuilder builder, Action <HttpClientCollectorOptions> configure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var options = new HttpClientCollectorOptions();

            configure(options);

            return(builder
                   .AddCollector((t) => new AzureClientsCollector(t))
                   .AddCollector((t) => new AzurePipelineCollector(t))
                   .AddCollector((t) => new HttpClientCollector(t, options)));
        }
        /// <summary>
        /// Creates tracerSdk factory.
        /// </summary>
        /// <param name="configure">Function that configures tracerSdk factory.</param>
        /// <returns>Returns new <see cref="TracerFactory"/>.</returns>
        public static TracerFactory Create(Action <TracerBuilder> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var builder = new TracerBuilder();

            configure(builder);
            var factory = new TracerFactory(builder);

            if (builder.AdapterFactories != null)
            {
                foreach (var adapter in builder.AdapterFactories)
                {
                    var tracer = factory.GetTracer(adapter.Name, adapter.Version);
                    factory.adapters.Add(adapter.Factory(tracer));
                }
            }

            return(factory);
        }
        /// <summary>
        /// Enables the outgoing requests automatic data collection.
        /// </summary>
        /// <param name="builder">Trace builder to use.</param>
        /// <param name="configureHttpCollectorOptions">Http configuration options.</param>
        /// <param name="configureSqlCollectorOptions">Sql configuration options.</param>
        /// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
        public static TracerBuilder AddDependencyCollector(
            this TracerBuilder builder,
            Action <HttpClientCollectorOptions> configureHttpCollectorOptions = null,
            Action <SqlClientCollectorOptions> configureSqlCollectorOptions   = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var httpOptions = new HttpClientCollectorOptions();

            configureHttpCollectorOptions?.Invoke(httpOptions);

            var sqlOptions = new SqlClientCollectorOptions();

            configureSqlCollectorOptions?.Invoke(sqlOptions);

            return(builder
                   .AddCollector((t) => new AzureClientsCollector(t))
                   .AddCollector((t) => new AzurePipelineCollector(t))
                   .AddCollector((t) => new HttpClientCollector(t, httpOptions))
                   .AddCollector((t) => new SqlClientCollector(t, sqlOptions)));
        }