private static TracerProviderBuilder AddOtlpExporter(
            TracerProviderBuilder builder,
            OtlpExporterOptions exporterOptions,
            Action <OtlpExporterOptions> configure,
            IServiceProvider serviceProvider)
        {
            var originalEndpoint = exporterOptions.Endpoint;

            configure?.Invoke(exporterOptions);

            exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter");

            exporterOptions.AppendExportPath(originalEndpoint, OtlpExporterOptions.TracesExportPath);

            var otlpExporter = new OtlpTraceExporter(exporterOptions);

            if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple)
            {
                return(builder.AddProcessor(new SimpleActivityExportProcessor(otlpExporter)));
            }
            else
            {
                return(builder.AddProcessor(new BatchActivityExportProcessor(
                                                otlpExporter,
                                                exporterOptions.BatchExportProcessorOptions.MaxQueueSize,
                                                exporterOptions.BatchExportProcessorOptions.ScheduledDelayMilliseconds,
                                                exporterOptions.BatchExportProcessorOptions.ExporterTimeoutMilliseconds,
                                                exporterOptions.BatchExportProcessorOptions.MaxExportBatchSize)));
            }
        }
Пример #2
0
        public static TracerProviderBuilder AddJaegerExporter(this TracerProviderBuilder builder, Action <JaegerExporterOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var exporterOptions = new JaegerExporterOptions();

            configure?.Invoke(exporterOptions);
            var jaegerExporter = new JaegerExporter(exporterOptions);

            if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple)
            {
                return(builder.AddProcessor(new SimpleActivityExportProcessor(jaegerExporter)));
            }
            else
            {
                return(builder.AddProcessor(new BatchActivityExportProcessor(
                                                jaegerExporter,
                                                exporterOptions.BatchExportProcessorOptions.MaxQueueSize,
                                                exporterOptions.BatchExportProcessorOptions.ScheduledDelayMilliseconds,
                                                exporterOptions.BatchExportProcessorOptions.ExporterTimeoutMilliseconds,
                                                exporterOptions.BatchExportProcessorOptions.MaxExportBatchSize)));
            }
        }
        internal static TracerProviderBuilder AddOtlpExporter(
            TracerProviderBuilder builder,
            OtlpExporterOptions exporterOptions,
            Action <OtlpExporterOptions> configure,
            IServiceProvider serviceProvider,
            Func <BaseExporter <Activity>, BaseExporter <Activity> > configureExporterInstance = null)
        {
            configure?.Invoke(exporterOptions);

            exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter");

            BaseExporter <Activity> otlpExporter = new OtlpTraceExporter(exporterOptions);

            if (configureExporterInstance != null)
            {
                otlpExporter = configureExporterInstance(otlpExporter);
            }

            if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple)
            {
                return(builder.AddProcessor(new SimpleActivityExportProcessor(otlpExporter)));
            }
            else
            {
                var batchOptions = exporterOptions.BatchExportProcessorOptions ?? new();

                return(builder.AddProcessor(new BatchActivityExportProcessor(
                                                otlpExporter,
                                                batchOptions.MaxQueueSize,
                                                batchOptions.ScheduledDelayMilliseconds,
                                                batchOptions.ExporterTimeoutMilliseconds,
                                                batchOptions.MaxExportBatchSize)));
            }
        }
Пример #4
0
        private static TracerProviderBuilder AddJaegerExporter(
            TracerProviderBuilder builder,
            JaegerExporterOptions options,
            Action <JaegerExporterOptions> configure,
            IServiceProvider serviceProvider)
        {
            configure?.Invoke(options);

            if (options.Protocol == JaegerExportProtocol.HttpBinaryThrift && options.HttpClientFactory == null)
            {
                if (serviceProvider != null)
                {
                    options.HttpClientFactory = () =>
                    {
                        Type httpClientFactoryType = Type.GetType("System.Net.Http.IHttpClientFactory, Microsoft.Extensions.Http", throwOnError: false);
                        if (httpClientFactoryType != null)
                        {
                            object httpClientFactory = serviceProvider.GetService(httpClientFactoryType);
                            if (httpClientFactory != null)
                            {
                                MethodInfo createClientMethod = httpClientFactoryType.GetMethod(
                                    "CreateClient",
                                    BindingFlags.Public | BindingFlags.Instance,
                                    binder: null,
                                    new Type[] { typeof(string) },
                                    modifiers: null);
                                if (createClientMethod != null)
                                {
                                    return((HttpClient)createClientMethod.Invoke(httpClientFactory, new object[] { "JaegerExporter" }));
                                }
                            }
                        }

                        return(new HttpClient());
                    };
                }
                else
                {
                    options.HttpClientFactory = () => new HttpClient();
                }
            }

            var jaegerExporter = new JaegerExporter(options);

            if (options.ExportProcessorType == ExportProcessorType.Simple)
            {
                return(builder.AddProcessor(new SimpleActivityExportProcessor(jaegerExporter)));
            }
            else
            {
                return(builder.AddProcessor(new BatchActivityExportProcessor(
                                                jaegerExporter,
                                                options.BatchExportProcessorOptions.MaxQueueSize,
                                                options.BatchExportProcessorOptions.ScheduledDelayMilliseconds,
                                                options.BatchExportProcessorOptions.ExporterTimeoutMilliseconds,
                                                options.BatchExportProcessorOptions.MaxExportBatchSize)));
            }
        }
Пример #5
0
        public static TracerProviderBuilder AddInMemoryExporter(this TracerProviderBuilder builder, ICollection <Activity> exportedItems)
        {
            Guard.ThrowIfNull(builder, nameof(builder));
            Guard.ThrowIfNull(exportedItems, nameof(exportedItems));

            if (builder is IDeferredTracerProviderBuilder deferredTracerProviderBuilder)
            {
                return(deferredTracerProviderBuilder.Configure((sp, builder) =>
                {
                    builder.AddProcessor(new SimpleActivityExportProcessor(new InMemoryExporter <Activity>(exportedItems)));
                }));
            }

            return(builder.AddProcessor(new SimpleActivityExportProcessor(new InMemoryExporter <Activity>(exportedItems))));
        }
Пример #6
0
        private static TracerProviderBuilder AddOtlpExporter(TracerProviderBuilder builder, OtlpExporterOptions exporterOptions, Action <OtlpExporterOptions> configure = null)
        {
            configure?.Invoke(exporterOptions);
            var otlpExporter = new OtlpTraceExporter(exporterOptions);

            if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple)
            {
                return(builder.AddProcessor(new SimpleActivityExportProcessor(otlpExporter)));
            }
            else
            {
                return(builder.AddProcessor(new BatchActivityExportProcessor(
                                                otlpExporter,
                                                exporterOptions.BatchExportProcessorOptions.MaxQueueSize,
                                                exporterOptions.BatchExportProcessorOptions.ScheduledDelayMilliseconds,
                                                exporterOptions.BatchExportProcessorOptions.ExporterTimeoutMilliseconds,
                                                exporterOptions.BatchExportProcessorOptions.MaxExportBatchSize)));
            }
        }
Пример #7
0
        private static TracerProviderBuilder AddJaegerExporter(TracerProviderBuilder builder, JaegerExporterOptions options, Action <JaegerExporterOptions> configure = null)
        {
            configure?.Invoke(options);

            var jaegerExporter = new JaegerExporter(options);

            if (options.ExportProcessorType == ExportProcessorType.Simple)
            {
                return(builder.AddProcessor(new SimpleActivityExportProcessor(jaegerExporter)));
            }
            else
            {
                return(builder.AddProcessor(new BatchActivityExportProcessor(
                                                jaegerExporter,
                                                options.BatchExportProcessorOptions.MaxQueueSize,
                                                options.BatchExportProcessorOptions.ScheduledDelayMilliseconds,
                                                options.BatchExportProcessorOptions.ExporterTimeoutMilliseconds,
                                                options.BatchExportProcessorOptions.MaxExportBatchSize)));
            }
        }
Пример #8
0
        public static TracerProviderBuilder AddConsoleExporter(this TracerProviderBuilder builder, Action <ConsoleExporterOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var options = new ConsoleExporterOptions();

            configure?.Invoke(options);
            return(builder.AddProcessor(new SimpleExportActivityProcessor(new ConsoleExporter(options))));
        }
Пример #9
0
        public static TracerProviderBuilder AddInMemoryExporter(this TracerProviderBuilder builder, ICollection <Activity> exportedItems)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            if (builder is IDeferredTracerProviderBuilder deferredTracerProviderBuilder)
            {
                return(deferredTracerProviderBuilder.Configure((sp, builder) =>
                {
                    builder.AddProcessor(new SimpleActivityExportProcessor(new InMemoryExporter <Activity>(exportedItems)));
                }));
            }

            return(builder.AddProcessor(new SimpleActivityExportProcessor(new InMemoryExporter <Activity>(exportedItems))));
        }
        /// <summary>
        /// Registers a Stackdriver exporter that will receive <see cref="System.Diagnostics.Activity"/> instances.
        /// </summary>
        /// <param name="builder"><see cref="TracerProviderBuilder"/> builder to use.</param>
        /// <param name="projectId">Project ID to send telemetry to.</param>
        /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
        public static TracerProviderBuilder UseStackdriverExporter(
            this TracerProviderBuilder builder,
            string projectId)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var activityExporter = new StackdriverTraceExporter(projectId);

            return(builder.AddProcessor(new BatchActivityExportProcessor(activityExporter)));
        }
Пример #11
0
        public static TracerProviderBuilder AddZPagesExporter(
            this TracerProviderBuilder builder,
            Action <ZPagesExporterOptions> configure = null)
        {
            Guard.ThrowIfNull(builder);

            var exporterOptions = new ZPagesExporterOptions();

            configure?.Invoke(exporterOptions);
            var zpagesExporter = new ZPagesExporter(exporterOptions);

            // TODO: Pick Simple vs Batching based on ZipkinExporterOptions
            return(builder.AddProcessor(new ZPagesProcessor(zpagesExporter)));
        }
        public static TracerProviderBuilder AddInMemoryExporter(this TracerProviderBuilder builder, ICollection <Activity> exportedItems)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            return(builder.AddProcessor(new SimpleExportProcessor <Activity>(new InMemoryExporter <Activity>(exportedItems))));
        }
        public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action <OtlpExporterOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var exporterOptions = new OtlpExporterOptions();

            configure?.Invoke(exporterOptions);
            var otlpExporter = new OtlpExporter(exporterOptions);

            // TODO: Pick Simple vs Batching based on OtlpExporterOptions
            return(builder.AddProcessor(new BatchExportActivityProcessor(otlpExporter)));
        }
        /// <summary>
        /// Registers a Zipkin exporter that will receive <see cref="System.Diagnostics.Activity"/> instances.
        /// </summary>
        /// <param name="builder"><see cref="TracerProviderBuilder"/> builder to use.</param>
        /// <param name="configure">Exporter configuration options.</param>
        /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
        public static TracerProviderBuilder AddZPagesExporter(
            this TracerProviderBuilder builder,
            Action <ZPagesExporterOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var exporterOptions = new ZPagesExporterOptions();

            configure?.Invoke(exporterOptions);
            var zpagesExporter = new ZPagesExporter(exporterOptions);

            // TODO: Pick Simple vs Batching based on ZipkinExporterOptions
            return(builder.AddProcessor(new ZPagesProcessor(zpagesExporter)));
        }
 private static TracerProviderBuilder AddConsoleExporter(TracerProviderBuilder builder, ConsoleExporterOptions options, Action <ConsoleExporterOptions> configure = null)
 {
     configure?.Invoke(options);
     return(builder.AddProcessor(new SimpleActivityExportProcessor(new ConsoleActivityExporter(options))));
 }
        /// <summary>
        /// Adds a <see cref="BaseProcessor{T}"/> which will enrich <see cref="Activity"/> objects created while inside an <see cref="ActivityEnrichmentScope"/>.
        /// </summary>
        /// <param name="tracerProviderBuilder"><see cref="TracerProviderBuilder"/>.</param>
        /// <returns>Returns the supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
        public static TracerProviderBuilder AddActivityEnrichmentScopeProcessor(this TracerProviderBuilder tracerProviderBuilder)
#pragma warning disable CA2000 // Dispose objects before losing scope
        => tracerProviderBuilder.AddProcessor(new ActivityEnrichmentScopeProcessor());