Repository navigation
Record error.type for HTTP error responses and status codes on successful exports - #5898
Open
kshitizj03 wants to merge 2 commits into
Open
kshitizj03 wants to merge 2 commits into
kshitizj03 wants to merge 2 commits into
Conversation
…sful exports HTTP exports that got a 4xx/5xx response without a Python exception were recorded on the exporter self-observability metrics without `error.type`, the same as a successful export, because `ExporterMetrics.export_operation` only derived `error.type` from an exception. `http.response.status_code` and `rpc.response.status_code` were also only recorded on failed exports. `ExportResult` now has an `error_type` field for failures without an exception, which the OTLP HTTP exporters set to the response status code (e.g. "503"). `error_attrs` is renamed to `response_attrs` and is set whenever a response is received, so the status code is recorded on `otel.sdk.exporter.operation.duration` for successful HTTP (2xx) and gRPC (OK) exports as well. Fixes open-telemetry#5889 Assisted-by: Claude Opus 5.5
Assisted-by: Claude Opus 5.5
Pull request dashboard statusWaiting on reviewers · refreshed 2026-11-09 10:28 UTC Review the latest changes. Status above doesn't look right?
|
chrikrah
approved these changes
Nov 9, 2026
chrikrah
left a comment
There was a problem hiding this comment.
@kshitizj03 as far as I can see this can be merged: with the five source files reverted to 66ec883, the new tests fail (7 failures across the two runs below).
non-blocking: one failure still counts as exported. When a shutdown interrupts a retry, http.py:239 returns _ExportResult(False, None, None, None), so error_type stays None. Returning the last status_code and export_error there would give that batch the 503 that started the retry. A separate PR fits it best.
$ OTEL_PYTHON_SDK_INTERNAL_METRICS_ENABLED=true python ot_probe.py # 7ef7b64; OTLPSpanExporter with _client.export patched to return _ExportResult(False, None, None, None)
export -> SpanExportResult.FAILURE
otel.sdk.exporter.span.exported {'otel.component.type': 'otlp_http_span_exporter', 'otel.component.name': 'otlp_http_span_exporter/0', 'server.address': 'localhost', 'server.port': 4318} 1
$ pytest exporter/opentelemetry-exporter-otlp-proto-http/tests -q # 7ef7b64, Python 3.13.5
121 passed, 139 subtests passed in 2.28s
$ pytest exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py -q
27 passed in 13.21s
$ (same two runs, the five changed source files from 66ec883, head tests)
6 failed, 115 passed, 139 subtests passed in 1.86s
1 failed, 26 passed in 13.63s # KeyError: 'rpc.response.status_code'
# not run: tox, the other exporter packages
Want me to send that follow-up once this lands?
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
HTTP exports that received a 4xx/5xx response without raising an exception were recorded on the
exporter self-observability metrics without
error.type, so they looked like successful exports.ExporterMetrics.export_operationonly derivederror.typefrom an exception. Also,http.response.status_codeandrpc.response.status_codewere only recorded on failed exports.Changes:
ExportResultgets anerror_typefield for failures without an exception. The OTLP HTTP span,log and metric exporters set it to the response status code (e.g.
"503"), so it is recorded onboth
otel.sdk.exporter.{span,log,metric_data_point}.exportedandotel.sdk.exporter.operation.duration.ExportResult.error_attrsis renamed toresponse_attrs(private module) and is now set whenever aresponse is received, so
http.response.status_code(2xx) andrpc.response.status_code(OK)are recorded on
otel.sdk.exporter.operation.durationfor successful exports too.Fixes #5889
Type of change
Checklist:
tox -e precommit(ranruff check+ruff format --checkon changed files)tox -e typecheck(ran pyright 1.1.405 on the changed packages: no errors in changed files)otlp-proto-http, otlp-proto-grpc: all pass; new tests fail without the fix)
I used AI assistance (Claude) for this change and reviewed it myself.
🤖 Generated with Claude Code