Skip to content

Commit

Permalink
Log dropped telemetry item count on shutdown (#2331)
Browse files Browse the repository at this point in the history
  • Loading branch information
mic-max authored Sep 21, 2021
1 parent a538016 commit 032f22d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/Console/TestJaegerExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ internal static object RunWithActivity(string host, int port)
{
sample.Start();

System.Console.WriteLine("Traces are being created and exported" +
"to Jaeger in the background. Use Jaeger to view them." +
System.Console.WriteLine("Traces are being created and exported " +
"to Jaeger in the background. Use Jaeger to view them. " +
"Press ENTER to stop.");
System.Console.ReadLine();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestOtlpExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static object RunWithActivitySource(string endpoint)
{
sample.Start();

System.Console.WriteLine("Traces are being created and exported" +
System.Console.WriteLine("Traces are being created and exported " +
"to the OpenTelemetry Collector in the background. " +
"Press ENTER to stop.");
System.Console.ReadLine();
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestZipkinExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal static object Run(string zipkinUri)
{
sample.Start();

System.Console.WriteLine("Traces are being created and exported" +
System.Console.WriteLine("Traces are being created and exported " +
"to Zipkin in the background. Use Zipkin to view them. " +
"Press ENTER to stop.");
System.Console.ReadLine();
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry/BatchExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ protected override bool OnShutdown(int timeoutMilliseconds)
this.shutdownDrainTarget = this.circularBuffer.AddedCount;
this.shutdownTrigger.Set();

OpenTelemetrySdkEventSource.Log.DroppedExportProcessorItems(this.GetType().Name, this.exporter.GetType().Name, this.droppedCount);

if (timeoutMilliseconds == Timeout.Infinite)
{
this.exporterThread.Join();
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* `BatchExportProcessor.OnShutdown` will now log the count of dropped telemetry items.
([#2331](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2331))
* Changed `CompositeProcessor<T>.OnForceFlush` to meet with the spec
requirement. Now the SDK will invoke `ForceFlush` on all registered
processors, even if there is a timeout.
Expand Down
31 changes: 31 additions & 0 deletions src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,25 @@ public void MissingPermissionsToReadEnvironmentVariable(SecurityException ex)
}
}

[NonEvent]
public void DroppedExportProcessorItems(string exportProcessorName, string exporterName, long droppedCount)
{
if (droppedCount > 0)
{
if (this.IsEnabled(EventLevel.Warning, EventKeywords.All))
{
this.ExistsDroppedExportProcessorItems(exportProcessorName, exporterName, droppedCount);
}
}
else
{
if (this.IsEnabled(EventLevel.Informational, EventKeywords.All))
{
this.NoDroppedExportProcessorItems(exportProcessorName, exporterName);
}
}
}

[Event(1, Message = "Span processor queue size reached maximum. Throttling spans.", Level = EventLevel.Warning)]
public void SpanProcessorQueueIsExhausted()
{
Expand Down Expand Up @@ -309,6 +328,18 @@ public void MissingPermissionsToReadEnvironmentVariable(string exception)
this.WriteEvent(30, exception);
}

[Event(31, Message = "'{0}' exporting to '{1}' dropped '0' items.", Level = EventLevel.Informational)]
public void NoDroppedExportProcessorItems(string exportProcessorName, string exporterName)
{
this.WriteEvent(31, exportProcessorName, exporterName);
}

[Event(32, Message = "'{0}' exporting to '{1}' dropped '{2}' item(s) due to buffer full.", Level = EventLevel.Warning)]
public void ExistsDroppedExportProcessorItems(string exportProcessorName, string exporterName, long droppedCount)
{
this.WriteEvent(32, exportProcessorName, exporterName, droppedCount);
}

#if DEBUG
public class OpenTelemetryEventListener : EventListener
{
Expand Down

0 comments on commit 032f22d

Please sign in to comment.