Basic eventsource logging for ZipkinExporter and minor renamings (#877)

* Rename to OpenTelemetryProtocolExporterEventSource

* Add basic eventsource logging int ZipkinExporter

* clean readme
This commit is contained in:
Cijo Thomas 2020-07-22 06:53:39 -07:00 committed by GitHub
parent 13dd5d717e
commit 1ed4a28927
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 17 deletions

View File

@ -1,4 +1,4 @@
// <copyright file="ExporterEventSource.cs" company="OpenTelemetry Authors">
// <copyright file="OpenTelemetryProtocolExporterEventSource.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -22,9 +22,9 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
using System.Threading;
[EventSource(Name = "OpenTelemetry-Exporter-OpenTelemetryProtocol")]
internal class ExporterEventSource : EventSource
internal class OpenTelemetryProtocolExporterEventSource : EventSource
{
public static readonly ExporterEventSource Log = new ExporterEventSource();
public static readonly OpenTelemetryProtocolExporterEventSource Log = new OpenTelemetryProtocolExporterEventSource();
[NonEvent]
public void FailedToConvertToProtoDefinitionError(Exception ex)

View File

@ -63,7 +63,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
}
catch (RpcException ex)
{
ExporterEventSource.Log.FailedToReachCollector(ex);
OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(ex);
return ExportResult.FailedRetryable;
}

View File

@ -0,0 +1,66 @@
// <copyright file="ZipkinExporterEventSource.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.Tracing;
using System.Globalization;
using System.Threading;
namespace OpenTelemetry.Exporter.Zipkin.Implementation
{
/// <summary>
/// EventSource events emitted from the project.
/// </summary>
[EventSource(Name = "OpenTelemetry-Exporter-Zipkin")]
internal class ZipkinExporterEventSource : EventSource
{
public static ZipkinExporterEventSource Log = new ZipkinExporterEventSource();
[NonEvent]
public void FailedExport(Exception ex)
{
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
{
this.FailedExport(ToInvariantString(ex));
}
}
[Event(1, Message = "Failed to export activities: '{0}'", Level = EventLevel.Error)]
public void FailedExport(string exception)
{
this.WriteEvent(1, exception);
}
/// <summary>
/// Returns a culture-independent string representation of the given <paramref name="exception"/> object,
/// appropriate for diagnostics tracing.
/// </summary>
private static string ToInvariantString(Exception exception)
{
var originalUICulture = Thread.CurrentThread.CurrentUICulture;
try
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
return exception.ToString();
}
finally
{
Thread.CurrentThread.CurrentUICulture = originalUICulture;
}
}
}
}

View File

@ -64,8 +64,10 @@ namespace OpenTelemetry.Exporter.Zipkin
await this.SendBatchActivityAsync(batchActivity).ConfigureAwait(false);
return ExportResult.Success;
}
catch (Exception)
catch (Exception ex)
{
ZipkinExporterEventSource.Log.FailedExport(ex);
// TODO distinguish retryable exceptions
return ExportResult.FailedNotRetryable;
}

View File

@ -29,15 +29,6 @@ namespace OpenTelemetry.Instrumentation
{
public static InstrumentationEventSource Log = new InstrumentationEventSource();
[NonEvent]
public void ExceptionInCustomSampler(Exception ex)
{
if (this.IsEnabled(EventLevel.Warning, (EventKeywords)(-1)))
{
this.ExceptionInCustomSampler(ToInvariantString(ex));
}
}
[Event(1, Message = "Span is NULL or blank in the '{0}' callback. Span will not be recorded.", Level = EventLevel.Warning)]
public void NullOrBlankSpan(string eventName)
{

View File

@ -89,15 +89,15 @@ Run the application. Traces will be displayed in the console.
are used to control the noise and overhead introduced by OpenTelemetry by
reducing the number of samples of traces collected and sent to the backend. If
no sampler is explicitly specified, the default is to use
[AlwaysOnActivitySampler](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#alwayson).
[AlwaysOnSampler](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#alwayson).
The following sample shows how to change it to
[ProbabilityActivitySampler](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#probability)
[ProbabilitySampler](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#probability)
with sampling probability of 25%.
```csharp
using var openTelemetry = OpenTelemetrySdk.EnableOpenTelemetry(builder => builder
.AddActivitySource("companyname.product.library")
.SetSampler(new ProbabilityActivitySampler(.25))
.SetSampler(new ProbabilitySampler(.25))
.UseConsoleExporter());
```