-
Notifications
You must be signed in to change notification settings - Fork 157
Comments
fix(logging): make LoggerAdapter OpenTelemetry-safe (Issue #837)#1283
fix(logging): make LoggerAdapter OpenTelemetry-safe (Issue #837) #1283harsh543 wants to merge 11 commits intotemporalio:main from
Conversation
CLA assistant check
All committers have signed the CLA.
- 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
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])
- 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
harsh543
commented
Feb 3, 2026
Re: test changes
Good feedback — consolidated into a single parameterized test that validates all concerns:
What test_workflow_logging[dict/flatten] now tests:
- Dict/flatten formatting — parameterized to verify
LogRecord.extrastructure for each mode - Replay suppression — worker restart mid-workflow triggers history replay; asserts old logs don't reappear
full_workflow_info_on_extra— verifiesworkflow.Infoobject is attached when enabled
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 normally
Cleanup:
finally: workflow.logger.temporal_extra_mode = original_mode workflow.logger.full_workflow_info_on_extra = original_full_info
No separate replay test needed — one test, clear phases, all concerns covered.
Run ruff format to fix line length and assertion formatting. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
harsh543
commented
Feb 6, 2026
Fixed CI lint failures in 730abbf:
- Ran
ruff formatontests/test_log_utils.pyandtests/worker/test_workflow.py - Changes are purely stylistic (line wrapping, assertion formatting)
- No functional code changes
Safe to re-run CI.
Four type errors caused all 11 CI jobs to fail at the lint-types step: - tests/test_log_utils.py: annotate `mode` as `TemporalLogExtraMode` instead of `str` so it is compatible with _apply_temporal_context_to_extra and _update_temporal_context_in_extra signatures - tests/worker/test_activity.py: same fix for `temporal_extra_mode` param - tests/worker/test_workflow.py: same fix for `temporal_extra_mode` param - temporalio/_log_utils.py: suppress basedpyright reportUnusedFunction on both helper functions; basedpyright exits 1 on warnings, and it does not track cross-module usage of _-prefixed functions even though both are explicitly imported and called from activity.py and workflow.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
harsh543
commented
Feb 22, 2026
CI lint failures fixed — please re-run CIAll 11 Root causes & fixes (commit 302af5d)1. pyright: 4 type errors —
2. basedpyright: 2 warnings → exit code 1 basedpyright exits 1 even on warnings. The new Fix: added Verified locally (replicating CI environment) |
Uh oh!
There was an error while loading. Please reload this page.
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