Skip to content

[Auto-instrumentation] Add unique instance.id to all post-fork processes #4390

@noobHappylife

Description

@noobHappylife

Is your feature request related to a problem?

When working with process with multiple workers, like a FastAPI server using uvicorn workers. Metrics provider doesn't have unique instance.id for each workers, thus the metrics doesn't work properly. Ex: All workers are using the same timeseries without unique identifier, causing the statistics unstable.

Describe the solution you'd like

Would it be possible to allow adding unique instance.id while using auto-instrumentation? For now using Opentelemetry python SDK you can do it manually, like the following during the post-fork hook https://opentelemetry-python.readthedocs.io/en/latest/examples/fork-process-model/README.html.

But with auto-instrumentation, I'm not sure how to add the unique instance id, as MeterProvider can't be override.

resource = Resource.create({
    "service.instance.id": uuid7_str(),
})
reader = PeriodicExportingMetricReader(
    OTLPMetricExporter(endpoint=endpoint), export_interval_millis=math.inf
)
self.provider = MeterProvider(resource=resource, metric_readers=[reader])
metrics.set_meter_provider(self.provider)

Describe alternatives you've considered

No response

Additional Context

No response

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions