Skip to content

opentelemetry-sdk: catch exceptions from child processors in multi on_emit - #5846

Open
hippi345 wants to merge 7 commits into
open-telemetry:mainfrom
hippi345:fix-5841-multi-log-on-emit
Open

hippi345 wants to merge 7 commits into
open-telemetry:mainfrom
hippi345:fix-5841-multi-log-on-emit

Conversation

@hippi345

Copy link
Copy Markdown

Changes

SynchronousMultiLogRecordProcessor and ConcurrentMultiLogRecordProcessor now catch exceptions from each child LogRecordProcessor.on_emit, log them, and continue with the other processors. One failing processor no longer crashes the caller or drops the record for processors registered after it.

Fixes #5841

Checklist

  • Add a changelog fragment
  • Add a unit test

…_emit

A failing LogRecordProcessor.on_emit no longer skips the remaining
processors registered on the synchronous or concurrent multi processor.

Fixes open-telemetry#5841
@hippi345
hippi345 requested a review from a team as a code owner October 27, 2026 18:49
@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-11-05 01:28 UTC

Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):

  • Top-level threads: 1
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

mock.on_emit.assert_called_with(record)
multi_log_record_processor.shutdown()

def test_on_emit_exception_does_not_stop_other_processors(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add a test with in-memory processors that fully integrates with a failing log processor and validates that telemetry is produced correctly end-to-end for non-erroring processors?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yeah makes sense, I added one that wires up a real LoggerProvider with a processor that throws in the middle and in memory exporters before and after it so you can see the records actually come out the other side, it runs for both sync and concurrent, just pushed it

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Failure diagnostics can recursively re-enter the failing processor or deadlock behind a root LoggingHandler, requiring a non-propagating internal logger and regression coverage.

1 open issue
What changed in this PR

This PR addresses #5841 by adding exception handling around child log processors’ on_emit calls, aiming to keep processor failures from interrupting application logging or delivery to other processors.

Changes:

  • Catch and log child processor exceptions in synchronous and concurrent processing.
  • Add a shared regression test verifying that other processors still receive the record.
  • Add a changelog fragment documenting the fix.
File Description
opentelemetry-sdk/​tests/​logs/​test_multi_log_processor.py Tests exception reporting and continued delivery for both processor types.
opentelemetry-sdk/​src/​opentelemetry/​sdk/​_logs/​_internal/​__init__.py Adds exception guards around child on_emit calls.
.changelog/​5846.fixed Documents the log processor exception-handling change.

Review effort: Balanced

try:
lp.on_emit(log_record)
except Exception: # pylint: disable=broad-exception-caught
_logger.exception("Exception while calling on_emit on %s.", lp)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think this one was real, with a LoggingHandler on root the exception log from on_emit went right back through the same handler so it could loop and the concurrent one could block on the handler lock. I switched both to a logger that doesn't propagate, same as what SimpleLogRecordProcessor already does, and added a test with a root handler and a failing processor for sync and concurrent. pushed with the other test

@lzchen

lzchen commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@hippi345 Please sign the CLA.

…ot handlers

Route processor on_emit exception diagnostics through a non-propagating
internal logger, matching SimpleLogRecordProcessor export error handling.

Add LoggerProvider integration and root LoggingHandler regression tests
for synchronous and concurrent multi processors.

Co-authored-by: Joel Town Road <hippi345@users.noreply.github.com>
…on shutdown

Release ThreadPoolExecutor worker threads when ConcurrentMultiLogRecordProcessor
shuts down so PyPy test runs can exit cleanly. Ensure force_flush test shuts down
its processor.
@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Hi @hippi345 — just a friendly reminder that this pull request is waiting on you. The dashboard status comment has the open items and is kept current.

  • Replying is enough to hand it off — answer, explain why no change is needed, or ask a follow-up. The dashboard routes it onward once nothing on the list is waiting on you.
  • To hand it back for any other reason, including the dashboard getting this wrong, comment /dashboard route:reviewers.

This branch has not been deployed

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[bug] LogRecordProcessor exceptions in on_emit escape and crash the host application

4 participants