Skip to content

Commit 6c796b6

Browse files
committed
Add stack trace on StatusCode.UNKNOWN export error
A deployment I ran over the weekend is logging the following message hundreds of times per minute: > "Failed to export metrics to otlp.eu01.nr-data.net, error code: StatusCode.UNKNOWN" For this status code - 'Unknown' - it would be nice to have the full error logged, as the message above is very hard to debug.
1 parent 36aaa84 commit 6c796b6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def _export(
308308
self._exporting,
309309
self._endpoint,
310310
error.code(),
311+
exc_info=error.code() == StatusCode.UNKNOWN,
311312
)
312313

313314
if error.code() == StatusCode.OK:

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ def Export(self, request, context):
112112
return ExportMetricsServiceResponse()
113113

114114

115+
class MetricsServiceServicerUNKNOWN(MetricsServiceServicer):
116+
# pylint: disable=invalid-name,unused-argument,no-self-use
117+
def Export(self, request, context):
118+
context.set_code(StatusCode.UNKNOWN)
119+
120+
return ExportMetricsServiceResponse()
121+
122+
115123
class MetricsServiceServicerSUCCESS(MetricsServiceServicer):
116124
# pylint: disable=invalid-name,unused-argument,no-self-use
117125
def Export(self, request, context):
@@ -441,6 +449,31 @@ def test_unavailable_delay(self, mock_sleep, mock_expo):
441449
)
442450
mock_sleep.assert_called_with(4)
443451

452+
@patch(
453+
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
454+
)
455+
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
456+
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.logger")
457+
def test_unknown_logs(self, mock_sleep, mock_expo, mock_logger):
458+
459+
mock_expo.configure_mock(**{"return_value": [1]})
460+
461+
add_MetricsServiceServicer_to_server(
462+
MetricsServiceServicerUNKNOWN(), self.server
463+
)
464+
self.assertEqual(
465+
self.exporter.export(self.metrics["sum_int"]),
466+
MetricExportResult.FAILURE,
467+
)
468+
mock_sleep.assert_called_with(1)
469+
mock_logger.error.assert_called_with(
470+
"Failed to export %s to %s, error code: %s",
471+
"metrics",
472+
"TODO",
473+
StatusCode.UNKNOWN,
474+
exc_info=True,
475+
)
476+
444477
def test_success(self):
445478
add_MetricsServiceServicer_to_server(
446479
MetricsServiceServicerSUCCESS(), self.server

0 commit comments

Comments
 (0)