-
Notifications
You must be signed in to change notification settings - Fork 152
fix(logging): make LoggerAdapter OpenTelemetry-safe (Issue #837) #1283
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
Open
harsh543
wants to merge
5
commits into
temporalio:main
Choose a base branch
from
harsh543:fix/loggeradapter-otel-extra-837
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(logging): make LoggerAdapter OpenTelemetry-safe (Issue #837) #1283
harsh543
wants to merge
5
commits into
temporalio:main
from
harsh543:fix/loggeradapter-otel-extra-837
+501
−114
Conversation
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
tconley1428
reviewed
Jan 22, 2026
tconley1428
reviewed
Jan 22, 2026
tconley1428
reviewed
Jan 22, 2026
tconley1428
reviewed
Jan 22, 2026
tconley1428
reviewed
Jan 22, 2026
- Add TestFlattenModeOTelSafety class with critical assertions - Verify zero dict values exist for temporal keys in flatten mode - Verify legacy nested keys (temporal_workflow, temporal_activity) don't exist - Test both workflow and activity contexts - Test update context handling in flatten mode
- Remove json mode (no known use case, simplifies code) - Merge key/prefix params into single key param (prefix derived via replace) - Revert unrelated README changes - Parameterize unit tests, remove json-mode tests - Remove json integration tests from test_activity and test_workflow Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
a271c94 to
2307d25
Compare
…anges - Merge test_activity_logging and test_activity_logging_flatten_mode into a single pytest-parameterized test covering dict and flatten modes - Revert README import path changes that were unrelated to this PR Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2d556bb to
3e29635
Compare
harsh543
commented
Feb 1, 2026
Author
harsh543
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.
The PR is now:
- ✅ Tightly scoped to solving the OTel logging issue
- ✅ Free of unrelated README changes
- ✅ Simplified API with clear use cases
- ✅ Fully backward compatible by default
- ✅ Thoroughly tested with integration tests for both modes
Addressed feedback:
- Removed json mode (no use case identified)
- Reverted all README changes
- Parameterized duplicate tests (test_activity_logging[dict/flatten],
test_workflow_logging[dict/flatten])
tconley1428
reviewed
Feb 2, 2026
- Add try/finally to restore temporal_extra_mode and full_workflow_info_on_extra - Add clear phase comments: first execution, replay path, replay assertions - Single parameterized test validates: extra mode formatting (dict/flatten), replay suppression, and full_workflow_info_on_extra Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
de3217c to
3b51ef2
Compare
Author
Re: test changesGood feedback — consolidated into a single parameterized test that validates all concerns: What
Structure: # --- First execution: logs should appear ---
await handle.signal(LoggingWorkflow.my_signal, "signal 1")
...
assert capturer.find_log("Signal: signal 1")
# --- Clear logs and continue execution (replay path) ---
capturer.log_queue.queue.clear()
# --- Replay execution: no duplicate logs ---
assert not capturer.find_log("Signal: signal 1") # suppressed during replay
assert capturer.find_log("Signal: signal 3") # new execution logs normallyCleanup: finally:
workflow.logger.temporal_extra_mode = original_mode
workflow.logger.full_workflow_info_on_extra = original_full_infoNo separate replay test needed — one test, clear phases, all concerns covered. |
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.
Summary
This PR adds an OTel-safe logging mode for Temporal's Python
LoggerAdapterclasses, addressing Issue #837 where nested dicts inLogRecord.extrabreak OpenTelemetry logging pipelines.Problem
Temporal's
workflow.LoggerAdapterandactivity.LoggerAdapterinject nested dictionaries intoLogRecord.extra:OpenTelemetry log attributes must be
AnyValuetypes (scalars, not nested dicts). This causes Temporal context to be dropped or cause errors in OTel pipelines.Solution
Add a
temporal_extra_modeattribute to bothLoggerAdapterclasses with two modes:"dict"(default)temporal_workflow/temporal_activity"flatten"temporal.workflow.*/temporal.activity.*prefixesUsage
Changes
temporalio/_log_utils.py- Shared helper functions andTemporalLogExtraModetypetemporalio/workflow.py- Addedtemporal_extra_modetoLoggerAdaptertemporalio/activity.py- Addedtemporal_extra_modetoLoggerAdaptertests/test_log_utils.py- Unit tests for all modestests/worker/test_workflow.py- Parameterized integration tests for workflow logging modestests/worker/test_activity.py- Parameterized integration tests for activity logging modesVerification Checklist
"dict") preserves existing behavior - no breaking changestemporal.workflow.*andtemporal.activity.*prefixesLogRecordcore attributesfinallyblocksTest Plan
Verify default behavior unchanged:
Verify flatten mode is OTel-safe:
Fixes #837
🤖 Generated with Claude Code