Example #1
0
        /// <summary>
        /// Adds OpenTelemetry Protocol (OTLP) exporter to the MeterProvider.
        /// </summary>
        /// <param name="builder"><see cref="MeterProviderBuilder"/> builder to use.</param>
        /// <param name="configure">Exporter configuration options.</param>
        /// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
        public static MeterProviderBuilder AddOtlpExporter(this MeterProviderBuilder builder, Action <OtlpExporterOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var options = new OtlpExporterOptions();

            configure?.Invoke(options);
            return(builder.AddMetricProcessor(new PushMetricProcessor(new OtlpMetricsExporter(options), options.MetricExportIntervalMilliseconds, options.IsDelta)));
        }
        public static MeterProviderBuilder AddInMemoryExporter(this MeterProviderBuilder builder, ICollection <MetricItem> exportedItems, Action <InMemoryExporterOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            var options = new InMemoryExporterOptions();

            configure?.Invoke(options);
            return(builder.AddMetricProcessor(new PushMetricProcessor(new InMemoryExporter <MetricItem>(exportedItems), options.MetricExportIntervalMilliseconds, options.IsDelta)));
        }
        public static MeterProviderBuilder AddPrometheusExporter(this MeterProviderBuilder builder, Action <PrometheusExporterOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var options = new PrometheusExporterOptions();

            configure?.Invoke(options);
            var exporter            = new PrometheusExporter(options);
            var pullMetricProcessor = new PullMetricProcessor(exporter, false);

            exporter.MakePullRequest = pullMetricProcessor.PullRequest;

            var metricsHttpServer = new PrometheusExporterMetricsHttpServer(exporter);

            metricsHttpServer.Start();
            return(builder.AddMetricProcessor(pullMetricProcessor));
        }