From 9da6dca527ca573c0a27907b788728aafc9932d4 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 30 Jun 2022 14:59:23 +0200 Subject: [PATCH] Use fixed warning messages for traces and metrics --- .../exporter/otlp/proto/grpc/exporter.py | 22 ++++++++++++--- .../tests/test_otlp_exporter_mixin.py | 27 ++++++++++++++++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index 1936046297b..b97f7c57991 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -283,6 +283,19 @@ def _export( self, data: Union[TypingSequence[ReadableSpan], MetricsData] ) -> ExportResultT: + # FIXME remove this check if the export type for traces + # gets updated to a class that represents the proto + # TracesData and use the code below instead. + # logger.warning( + # "Transient error %s encountered while exporting %s, retrying in %ss.", + # error.code(), + # data.__class__.__name__, + # delay, + # ) + if isinstance(data, TypingSequence): + exporting = "traces" + else: + exporting = "metrics" max_value = 64 # expo returns a generator that yields delay values which grow # exponentially. Once delay is greater than max_value, the yielded @@ -325,9 +338,12 @@ def _export( ) logger.warning( - "Transient error %s encountered while exporting %s, retrying in %ss.", + ( + "Transient error %s encountered while exporting " + "%s, retrying in %ss." + ), error.code(), - data.__class__.__name__, + exporting, delay, ) sleep(delay) @@ -335,7 +351,7 @@ def _export( else: logger.error( "Failed to export %s, error code: %s", - data.__class__.__name__, + exporting, error.code(), ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py index 5533bf2c110..d5dd8f1d467 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py @@ -84,10 +84,18 @@ def _translate_data( with self.assertLogs(level=WARNING) as warning: # pylint: disable=protected-access - otlp_mock_exporter._export(Mock()) + otlp_mock_exporter._export([]) self.assertEqual( warning.records[0].message, - "Failed to export Mock, error code: None", + "Failed to export traces, error code: None", + ) + + with self.assertLogs(level=WARNING) as warning: + # pylint: disable=protected-access + otlp_mock_exporter._export(None) + self.assertEqual( + warning.records[0].message, + "Failed to export metrics, error code: None", ) def code(self): # pylint: disable=function-redefined @@ -101,11 +109,22 @@ def trailing_metadata(self): with self.assertLogs(level=WARNING) as warning: # pylint: disable=protected-access - otlp_mock_exporter._export(Mock()) + otlp_mock_exporter._export([]) + self.assertEqual( + warning.records[0].message, + ( + "Transient error StatusCode.CANCELLED encountered " + "while exporting traces, retrying in 0s." + ), + ) + + with self.assertLogs(level=WARNING) as warning: + # pylint: disable=protected-access + otlp_mock_exporter._export(None) self.assertEqual( warning.records[0].message, ( "Transient error StatusCode.CANCELLED encountered " - "while exporting Mock, retrying in 0s." + "while exporting metrics, retrying in 0s." ), )