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)));
            }
        }
        public void AppendExportPath_EndpointNotSet_EnvironmentVariableNotDefined_NotAppended()
        {
            ClearEndpointEnvVar();

            var options = new OtlpExporterOptions {
                Protocol = OtlpExportProtocol.HttpProtobuf
            };

            options.AppendExportPath(options.Endpoint, "test/path");

            Assert.Equal("http://localhost:4317/", options.Endpoint.AbsoluteUri);
        }
        public void AppendExportPath_EndpointNotSet_EnvironmentVariableDefined_Appended()
        {
            Environment.SetEnvironmentVariable(OtlpExporterOptions.EndpointEnvVarName, "http://test:8888");

            var options = new OtlpExporterOptions {
                Protocol = OtlpExportProtocol.HttpProtobuf
            };

            options.AppendExportPath(options.Endpoint, "test/path");

            Assert.Equal("http://test:8888/test/path", options.Endpoint.AbsoluteUri);

            ClearEndpointEnvVar();
        }
        private static MeterProviderBuilder AddOtlpExporter(MeterProviderBuilder builder, OtlpExporterOptions options, Action <OtlpExporterOptions> configure = null)
        {
            var initialEndpoint = options.Endpoint;

            configure?.Invoke(options);

            options.AppendExportPath(initialEndpoint, OtlpExporterOptions.MetricsExportPath);

            var metricExporter = new OtlpMetricExporter(options);
            var metricReader   = new PeriodicExportingMetricReader(metricExporter, options.MetricExportIntervalMilliseconds);

            metricReader.PreferredAggregationTemporality = options.AggregationTemporality;
            return(builder.AddReader(metricReader));
        }
        public void AppendExportPath_EndpointSet_EnvironmentVariableNotDefined_NotAppended(string endpoint)
        {
            ClearEndpointEnvVar();

            var options = new OtlpExporterOptions {
                Protocol = OtlpExportProtocol.HttpProtobuf
            };
            var originalEndpoint = options.Endpoint;

            options.Endpoint = new Uri(endpoint);

            options.AppendExportPath(originalEndpoint, "test/path");

            Assert.Equal(endpoint, options.Endpoint.AbsoluteUri);
        }
        private static MeterProviderBuilder AddOtlpExporter(
            MeterProviderBuilder builder,
            OtlpExporterOptions options,
            Action <OtlpExporterOptions> configure,
            IServiceProvider serviceProvider)
        {
            var initialEndpoint = options.Endpoint;

            configure?.Invoke(options);

            options.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpMetricExporter");

            options.AppendExportPath(initialEndpoint, OtlpExporterOptions.MetricsExportPath);

            var metricExporter = new OtlpMetricExporter(options);

            var metricReader = options.MetricReaderType == MetricReaderType.Manual
                ? new BaseExportingMetricReader(metricExporter)
                : new PeriodicExportingMetricReader(metricExporter, options.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds);

            metricReader.Temporality = options.AggregationTemporality;
            return(builder.AddReader(metricReader));
        }