Update console exporter (#1051)

* update console exporter

* update changelog
This commit is contained in:
Reiley Yang 2020-08-12 00:17:35 -07:00 committed by GitHub
parent c852a32306
commit 7b86d25274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 37 additions and 33 deletions

View File

@ -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);
}
}

View File

@ -16,7 +16,6 @@
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Exporter.Console;
using OpenTelemetry.Trace;
public class Program
@ -29,7 +28,7 @@ public class Program
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"))

View File

@ -28,7 +28,7 @@ public class Program
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("MyCompany.MyProduct.MyLibrary")
.AddProcessor(new SimpleActivityProcessor(new ConsoleExporter(new ConsoleExporterOptions())))
.AddConsoleExporter()
.Build();
using (var activity = MyActivitySource.StartActivity("SayHello"))

View File

@ -81,7 +81,7 @@ namespace Examples.AspNetCore
services.AddOpenTelemetry((builder) => builder
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.UseConsoleExporter());
.AddConsoleExporter());
break;
}
}

View File

@ -34,7 +34,7 @@ namespace Examples.Console
.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

View File

@ -31,7 +31,7 @@ namespace Examples.Console
.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");

View File

@ -29,7 +29,7 @@ namespace Examples.Console
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

View File

@ -32,7 +32,7 @@ namespace Examples.Console
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

View File

@ -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

View File

@ -56,30 +56,30 @@ namespace OpenTelemetry.Exporter.Console
}
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 @@ namespace OpenTelemetry.Exporter.Console
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}");
}
}

View File

@ -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");
@ -19,7 +19,7 @@ using OpenTelemetry.Exporter.Console;
namespace OpenTelemetry.Trace
{
public static class TracerProviderBuilderExtensions
public static class ConsoleExporterHelperExtensions
{
/// <summary>
/// Registers a ConsoleActivity exporter to a processing pipeline.
@ -27,18 +27,16 @@ namespace OpenTelemetry.Trace
/// <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)));
}
}
}