Skip to content

Refresh the process resource after fork - #1629

Open
unflxw wants to merge 1 commit into
mainfrom
refresh-resource-after-fork
Open

unflxw wants to merge 1 commit into
mainfrom
refresh-resource-after-fork

Conversation

@unflxw

@unflxw unflxw commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Another monkey-patch to the OpenTelemetry SDK. Mostly taken from open-telemetry/opentelemetry-ruby#1425, with additional guards to try our best to not accidentally break things if #resource or @resource suddenly become something else. We can't just reinitialize the providers because the tracers, meters and loggers that have already been created hold references to their old providers.


The fix described on the changeset is dependent on appsignal/appsignal-collector#449, which keys the collector's cumulative metric state by resource.


The OpenTelemetry providers are built once, and their resource carries
the process.pid of the process that built them. A process forked
after that, such as a Puma worker under preload_app!, exports its
data with its parent's resource, so the collector computes the deltas
of every worker's up-down counters as one series.

The resource now also carries a service.instance.id, a UUIDv4
generated once per process, as the Python SDK does. A Process._fork
hook replaces it and process.pid on each provider's resource in the
child. The providers have no resource setter, so the hook writes
@resource, reads the resource back, and logs a warning when the
provider did not keep it.

@backlog-helper

backlog-helper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

鉁旓笍 All good!

New issue guide | Backlog management | Rules | Feedback

@unflxw
unflxw force-pushed the refresh-resource-after-fork branch 2 times, most recently from d43ef2d to 6998ae0 Compare September 30, 2026 13:24
The OpenTelemetry providers are built once, and their resource carries
the `process.pid` of the process that built them. A process forked
after that, such as a Puma worker under `preload_app!`, exports its
data with its parent's resource, so the collector computes the deltas
of every worker's up-down counters as one series.

The resource now also carries a `service.instance.id`, a UUIDv4
generated once per process, as the Python SDK does. A `Process._fork`
hook replaces it and `process.pid` on each provider's resource in the
child. The providers have no resource setter, so the hook writes
`@resource`, reads the resource back, and logs a warning when the
provider did not keep it.
@unflxw
unflxw force-pushed the refresh-resource-after-fork branch from 6998ae0 to 623d67b Compare September 30, 2026 14:02
@unflxw unflxw added the enhancement An improvement to an existing feature. label Oct 2, 2026
@unflxw
unflxw marked this pull request as ready for review October 2, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An improvement to an existing feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant