Skip to content

Commit 032f22d

Browse files
authored
Log dropped telemetry item count on shutdown (#2331)
1 parent a538016 commit 032f22d

File tree

6 files changed

+39
-4
lines changed

6 files changed

+39
-4
lines changed

examples/Console/TestJaegerExporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ internal static object RunWithActivity(string host, int port)
8787
{
8888
sample.Start();
8989

90-
System.Console.WriteLine("Traces are being created and exported" +
91-
"to Jaeger in the background. Use Jaeger to view them." +
90+
System.Console.WriteLine("Traces are being created and exported " +
91+
"to Jaeger in the background. Use Jaeger to view them. " +
9292
"Press ENTER to stop.");
9393
System.Console.ReadLine();
9494
}

examples/Console/TestOtlpExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private static object RunWithActivitySource(string endpoint)
7373
{
7474
sample.Start();
7575

76-
System.Console.WriteLine("Traces are being created and exported" +
76+
System.Console.WriteLine("Traces are being created and exported " +
7777
"to the OpenTelemetry Collector in the background. " +
7878
"Press ENTER to stop.");
7979
System.Console.ReadLine();

examples/Console/TestZipkinExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal static object Run(string zipkinUri)
5050
{
5151
sample.Start();
5252

53-
System.Console.WriteLine("Traces are being created and exported" +
53+
System.Console.WriteLine("Traces are being created and exported " +
5454
"to Zipkin in the background. Use Zipkin to view them. " +
5555
"Press ENTER to stop.");
5656
System.Console.ReadLine();

src/OpenTelemetry/BatchExportProcessor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ protected override bool OnShutdown(int timeoutMilliseconds)
186186
this.shutdownDrainTarget = this.circularBuffer.AddedCount;
187187
this.shutdownTrigger.Set();
188188

189+
OpenTelemetrySdkEventSource.Log.DroppedExportProcessorItems(this.GetType().Name, this.exporter.GetType().Name, this.droppedCount);
190+
189191
if (timeoutMilliseconds == Timeout.Infinite)
190192
{
191193
this.exporterThread.Join();

src/OpenTelemetry/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
* `BatchExportProcessor.OnShutdown` will now log the count of dropped telemetry items.
6+
([#2331](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2331))
57
* Changed `CompositeProcessor<T>.OnForceFlush` to meet with the spec
68
requirement. Now the SDK will invoke `ForceFlush` on all registered
79
processors, even if there is a timeout.

src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ public void MissingPermissionsToReadEnvironmentVariable(SecurityException ex)
135135
}
136136
}
137137

138+
[NonEvent]
139+
public void DroppedExportProcessorItems(string exportProcessorName, string exporterName, long droppedCount)
140+
{
141+
if (droppedCount > 0)
142+
{
143+
if (this.IsEnabled(EventLevel.Warning, EventKeywords.All))
144+
{
145+
this.ExistsDroppedExportProcessorItems(exportProcessorName, exporterName, droppedCount);
146+
}
147+
}
148+
else
149+
{
150+
if (this.IsEnabled(EventLevel.Informational, EventKeywords.All))
151+
{
152+
this.NoDroppedExportProcessorItems(exportProcessorName, exporterName);
153+
}
154+
}
155+
}
156+
138157
[Event(1, Message = "Span processor queue size reached maximum. Throttling spans.", Level = EventLevel.Warning)]
139158
public void SpanProcessorQueueIsExhausted()
140159
{
@@ -309,6 +328,18 @@ public void MissingPermissionsToReadEnvironmentVariable(string exception)
309328
this.WriteEvent(30, exception);
310329
}
311330

331+
[Event(31, Message = "'{0}' exporting to '{1}' dropped '0' items.", Level = EventLevel.Informational)]
332+
public void NoDroppedExportProcessorItems(string exportProcessorName, string exporterName)
333+
{
334+
this.WriteEvent(31, exportProcessorName, exporterName);
335+
}
336+
337+
[Event(32, Message = "'{0}' exporting to '{1}' dropped '{2}' item(s) due to buffer full.", Level = EventLevel.Warning)]
338+
public void ExistsDroppedExportProcessorItems(string exportProcessorName, string exporterName, long droppedCount)
339+
{
340+
this.WriteEvent(32, exportProcessorName, exporterName, droppedCount);
341+
}
342+
312343
#if DEBUG
313344
public class OpenTelemetryEventListener : EventListener
314345
{

0 commit comments

Comments
 (0)