-
Notifications
You must be signed in to change notification settings - Fork 783
feat(http): add error handling for exporting #4709
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
base: main
Are you sure you want to change the base?
feat(http): add error handling for exporting #4709
Conversation
d3d4031 to
afb76f2
Compare
...xporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py
Outdated
Show resolved
Hide resolved
|
Okay so I know that the pipeline is failing and I assume this PR should be rebased, but for me there is still the question if my proposed fix is actually how it should be handled. Would appreciate some more feedback here. Also I've created an issue related to this PR: #4712 |
afb76f2 to
f581f22
Compare
emdneto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pafi-code can we have tests for this?
|
@emdneto I had a look into the existing tests and too be honest I have no clue what's going on. I'm not used to the sort of testing that you guys are doing. Would appreciate if you could help regarding the tests. |
| return MetricExportResult.SUCCESS | ||
| except requests.exceptions.RequestException as error: | ||
| reason = str(error) | ||
| retryable = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe only mark it as retryable if it's a connection error to start out ? Otherwise this looks good to me. Also can we add a test that exercises this branch in the code...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you want me to catch the ConnectionError? :D
For testing as I already said I have a really hard time understanding whats going on :D So I would appreciate some help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I meant only make Connection error retryable, but leave the broad requests exception catch as you have it..
For testing you just need to add 1 test (maybe 2 if you special case Connection error as retryable to exercise that logic). Here is the span exporter test: https://github.com/open-telemetry/opentelemetry-python/blob/main/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py#L281-L304 -- you'll want to add basically duplicate tests to each of the 3 http exporters.. You can set up the mock post call to raise an exception (mock_post.side_effect = RequestsException), see (https://github.com/open-telemetry/opentelemetry-python/blob/main/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py#L288C9-L288C38)
IN order to run the tests make sure you have uv installed.. Then run uv sync at the top level directory (opentelemetry-python). Then activate the venv that uv creates (source .venv/bin/activate in the same directory).. Then you can run the unit tests via uv via tox -e py312-test-opentelemetry-exporter-otlp-proto-http -- you can run them for a different version of python too (run tox -l | grep http to see all python versions the tests can run again).. You can also have uv install python version if you haven't done that check out the docs for UV tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DylanRussell is this what you had in mind?
|
Have we considered just using |
|
@herin049 should this be part of this PR as this is a refactor and not a fix? |
|
Regarding the two failing checks I'm not really sure what I should do. |
emdneto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pafi-code, please add the changelog. public-symbols-check should be ok by just rebasing the branch before merging.
...xporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py
Outdated
Show resolved
Hide resolved
6b5c920 to
f33957f
Compare
...xporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py
Outdated
Show resolved
Hide resolved
...orter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py
Outdated
Show resolved
Hide resolved
...porter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py
Outdated
Show resolved
Hide resolved
a6c93d1 to
4a6fec8
Compare
|
I will rebase the PR once again, after we got the approvals. Is there any time limit regarding how long we wait for approval or do we just wait? (not trying to stress here, just curious about the process) |
exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py
Outdated
Show resolved
Hide resolved
exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py
Outdated
Show resolved
Hide resolved
dd052a7 to
ef2ff34
Compare
| > [!IMPORTANT] | ||
| > We are working on stabilizing the Log signal that would require making deprecations and breaking changes. We will try to reduce the releases that may require an update to your code, especially for instrumentations or for sdk developers. | ||
|
|
||
| ## Unreleased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remind to fix changelog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm? Remind for whom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For you before we merge
| if resp.ok: | ||
| return LogRecordExportResult.SUCCESS | ||
| except requests.exceptions.RequestException as error: | ||
| reason = str(error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit I don't think you need to convert to a string here, the logger.error() call should handle it lazily and then handlers/formatters can read the exception directly.
| if resp.ok: | ||
| return MetricExportResult.SUCCESS | ||
| except requests.exceptions.RequestException as error: | ||
| reason = str(error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
| if resp.ok: | ||
| return SpanExportResult.SUCCESS | ||
| except requests.exceptions.RequestException as error: | ||
| reason = str(error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more
emdneto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pafi-code can you please fix the comments and changelog?
Description
When using the OTEL http exporters the std.out gets polluted by unhandled error traces. I don't think that this should be the desired result. This happens when the endpoint is not available when exporting telemetry. This can be cause by different events but in general I think it should be better handled.
Therefore I added error handling with more specific and shorted error messages.
Type of change
I'm not sure if the change type is rather fix or feature, as the service was still running.
How Has This Been Tested?
Does This PR Require a Contrib Repo Change?
Checklist: