From bbc1d8e8b222f965aaf588824af8e08c73e446b6 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 11 Aug 2020 23:43:07 -0700 Subject: [PATCH 1/2] update console exporter --- .../building-your-own-sampler/MySampler.cs | 2 +- .../building-your-own-sampler/Program.cs | 3 +- docs/trace/getting-started/Program.cs | 2 +- examples/AspNetCore/Startup.cs | 2 +- examples/Console/TestConsoleExporter.cs | 2 +- examples/Console/TestHttpClient.cs | 2 +- .../TestOTelShimWithConsoleExporter.cs | 2 +- .../TestOpenTracingWithConsoleExporter.cs | 2 +- .../ConsoleExporter.cs | 32 +++++++++---------- ....cs => ConsoleExporterHelperExtensions.cs} | 14 ++++---- 10 files changed, 30 insertions(+), 33 deletions(-) rename src/OpenTelemetry.Exporter.Console/{TracerProviderBuilderExtensions.cs => ConsoleExporterHelperExtensions.cs} (76%) diff --git a/docs/trace/building-your-own-sampler/MySampler.cs b/docs/trace/building-your-own-sampler/MySampler.cs index f2099cd2027..36efe19afd5 100644 --- a/docs/trace/building-your-own-sampler/MySampler.cs +++ b/docs/trace/building-your-own-sampler/MySampler.cs @@ -20,6 +20,6 @@ internal class MySampler : Sampler { public override SamplingResult ShouldSample(in SamplingParameters samplingParameters) { - return new SamplingResult(SamplingDecision.NotRecord); + return new SamplingResult(SamplingDecision.RecordAndSampled); } } diff --git a/docs/trace/building-your-own-sampler/Program.cs b/docs/trace/building-your-own-sampler/Program.cs index 887ca8890ba..906c6311d4d 100644 --- a/docs/trace/building-your-own-sampler/Program.cs +++ b/docs/trace/building-your-own-sampler/Program.cs @@ -16,7 +16,6 @@ using System.Diagnostics; using OpenTelemetry; -using OpenTelemetry.Exporter.Console; using OpenTelemetry.Trace; public class Program @@ -29,7 +28,7 @@ public static void Main() using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("MyCompany.MyProduct.MyLibrary") .SetSampler(new MySampler()) - .AddProcessor(new SimpleActivityProcessor(new ConsoleExporter(new ConsoleExporterOptions()))) + .AddConsoleExporter() .Build(); using (var activity = MyActivitySource.StartActivity("SayHello")) diff --git a/docs/trace/getting-started/Program.cs b/docs/trace/getting-started/Program.cs index 3b0c8b9dbc8..def1cbf7689 100644 --- a/docs/trace/getting-started/Program.cs +++ b/docs/trace/getting-started/Program.cs @@ -28,7 +28,7 @@ public static void Main() { using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("MyCompany.MyProduct.MyLibrary") - .AddProcessor(new SimpleActivityProcessor(new ConsoleExporter(new ConsoleExporterOptions()))) + .AddConsoleExporter() .Build(); using (var activity = MyActivitySource.StartActivity("SayHello")) diff --git a/examples/AspNetCore/Startup.cs b/examples/AspNetCore/Startup.cs index 068356f511f..43f81a499b8 100644 --- a/examples/AspNetCore/Startup.cs +++ b/examples/AspNetCore/Startup.cs @@ -81,7 +81,7 @@ public void ConfigureServices(IServiceCollection services) services.AddOpenTelemetry((builder) => builder .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() - .UseConsoleExporter()); + .AddConsoleExporter()); break; } } diff --git a/examples/Console/TestConsoleExporter.cs b/examples/Console/TestConsoleExporter.cs index fe8b5c024b6..1419cc32218 100644 --- a/examples/Console/TestConsoleExporter.cs +++ b/examples/Console/TestConsoleExporter.cs @@ -34,7 +34,7 @@ internal static object Run(ConsoleOptions options) .AddSource("MyCompany.MyProduct.MyWebServer") .SetResource(Resources.CreateServiceResource("MyServiceName")) .AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter - .UseConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson) + .AddConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson) .Build(); // The above line is required only in applications diff --git a/examples/Console/TestHttpClient.cs b/examples/Console/TestHttpClient.cs index e624a777b6e..ff5422f6f80 100644 --- a/examples/Console/TestHttpClient.cs +++ b/examples/Console/TestHttpClient.cs @@ -31,7 +31,7 @@ internal static object Run() .AddHttpClientInstrumentation() .SetResource(Resources.CreateServiceResource("http-service-example")) .AddSource("http-client-test") - .UseConsoleExporter(opt => opt.DisplayAsJson = false) + .AddConsoleExporter(opt => opt.DisplayAsJson = false) .Build(); var source = new ActivitySource("http-client-test"); diff --git a/examples/Console/TestOTelShimWithConsoleExporter.cs b/examples/Console/TestOTelShimWithConsoleExporter.cs index 13e0e398e99..36cd2174464 100644 --- a/examples/Console/TestOTelShimWithConsoleExporter.cs +++ b/examples/Console/TestOTelShimWithConsoleExporter.cs @@ -29,7 +29,7 @@ internal static object Run(OpenTelemetryShimOptions options) using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("MyCompany.MyProduct.MyWebServer") .SetResource(Resources.CreateServiceResource("MyServiceName")) - .UseConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson) + .AddConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson) .Build(); // The above line is required only in applications diff --git a/examples/Console/TestOpenTracingWithConsoleExporter.cs b/examples/Console/TestOpenTracingWithConsoleExporter.cs index cda0b03aa5c..e5751e84d93 100644 --- a/examples/Console/TestOpenTracingWithConsoleExporter.cs +++ b/examples/Console/TestOpenTracingWithConsoleExporter.cs @@ -32,7 +32,7 @@ internal static object Run(OpenTracingShimOptions options) using var openTelemetry = Sdk.CreateTracerProviderBuilder() .AddSource("MyCompany.MyProduct.MyWebServer") .SetResource(Resources.CreateServiceResource("MyServiceName")) - .UseConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson) + .AddConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson) .Build(); // The above line is required only in applications diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs index 44b959c76f7..0c973d131b4 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs @@ -56,30 +56,30 @@ public override Task ExportAsync(IEnumerable activityBat } else { - System.Console.WriteLine("Activity ID - " + activity.Id); + System.Console.WriteLine($"Activity.Id: {activity.Id}"); if (!string.IsNullOrEmpty(activity.ParentId)) { - System.Console.WriteLine("Activity ParentId - " + activity.ParentId); + System.Console.WriteLine($"Activity.ParentId: {activity.ParentId}"); } - System.Console.WriteLine("Activity DisplayName - " + activity.DisplayName); - System.Console.WriteLine("Activity Kind - " + activity.Kind); - System.Console.WriteLine("Activity StartTime - " + activity.StartTimeUtc); - System.Console.WriteLine("Activity Duration - " + activity.Duration); + System.Console.WriteLine($"Activity.DisplayName: {activity.DisplayName}"); + System.Console.WriteLine($"Activity.Kind: {activity.Kind}"); + System.Console.WriteLine($"Activity.StartTime: {activity.StartTimeUtc:yyyy-MM-ddTHH:mm:ss.fffffffZ}"); + System.Console.WriteLine($"Activity.Duration: {activity.Duration}"); if (activity.TagObjects.Any()) { - System.Console.WriteLine("Activity Tags"); + System.Console.WriteLine("Activity.TagObjects:"); foreach (var tag in activity.TagObjects) { var array = tag.Value as Array; if (array == null) { - System.Console.WriteLine($"\t {tag.Key} : {tag.Value}"); + System.Console.WriteLine($" {tag.Key}: {tag.Value}"); continue; } - System.Console.Write($"\t {tag.Key} : ["); + System.Console.Write($" {tag.Key}: ["); for (int i = 0; i < array.Length; i++) { @@ -93,33 +93,33 @@ public override Task ExportAsync(IEnumerable activityBat if (activity.Events.Any()) { - System.Console.WriteLine("Activity Events"); + System.Console.WriteLine("Activity.Events:"); foreach (var activityEvent in activity.Events) { - System.Console.WriteLine($"Event Name: {activityEvent.Name} TimeStamp: {activityEvent.Timestamp}"); + System.Console.WriteLine($" {activityEvent.Name} [{activityEvent.Timestamp}]"); foreach (var attribute in activityEvent.Tags) { - System.Console.WriteLine($"\t {attribute.Key} : {attribute.Value}"); + System.Console.WriteLine($" {attribute.Key}: {attribute.Value}"); } } } if (activity.Baggage.Any()) { - System.Console.WriteLine("Activity Baggage"); + System.Console.WriteLine("Activity.Baggage:"); foreach (var baggage in activity.Baggage) { - System.Console.WriteLine($"\t {baggage.Key} : {baggage.Value}"); + System.Console.WriteLine($" {baggage.Key}: {baggage.Value}"); } } var resource = activity.GetResource(); if (resource != Resource.Empty) { - System.Console.WriteLine("Resource associated with Activity"); + System.Console.WriteLine("Resource associated with Activity:"); foreach (var resourceAttribute in resource.Attributes) { - System.Console.WriteLine($"\t {resourceAttribute.Key} : {resourceAttribute.Value}"); + System.Console.WriteLine($" {resourceAttribute.Key}: {resourceAttribute.Value}"); } } diff --git a/src/OpenTelemetry.Exporter.Console/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs similarity index 76% rename from src/OpenTelemetry.Exporter.Console/TracerProviderBuilderExtensions.cs rename to src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs index f0231399a17..6c6fc366f1e 100644 --- a/src/OpenTelemetry.Exporter.Console/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ namespace OpenTelemetry.Trace { - public static class TracerProviderBuilderExtensions + public static class ConsoleExporterHelperExtensions { /// /// Registers a ConsoleActivity exporter to a processing pipeline. @@ -27,18 +27,16 @@ public static class TracerProviderBuilderExtensions /// builder to use. /// Exporter configuration options. /// The instance of to chain the calls. - public static TracerProviderBuilder UseConsoleExporter(this TracerProviderBuilder builder, Action configure = null) + public static TracerProviderBuilder AddConsoleExporter(this TracerProviderBuilder builder, Action configure = null) { - // TODO: Rename to AddConsoleExporter? if (builder == null) { throw new ArgumentNullException(nameof(builder)); } - var exporterOptions = new ConsoleExporterOptions(); - configure?.Invoke(exporterOptions); - var consoleExporter = new ConsoleExporter(exporterOptions); - return builder.AddProcessor(new SimpleActivityProcessor(consoleExporter)); + var options = new ConsoleExporterOptions(); + configure?.Invoke(options); + return builder.AddProcessor(new SimpleActivityProcessor(new ConsoleExporter(options))); } } } From c14b710d22c3d7ea94bc78b17aab6371925cbcd5 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 11 Aug 2020 23:48:13 -0700 Subject: [PATCH 2/2] update changelog --- src/OpenTelemetry.Exporter.Console/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md index 2410d0bec7a..c8f27a6c79d 100644 --- a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md @@ -2,6 +2,13 @@ ## Unreleased +* Changed `UseConsoleExporter` to `AddConsoleExporter`, improved readability + ([#1051](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1051)) + +## 0.4.0-beta.2 + +Released 2020-07-24 + ## 0.3.0-beta Released 2020-07-23