fix(sdk): regenerate service.instance.id post-fork in MeterProvider and TracerProvider by sterchelen · Pull Request #5000 · open-telemetry/opentelemetry-python

xrmx

The Python SDK did not auto-generate service.instance.id, unlike the
Java SDK and the stable semantic convention recommendation. Add it to
_DEFAULT_RESOURCE so every process gets a unique instance identity at
startup without any user configuration.
…nd TracerProvider

When a prefork server (e.g. gunicorn) forks workers, all workers inherit
the same Resource from the master process, including the same
service.instance.id. Register an os.register_at_fork(after_in_child=...)
hook on both MeterProvider and TracerProvider that replaces
service.instance.id with a fresh UUID in each forked worker, ensuring
distinct resource identities without any user configuration.

Resource.merge() preserves all other resource attributes. WeakMethod is
used for the hook reference, consistent with the existing pattern in
PeriodicExportingMetricReader and BatchSpanProcessor.

Fixes: open-telemetry#4390
Related: open-telemetry#3885