Skip to content

Commit

Permalink
Add stack trace on StatusCode.UNKNOWN export error (#3536)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewins authored Nov 22, 2023
1 parent cc8fd88 commit f399195
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Log stacktrace on `UNKNOWN` status OTLP export error
([#3536](https://github.com/open-telemetry/opentelemetry-python/pull/3536))
- Fix OTLPExporterMixin shutdown timeout period
([#3524](https://github.com/open-telemetry/opentelemetry-python/pull/3524))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def _export(
self._exporting,
self._endpoint,
error.code(),
exc_info=error.code() == StatusCode.UNKNOWN,
)

if error.code() == StatusCode.OK:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ def Export(self, request, context):
return ExportMetricsServiceResponse()


class MetricsServiceServicerUNKNOWN(MetricsServiceServicer):
# pylint: disable=invalid-name,unused-argument,no-self-use
def Export(self, request, context):
context.set_code(StatusCode.UNKNOWN)

return ExportMetricsServiceResponse()


class MetricsServiceServicerSUCCESS(MetricsServiceServicer):
# pylint: disable=invalid-name,unused-argument,no-self-use
def Export(self, request, context):
Expand Down Expand Up @@ -441,6 +449,31 @@ def test_unavailable_delay(self, mock_sleep, mock_expo):
)
mock_sleep.assert_called_with(4)

@patch(
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
)
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.logger.error")
def test_unknown_logs(self, mock_logger_error, mock_sleep, mock_expo):

mock_expo.configure_mock(**{"return_value": [1]})

add_MetricsServiceServicer_to_server(
MetricsServiceServicerUNKNOWN(), self.server
)
self.assertEqual(
self.exporter.export(self.metrics["sum_int"]),
MetricExportResult.FAILURE,
)
mock_sleep.assert_not_called()
mock_logger_error.assert_called_with(
"Failed to export %s to %s, error code: %s",
"metrics",
"localhost:4317",
StatusCode.UNKNOWN,
exc_info=True,
)

def test_success(self):
add_MetricsServiceServicer_to_server(
MetricsServiceServicerSUCCESS(), self.server
Expand Down

0 comments on commit f399195

Please sign in to comment.