Skip to content

Fix metric resource PID after fork - #2189

Merged
alexmojaki merged 13 commits into
mainfrom
codex/fix-forked-resource-pid
Aug 5, 2026
Merged

alexmojaki merged 13 commits into
mainfrom
codex/fix-forked-resource-pid

Conversation

@alexmojaki

@alexmojaki alexmojaki commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • update metric, span, and log resources with the child PID after os.fork()
  • perform the updates without taking OpenTelemetry locks or rerunning its process-dependent resource detectors
  • snapshot OpenTelemetry's private resource updater implementations so dependency drift fails loudly
  • cover parent and child resource PIDs end to end, including a fork while provider locks are held

Root cause

MeterProvider stores the resource used during collection in _sdk_config.resource. Assigning meter_provider._resource created an unused attribute, so child metrics continued to export the parent process PID. Cached SDK tracer and logger instances also retain their original resource and need to be updated after the fork.

Logfire's child callback runs before OpenTelemetry resets inherited provider locks. It therefore updates the same backing state as OpenTelemetry's private _update_resource() methods without calling those lock-taking methods or _handle_fork(), which also reruns resource detection.

Validation

  • uv run pytest tests/test_configure.py — 106 passed
  • focused regression tests with OpenTelemetry SDK 1.44.0 — 3 passed
  • focused regression tests with the minimum supported OpenTelemetry SDK 1.39.0 — 2 passed, 1 expected skip
  • uv run pyright logfire/_internal/config.py tests/test_configure.py
  • Ruff formatting and lint checks

devin-ai-integration[bot]

This comment was marked as resolved.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change refactors fix_pid() to update provider resources after process fork. Tracer and logger providers use _update_resource when available; fallback updates provider and proxy objects. Meter resources update through _sdk_config.resource for MeterProvider instances. The test verifies that parent and child processes report their respective PIDs for metrics, logs, and spans.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the main fix for metric resource PIDs after process forks.
Description check ✅ Passed The description directly explains the fork-related resource bug, the implementation, root cause, and validation.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-forked-resource-pid

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]

This comment was marked as resolved.

Comment thread logfire/_internal/config.py Resolved
Comment thread logfire/_internal/config.py Resolved
Comment thread tests/test_configure.py Resolved
Comment thread logfire/_internal/config.py Resolved
Comment thread logfire/_internal/config.py Resolved
Comment thread logfire/_internal/config.py Resolved
Comment thread logfire/_internal/config.py Resolved
macroscopeapp[bot]

This comment was marked as resolved.

Comment thread logfire/_internal/config.py Resolved
veria-ai[bot]

This comment was marked as resolved.

@veria-ai

veria-ai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

cubic-dev-ai[bot]

This comment was marked as resolved.

cubic-dev-ai[bot]

This comment was marked as resolved.

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 2 new potential issues.

Open in Devin Review

Comment thread logfire/_internal/config.py Resolved
Comment thread logfire/_internal/config.py Resolved

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread tests/test_configure.py Resolved
@alexmojaki
alexmojaki added this pull request to the merge queue Aug 5, 2026
Merged via the queue into main with commit 3f68931 Aug 5, 2026
26 checks passed
@alexmojaki
alexmojaki deleted the codex/fix-forked-resource-pid branch August 5, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant