Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stack trace on StatusCode.UNKNOWN export error #3536

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading