From fcde600f221951812d95119b15463f4005e99815 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Tue, 3 Nov 2020 20:10:48 -0800 Subject: [PATCH] Add extension method to add ConsoleExporter for logs (#1452) * Added an extension method to add ConsoleExporter for logs; Updated the logs getting-started docs to add ConsoleExporter * Updated CHANGELOG.md * Addressing PR comments Co-authored-by: Cijo Thomas --- docs/logs/getting-started/Program.cs | 3 +- .../getting-started/getting-started.csproj | 4 +- .../CHANGELOG.md | 6 +++ .../ConsoleExporterLoggingExtensions.cs | 45 +++++++++++++++++++ src/OpenTelemetry.Exporter.Console/README.md | 2 +- 5 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs diff --git a/docs/logs/getting-started/Program.cs b/docs/logs/getting-started/Program.cs index fcf12ae99..a86fee8f3 100644 --- a/docs/logs/getting-started/Program.cs +++ b/docs/logs/getting-started/Program.cs @@ -14,6 +14,7 @@ // limitations under the License. // +using OpenTelemetry.Trace; #if NETCOREAPP2_1 using Microsoft.Extensions.DependencyInjection; #endif @@ -30,7 +31,7 @@ public class Program #endif { builder.AddOpenTelemetry(options => options - .AddInMemoryExporter()); // TODO: change to console output + .AddConsoleExporter()); }); #if NETCOREAPP2_1 diff --git a/docs/logs/getting-started/getting-started.csproj b/docs/logs/getting-started/getting-started.csproj index 937bc2133..4db489c91 100644 --- a/docs/logs/getting-started/getting-started.csproj +++ b/docs/logs/getting-started/getting-started.csproj @@ -1,6 +1,6 @@ - + - + diff --git a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md index 20c68acaf..498b1f9df 100644 --- a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +* Add extension method to add `ConsoleExporter` for logs + ([#1452](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1452)) + +* Generalized `ConsoleExporter` to add support for logs + ([#1438](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1438)) + ## 0.7.0-beta.1 Released 2020-Oct-16 diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs new file mode 100644 index 000000000..3b138f6a9 --- /dev/null +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs @@ -0,0 +1,45 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#if NET461 || NETSTANDARD2_0 +using System; +using OpenTelemetry.Exporter; +using OpenTelemetry.Logs; + +namespace OpenTelemetry.Trace +{ + public static class ConsoleExporterLoggingExtensions + { + /// + /// Adds Console Exporter as a configuration to the OpenTelemetry ILoggingBuilder. + /// + /// options to use. + /// Exporter configuration options. + /// The instance of to chain the calls. + public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLoggerOptions loggerOptions, Action configure = null) + { + if (loggerOptions == null) + { + throw new ArgumentNullException(nameof(loggerOptions)); + } + + var options = new ConsoleExporterOptions(); + configure?.Invoke(options); + return loggerOptions.AddProcessor(new SimpleExportProcessor(new ConsoleExporter(options))); + } + } +} +#endif diff --git a/src/OpenTelemetry.Exporter.Console/README.md b/src/OpenTelemetry.Exporter.Console/README.md index e6df1df6e..79c7fec6b 100644 --- a/src/OpenTelemetry.Exporter.Console/README.md +++ b/src/OpenTelemetry.Exporter.Console/README.md @@ -3,7 +3,7 @@ [![NuGet](https://img.shields.io/nuget/v/OpenTelemetry.Exporter.Console.svg)](https://www.nuget.org/packages/OpenTelemetry.Exporter.Console) [![NuGet](https://img.shields.io/nuget/dt/OpenTelemetry.Exporter.Console.svg)](https://www.nuget.org/packages/OpenTelemetry.Exporter.Console) -The console exporter prints data to the Console in a JSON serialized format. +The console exporter prints data to the Console window. **Note:** this exporter is intended to be used during learning how telemetry data are created and exported. It is not recommended for any production