Exemple #1
0
        public ConsoleActivityExporter(ConsoleActivityExporterOptions options)
        {
            this.serializerOptions = new JsonSerializerOptions()
            {
                WriteIndented = true,
            };

            this.displayAsJson = options.DisplayAsJson;

            this.serializerOptions.Converters.Add(new JsonStringEnumConverter());
            this.serializerOptions.Converters.Add(new ActivitySpanIdConverter());
            this.serializerOptions.Converters.Add(new ActivityTraceIdConverter());
        }
        /// <summary>
        /// Registers a ConsoleActivity exporter.
        /// </summary>
        /// <param name="builder">Open Telemetry builder to use.</param>
        /// <param name="configure">Exporter configuration options.</param>
        /// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
        public static OpenTelemetryBuilder UseConsoleActivityExporter(this OpenTelemetryBuilder builder, Action <ConsoleActivityExporterOptions> configure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            var exporterOptions = new ConsoleActivityExporterOptions();

            configure(exporterOptions);
            var consoleExporter = new ConsoleActivityExporter(exporterOptions);

            return(builder.SetProcessorPipeline(pipeline => pipeline.SetExporter(consoleExporter)));
        }