From 5ac6decc58519db0ffe05418a766c751ce06a851 Mon Sep 17 00:00:00 2001 From: Rajat Jain Date: Wed, 19 Jul 2023 17:35:19 +0530 Subject: [PATCH 1/2] Added dropped spans counter metric to catch number of dropped spans. --- .../src/opentelemetry/sdk/trace/export/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index 7f56a30172..b49aa9f8c4 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -38,6 +38,7 @@ ) from opentelemetry.sdk.trace import ReadableSpan, Span, SpanProcessor from opentelemetry.util._once import Once +from opentelemetry.metrics import Meter _DEFAULT_SCHEDULE_DELAY_MILLIS = 5000 _DEFAULT_MAX_EXPORT_BATCH_SIZE = 512 @@ -198,6 +199,7 @@ def __init__( self.done = False # flag that indicates that spans are being dropped self._spans_dropped = False + self._dropped_counter = None # precallocated list to send spans to exporter self.spans_list = [ None @@ -228,7 +230,10 @@ def on_end(self, span: ReadableSpan) -> None: if not self._spans_dropped: logger.warning("Queue is full, likely spans will be dropped.") self._spans_dropped = True - + self._dropped_counter = Meter.create_counter( + name="dropped_spans_counter", description="To count dropped Spans" + ) + dropped_counter.add(1) self.queue.appendleft(span) if len(self.queue) >= self.max_export_batch_size: From 4ee2e8a581713eb61292316a467df4b387c68e1d Mon Sep 17 00:00:00 2001 From: Rajat Jain Date: Mon, 7 Aug 2023 21:10:04 +0530 Subject: [PATCH 2/2] reviewed code. Signed-off-by: Rajat Jain --- .../src/opentelemetry/sdk/trace/export/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index b49aa9f8c4..54c2d7164f 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -199,7 +199,7 @@ def __init__( self.done = False # flag that indicates that spans are being dropped self._spans_dropped = False - self._dropped_counter = None + self._dropped_spans_counter = None # precallocated list to send spans to exporter self.spans_list = [ None @@ -230,10 +230,10 @@ def on_end(self, span: ReadableSpan) -> None: if not self._spans_dropped: logger.warning("Queue is full, likely spans will be dropped.") self._spans_dropped = True - self._dropped_counter = Meter.create_counter( - name="dropped_spans_counter", description="To count dropped Spans" - ) - dropped_counter.add(1) + self._dropped_spans_counter = Meter.create_counter( + name="dropped_spans_counter", description="Dropped Spans counter" + ) + self._dropped_spans_counter.add(1) self.queue.appendleft(span) if len(self.queue) >= self.max_export_batch_size: