Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update console exporter #1051

Merged
merged 2 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/trace/building-your-own-sampler/MySampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 1 addition & 2 deletions docs/trace/building-your-own-sampler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Exporter.Console;
using OpenTelemetry.Trace;

public class Program
Expand All @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion docs/trace/getting-started/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion examples/AspNetCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddOpenTelemetry((builder) => builder
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.UseConsoleExporter());
.AddConsoleExporter());
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestOTelShimWithConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestOpenTracingWithConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/OpenTelemetry.Exporter.Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,30 @@ public override Task<ExportResult> ExportAsync(IEnumerable<Activity> 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++)
{
Expand All @@ -93,33 +93,33 @@ public override Task<ExportResult> ExportAsync(IEnumerable<Activity> 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}");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="TracerProviderBuilderExtensions.cs" company="OpenTelemetry Authors">
// <copyright file="ConsoleExporterHelperExtensions.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,26 +19,24 @@

namespace OpenTelemetry.Trace
{
public static class TracerProviderBuilderExtensions
public static class ConsoleExporterHelperExtensions
{
/// <summary>
/// Registers a ConsoleActivity exporter to a processing pipeline.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> builder to use.</param>
/// <param name="configure">Exporter configuration options.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder UseConsoleExporter(this TracerProviderBuilder builder, Action<ConsoleExporterOptions> configure = null)
public static TracerProviderBuilder AddConsoleExporter(this TracerProviderBuilder builder, Action<ConsoleExporterOptions> 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)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we let user pick Simple vs Batched for other exporters?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it doesn't make much sense for console exporter to be batched as it is specifically designed for local dev scenario?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea. I was asking general approach for other exporters which can operate in simple and batch mode..

}
}
}