Skip to content

Commit

Permalink
Use fixed warning messages for traces and metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jun 30, 2022
1 parent 5059de2 commit 9da6dca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -325,17 +338,20 @@ 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)
continue
else:
logger.error(
"Failed to export %s, error code: %s",
data.__class__.__name__,
exporting,
error.code(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
),
)

0 comments on commit 9da6dca

Please sign in to comment.