Skip to content

Conversation

@pafi-code
Copy link

@pafi-code pafi-code commented Aug 1, 2025

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.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Don't provide a collector at the configured endpoint

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@pafi-code pafi-code requested a review from a team as a code owner August 1, 2025 14:21
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 1, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@pafi-code pafi-code force-pushed the feature/add_error_handling_for_otlp_exporters branch from d3d4031 to afb76f2 Compare August 1, 2025 14:45
@pafi-code
Copy link
Author

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

@pafi-code pafi-code force-pushed the feature/add_error_handling_for_otlp_exporters branch from afb76f2 to f581f22 Compare October 24, 2025 10:02
Copy link
Member

@emdneto emdneto left a 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?

@pafi-code
Copy link
Author

@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
Copy link
Contributor

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...

Copy link
Author

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.

Copy link
Contributor

@DylanRussell DylanRussell Nov 11, 2025

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Member

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?

@herin049
Copy link

Have we considered just using urllib3.util.Retry instead of rolling our own retry-backoff loop?
Docs: https://requests.readthedocs.io/en/latest/user/advanced/#example-automatic-retries

@pafi-code
Copy link
Author

@herin049 should this be part of this PR as this is a refactor and not a fix?

@pafi-code
Copy link
Author

Regarding the two failing checks I'm not really sure what I should do.
For the public_symbols_check I did not introduce those changes for which it is failing.
For the changelog: Should I update anything there?

Copy link
Member

@emdneto emdneto left a 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.

@pafi-code pafi-code force-pushed the feature/add_error_handling_for_otlp_exporters branch 2 times, most recently from 6b5c920 to f33957f Compare November 24, 2025 13:31
@pafi-code pafi-code force-pushed the feature/add_error_handling_for_otlp_exporters branch from a6c93d1 to 4a6fec8 Compare December 1, 2025 09:56
@emdneto emdneto moved this from Reviewed PRs that need fixes to Ready for review in @xrmx's Python PR digest Dec 2, 2025
@pafi-code
Copy link
Author

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)

@pafi-code pafi-code force-pushed the feature/add_error_handling_for_otlp_exporters branch from dd052a7 to ef2ff34 Compare December 9, 2025 10:05
> [!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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remind to fix changelog

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm? Remind for whom?

Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more

Copy link
Member

@emdneto emdneto left a 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

5 participants