Skip to content

Commit

Permalink
Merge branch 'master' into exporter-spec2
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Nov 28, 2020
2 parents 33c6381 + fe9e90d commit 77334ae
Show file tree
Hide file tree
Showing 17 changed files with 521 additions and 147 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
OpenTelemetry.Exporter.Console.ConsoleActivityExporter
OpenTelemetry.Exporter.Console.ConsoleActivityExporter.ConsoleActivityExporter(OpenTelemetry.Exporter.ConsoleExporterOptions options) -> void
OpenTelemetry.Exporter.ConsoleExporter<T>
OpenTelemetry.Exporter.ConsoleExporter<T>.ConsoleExporter(OpenTelemetry.Exporter.ConsoleExporterOptions options) -> void
OpenTelemetry.Exporter.ConsoleExporter<T>.WriteLine(string message) -> void
OpenTelemetry.Exporter.ConsoleExporterOptions
OpenTelemetry.Exporter.ConsoleExporterOptions.ConsoleExporterOptions() -> void
OpenTelemetry.Exporter.ConsoleExporterOptions.Targets.get -> OpenTelemetry.Exporter.ConsoleExporterOutputTargets
Expand All @@ -8,5 +11,5 @@ OpenTelemetry.Exporter.ConsoleExporterOutputTargets
OpenTelemetry.Exporter.ConsoleExporterOutputTargets.Console = 1 -> OpenTelemetry.Exporter.ConsoleExporterOutputTargets
OpenTelemetry.Exporter.ConsoleExporterOutputTargets.Debug = 2 -> OpenTelemetry.Exporter.ConsoleExporterOutputTargets
OpenTelemetry.Trace.ConsoleExporterHelperExtensions
override OpenTelemetry.Exporter.ConsoleExporter<T>.Export(in OpenTelemetry.Batch<T> batch) -> OpenTelemetry.ExportResult
override OpenTelemetry.Exporter.Console.ConsoleActivityExporter.Export(in OpenTelemetry.Batch<System.Diagnostics.Activity> batch) -> OpenTelemetry.ExportResult
static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Exporter.ConsoleExporterOptions> configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
OpenTelemetry.Exporter.Console.ConsoleActivityExporter
OpenTelemetry.Exporter.Console.ConsoleActivityExporter.ConsoleActivityExporter(OpenTelemetry.Exporter.ConsoleExporterOptions options) -> void
OpenTelemetry.Exporter.Console.ConsoleLogRecordExporter
OpenTelemetry.Exporter.Console.ConsoleLogRecordExporter.ConsoleLogRecordExporter(OpenTelemetry.Exporter.ConsoleExporterOptions options) -> void
OpenTelemetry.Exporter.ConsoleExporter<T>
OpenTelemetry.Exporter.ConsoleExporter<T>.ConsoleExporter(OpenTelemetry.Exporter.ConsoleExporterOptions options) -> void
OpenTelemetry.Exporter.ConsoleExporter<T>.WriteLine(string message) -> void
OpenTelemetry.Exporter.ConsoleExporterOptions
OpenTelemetry.Exporter.ConsoleExporterOptions.ConsoleExporterOptions() -> void
OpenTelemetry.Exporter.ConsoleExporterOptions.Targets.get -> OpenTelemetry.Exporter.ConsoleExporterOutputTargets
Expand All @@ -9,6 +14,7 @@ OpenTelemetry.Exporter.ConsoleExporterOutputTargets.Console = 1 -> OpenTelemetry
OpenTelemetry.Exporter.ConsoleExporterOutputTargets.Debug = 2 -> OpenTelemetry.Exporter.ConsoleExporterOutputTargets
OpenTelemetry.Trace.ConsoleExporterHelperExtensions
OpenTelemetry.Logs.ConsoleExporterLoggingExtensions
override OpenTelemetry.Exporter.ConsoleExporter<T>.Export(in OpenTelemetry.Batch<T> batch) -> OpenTelemetry.ExportResult
override OpenTelemetry.Exporter.Console.ConsoleActivityExporter.Export(in OpenTelemetry.Batch<System.Diagnostics.Activity> batch) -> OpenTelemetry.ExportResult
override OpenTelemetry.Exporter.Console.ConsoleLogRecordExporter.Export(in OpenTelemetry.Batch<OpenTelemetry.Logs.LogRecord> batch) -> OpenTelemetry.ExportResult
static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Exporter.ConsoleExporterOptions> configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action<OpenTelemetry.Exporter.ConsoleExporterOptions> configure = null) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
OpenTelemetry.Exporter.Console.ConsoleActivityExporter
OpenTelemetry.Exporter.Console.ConsoleActivityExporter.ConsoleActivityExporter(OpenTelemetry.Exporter.ConsoleExporterOptions options) -> void
OpenTelemetry.Exporter.Console.ConsoleLogRecordExporter
OpenTelemetry.Exporter.Console.ConsoleLogRecordExporter.ConsoleLogRecordExporter(OpenTelemetry.Exporter.ConsoleExporterOptions options) -> void
OpenTelemetry.Exporter.ConsoleExporter<T>
OpenTelemetry.Exporter.ConsoleExporter<T>.ConsoleExporter(OpenTelemetry.Exporter.ConsoleExporterOptions options) -> void
OpenTelemetry.Exporter.ConsoleExporter<T>.WriteLine(string message) -> void
OpenTelemetry.Exporter.ConsoleExporterOptions
OpenTelemetry.Exporter.ConsoleExporterOptions.ConsoleExporterOptions() -> void
OpenTelemetry.Exporter.ConsoleExporterOptions.Targets.get -> OpenTelemetry.Exporter.ConsoleExporterOutputTargets
Expand All @@ -9,6 +14,7 @@ OpenTelemetry.Exporter.ConsoleExporterOutputTargets.Console = 1 -> OpenTelemetry
OpenTelemetry.Exporter.ConsoleExporterOutputTargets.Debug = 2 -> OpenTelemetry.Exporter.ConsoleExporterOutputTargets
OpenTelemetry.Trace.ConsoleExporterHelperExtensions
OpenTelemetry.Logs.ConsoleExporterLoggingExtensions
override OpenTelemetry.Exporter.ConsoleExporter<T>.Export(in OpenTelemetry.Batch<T> batch) -> OpenTelemetry.ExportResult
override OpenTelemetry.Exporter.Console.ConsoleActivityExporter.Export(in OpenTelemetry.Batch<System.Diagnostics.Activity> batch) -> OpenTelemetry.ExportResult
override OpenTelemetry.Exporter.Console.ConsoleLogRecordExporter.Export(in OpenTelemetry.Batch<OpenTelemetry.Logs.LogRecord> batch) -> OpenTelemetry.ExportResult
static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Exporter.ConsoleExporterOptions> configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action<OpenTelemetry.Exporter.ConsoleExporterOptions> configure = null) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
`OpenTelemetry.Trace` namespace to `OpenTelemetry.Logs` namespace.
([#1576](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1576))

* Added `ConsoleActivityExporter` and `ConsoleLogExporter`. Refactored
`ConsoleExporter` to get rid of type specific check in the class
([#1593](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1593))

## 1.0.0-rc1.1

Released 2020-Nov-17
Expand Down
100 changes: 100 additions & 0 deletions src/OpenTelemetry.Exporter.Console/ConsoleActivityExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// <copyright file="ConsoleActivityExporter.cs" company="OpenTelemetry Authors">
// 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.
// </copyright>

using System;
using System.Diagnostics;
using System.Linq;
using OpenTelemetry.Resources;

namespace OpenTelemetry.Exporter.Console
{
public class ConsoleActivityExporter : ConsoleExporter<Activity>
{
public ConsoleActivityExporter(ConsoleExporterOptions options)
: base(options)
{
}

public override ExportResult Export(in Batch<Activity> batch)
{
foreach (var activity in batch)
{
this.WriteLine($"Activity.Id: {activity.Id}");
if (!string.IsNullOrEmpty(activity.ParentId))
{
this.WriteLine($"Activity.ParentId: {activity.ParentId}");
}

this.WriteLine($"Activity.DisplayName: {activity.DisplayName}");
this.WriteLine($"Activity.Kind: {activity.Kind}");
this.WriteLine($"Activity.StartTime: {activity.StartTimeUtc:yyyy-MM-ddTHH:mm:ss.fffffffZ}");
this.WriteLine($"Activity.Duration: {activity.Duration}");
if (activity.TagObjects.Any())
{
this.WriteLine("Activity.TagObjects:");
foreach (var tag in activity.TagObjects)
{
var array = tag.Value as Array;

if (array == null)
{
this.WriteLine($" {tag.Key}: {tag.Value}");
continue;
}

this.WriteLine($" {tag.Key}: [{string.Join(", ", array.Cast<object>())}]");
}
}

if (activity.Events.Any())
{
this.WriteLine("Activity.Events:");
foreach (var activityEvent in activity.Events)
{
this.WriteLine($" {activityEvent.Name} [{activityEvent.Timestamp}]");
foreach (var attribute in activityEvent.Tags)
{
this.WriteLine($" {attribute.Key}: {attribute.Value}");
}
}
}

if (activity.Baggage.Any())
{
this.WriteLine("Activity.Baggage:");
foreach (var baggage in activity.Baggage)
{
this.WriteLine($" {baggage.Key}: {baggage.Value}");
}
}

var resource = this.ParentProvider.GetResource();
if (resource != Resource.Empty)
{
this.WriteLine("Resource associated with Activity:");
foreach (var resourceAttribute in resource.Attributes)
{
this.WriteLine($" {resourceAttribute.Key}: {resourceAttribute.Value}");
}
}

this.WriteLine(string.Empty);
}

return ExportResult.Success;
}
}
}
132 changes: 4 additions & 128 deletions src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,155 +14,31 @@
// limitations under the License.
// </copyright>

using System;
using System.Diagnostics;
using System.Linq;
#if NET461 || NETSTANDARD2_0
using OpenTelemetry.Logs;
#endif
using OpenTelemetry.Resources;

namespace OpenTelemetry.Exporter
{
public class ConsoleExporter<T> : BaseExporter<T>
public abstract class ConsoleExporter<T> : BaseExporter<T>
where T : class
{
private readonly ConsoleExporterOptions options;

public ConsoleExporter(ConsoleExporterOptions options)
protected ConsoleExporter(ConsoleExporterOptions options)
{
this.options = options ?? new ConsoleExporterOptions();
}

public override ExportResult Export(in Batch<T> batch)
{
if (typeof(T) == typeof(Activity))
{
foreach (var item in batch)
{
var activity = item as Activity;
this.WriteLine($"Activity.Id: {activity.Id}");
if (!string.IsNullOrEmpty(activity.ParentId))
{
this.WriteLine($"Activity.ParentId: {activity.ParentId}");
}

this.WriteLine($"Activity.DisplayName: {activity.DisplayName}");
this.WriteLine($"Activity.Kind: {activity.Kind}");
this.WriteLine($"Activity.StartTime: {activity.StartTimeUtc:yyyy-MM-ddTHH:mm:ss.fffffffZ}");
this.WriteLine($"Activity.Duration: {activity.Duration}");
if (activity.TagObjects.Any())
{
this.WriteLine("Activity.TagObjects:");
foreach (var tag in activity.TagObjects)
{
var array = tag.Value as Array;

if (array == null)
{
this.WriteLine($" {tag.Key}: {tag.Value}");
continue;
}

this.Write($" {tag.Key}: [");

for (int i = 0; i < array.Length; i++)
{
this.Write(i != 0 ? ", " : string.Empty);
this.Write($"{array.GetValue(i)}");
}

this.WriteLine($"]");
}
}

if (activity.Events.Any())
{
this.WriteLine("Activity.Events:");
foreach (var activityEvent in activity.Events)
{
this.WriteLine($" {activityEvent.Name} [{activityEvent.Timestamp}]");
foreach (var attribute in activityEvent.Tags)
{
this.WriteLine($" {attribute.Key}: {attribute.Value}");
}
}
}

if (activity.Baggage.Any())
{
this.WriteLine("Activity.Baggage:");
foreach (var baggage in activity.Baggage)
{
this.WriteLine($" {baggage.Key}: {baggage.Value}");
}
}

var resource = this.ParentProvider.GetResource();
if (resource != Resource.Empty)
{
this.WriteLine("Resource associated with Activity:");
foreach (var resourceAttribute in resource.Attributes)
{
this.WriteLine($" {resourceAttribute.Key}: {resourceAttribute.Value}");
}
}

this.WriteLine(string.Empty);
}
}
#if NET461 || NETSTANDARD2_0
else if (typeof(T) == typeof(LogRecord))
{
var rightPaddingLength = 30;
foreach (var item in batch)
{
var logRecord = item as LogRecord;
this.WriteLine($"{"LogRecord.TraceId:".PadRight(rightPaddingLength)}{logRecord.TraceId}");
this.WriteLine($"{"LogRecord.SpanId:".PadRight(rightPaddingLength)}{logRecord.SpanId}");
this.WriteLine($"{"LogRecord.Timestamp:".PadRight(rightPaddingLength)}{logRecord.Timestamp:yyyy-MM-ddTHH:mm:ss.fffffffZ}");
this.WriteLine($"{"LogRecord.EventId:".PadRight(rightPaddingLength)}{logRecord.EventId}");
this.WriteLine($"{"LogRecord.CategoryName:".PadRight(rightPaddingLength)}{logRecord.CategoryName}");
this.WriteLine($"{"LogRecord.LogLevel:".PadRight(rightPaddingLength)}{logRecord.LogLevel}");
this.WriteLine($"{"LogRecord.TraceFlags:".PadRight(rightPaddingLength)}{logRecord.TraceFlags}");
this.WriteLine($"{"LogRecord.State:".PadRight(rightPaddingLength)}{logRecord.State}");
if (logRecord.Exception is { })
{
this.WriteLine($"{"LogRecord.Exception:".PadRight(rightPaddingLength)}{logRecord.Exception?.Message}");
}

this.WriteLine(string.Empty);
}
}
#endif

return ExportResult.Success;
}

private void WriteLine(string message)
protected void WriteLine(string message)
{
if (this.options.Targets.HasFlag(ConsoleExporterOutputTargets.Console))
{
Console.WriteLine(message);
System.Console.WriteLine(message);
}

if (this.options.Targets.HasFlag(ConsoleExporterOutputTargets.Debug))
{
Debug.WriteLine(message);
}
}

private void Write(string message)
{
if (this.options.Targets.HasFlag(ConsoleExporterOutputTargets.Console))
{
Console.Write(message);
}

if (this.options.Targets.HasFlag(ConsoleExporterOutputTargets.Debug))
{
Debug.Write(message);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System;
using System.Diagnostics;
using OpenTelemetry.Exporter;
using OpenTelemetry.Exporter.Console;

namespace OpenTelemetry.Trace
{
Expand All @@ -38,7 +39,7 @@ public static TracerProviderBuilder AddConsoleExporter(this TracerProviderBuilde

var options = new ConsoleExporterOptions();
configure?.Invoke(options);
return builder.AddProcessor(new SimpleExportProcessor<Activity>(new ConsoleExporter<Activity>(options)));
return builder.AddProcessor(new SimpleExportProcessor<Activity>(new ConsoleActivityExporter(options)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#if NET461 || NETSTANDARD2_0
using System;
using OpenTelemetry.Exporter;
using OpenTelemetry.Exporter.Console;

namespace OpenTelemetry.Logs
{
Expand All @@ -37,7 +38,7 @@ public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLo

var options = new ConsoleExporterOptions();
configure?.Invoke(options);
return loggerOptions.AddProcessor(new SimpleExportProcessor<LogRecord>(new ConsoleExporter<LogRecord>(options)));
return loggerOptions.AddProcessor(new SimpleExportProcessor<LogRecord>(new ConsoleLogRecordExporter(options)));
}
}
}
Expand Down
Loading

0 comments on commit 77334ae

Please sign in to comment.