Skip to content

rework ServiceInfoFactory priorities #1644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

brettmc
Copy link
Contributor

@brettmc brettmc commented Jun 19, 2025

  • default/all: load detectors from registry last
  • env-provided detectors: load in same order as default/all, then from registry in requested order

Related: #1643

- default/all: load detectors from registry last
- env-provided detectors: load in same order as default/all, then from registry in requested order
@brettmc brettmc requested a review from a team as a code owner June 19, 2025 02:47
Copy link

codecov bot commented Jun 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.76%. Comparing base (33715fd) to head (4a1fd64).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1644      +/-   ##
============================================
- Coverage     68.77%   68.76%   -0.02%     
+ Complexity     2854     2847       -7     
============================================
  Files           425      426       +1     
  Lines          8699     8711      +12     
============================================
+ Hits           5983     5990       +7     
- Misses         2716     2721       +5     
Flag Coverage Δ
8.1 68.42% <100.00%> (-0.05%) ⬇️
8.2 68.61% <100.00%> (+<0.01%) ⬆️
8.3 68.71% <100.00%> (+0.12%) ⬆️
8.4 68.60% <100.00%> (-0.03%) ⬇️
8.5 68.64% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/SDK/Resource/Detectors/Service.php 87.50% <100.00%> (-12.50%) ⬇️
src/SDK/Resource/Detectors/ServiceInstance.php 100.00% <100.00%> (ø)
src/SDK/Resource/ResourceInfoFactory.php 97.95% <100.00%> (-2.05%) ⬇️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 33715fd...4a1fd64. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@smaddock
Copy link
Contributor

smaddock commented Jun 19, 2025

The way I’m reading https://github.com/open-telemetry/opentelemetry-specification/blob/v1.45.0/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable is that the Environment detector always has to be last, even after other registry-provided custom detectors, as part of the default detector. I could be wrong though.

Edit: it also sounds like it’s mandatory.

@brettmc
Copy link
Contributor Author

brettmc commented Jun 19, 2025

@smaddock great question. Do you mean this part of spec?

The SDK MUST extract information from the OTEL_RESOURCE_ATTRIBUTES environment variable and merge this, as the secondary resource, with any resource information provided by the user, i.e. the user provided resource information has higher priority.

I think that does imply that environment detection should be last(ish). But I also think the spec has painted us into a corner here:

  • env must be last so that user-provided info takes precedence over almost anything else
  • except for OTEL_SERVICE_NAME, which has higher priority than OTEL_RESOURCE_ATTRIBUTES=service.name=xxx, which means the service detector should be higher priority than env detector
  • which means that service detector is just about the highest priority detector
  • which means that service.instance.id as provided by service detector is higher priority than that provided by another detector

So, what to do? I agree with @GrzegorzDrozd issue, service.instance.id needs to be lower priority, or opt-in/opt-out. This will be an issue for #1628

The options I see are:

  • move service.instance.id out of the service detector into service_instance and make it opt-in
  • leave it there, but provide an env var to opt-out
  • remove it entirely, delegating to specialised implementations

I think that shared-nothing runtimes are still in the majority of PHP usage, and so our current offering for service.instance.id is not going to be useful for the majority.

For reference, the current guidance for service.instance.id is https://github.com/open-telemetry/semantic-conventions/blob/v1.34.0/docs/registry/attributes/service.md

@smaddock
Copy link
Contributor

Ah, I see the circular definition now. I might map that out visually for my own sake, but for the purposes of this PR, this is the part I keep coming back to:

SDKs… are free to use an inherent unique ID as the source of this value if stability is desirable.

What if we had a config/env setting that toggles between:

  • the default ephemeral UUIDv4 if unset, and
  • a more stable UUIDv5 based on some X factor, which is passed as the value of the config/env setting. Could be the Apache process ID, host UUID… whatever the user wants.

@ChrisLightfootWild ChrisLightfootWild requested a review from a team June 19, 2025 06:36
@GrzegorzDrozd
Copy link
Contributor

Ah, I see the circular definition now. I might map that out visually for my own sake, but for the purposes of this PR, this is the part I keep coming back to:

SDKs… are free to use an inherent unique ID as the source of this value if stability is desirable.

What if we had a config/env setting that toggles between:

* the default ephemeral UUIDv4 if unset, and

* a more stable UUIDv5 based on some X factor, which is passed as the value of the config/env setting. Could be the Apache process ID, host UUID… whatever the user wants.

But to be most useful it would have to be provided by the developer - in my case I am using machine-id + sha of deployed git commit - that way I can have multiple persistent instances/machines + deployed version and it changes every time new code is deployed. Plus this has to be provided by dev as soon as possible (at least detector name) because once factories are created in autoload there is no way to change that.
In my case I am overriding OTEL_PHP_DETECTORS on top of the file/in env settings for the machine:

putenv('OTEL_PHP_DETECTORS=env,host,process,static-service-id');

and then after autoload is required i am just registering:

Registry::registerResourceDetector('static-service-id', new StaticServiceId(GIT_COMMIT_ID));

@GrzegorzDrozd
Copy link
Contributor

@brettmc It looks like it will solve my issue - I will test this branch early next week.

@smaddock
Copy link
Contributor

Any resource attribute should have mechanisms for users/developers to create overrides. Environment variables or manually setting the attributes as mentioned in #1643 (comment) should always override them.

My thoughts above were around what methods of setting the service.instance.id would still comply with the specifications odd requirements. Since the spec gives SDKs some leeway in this, I was imagining what a flexible option there might look like. It doesn’t sound to me like the spec allows for additional resource detectors to override the service resource detector, but I’m just some guy asking questions.

to avoid always generating service.instance.id (which is useless for fpm/apache), split it
into its own detector, ServiceInstance, and don't use it by default. If it is enabled, ensure
it runs before registry-provided detectors.
@brettmc
Copy link
Contributor Author

brettmc commented Jun 24, 2025

I've updated the PR, splitting off a new ServiceInstance detector, and noting the spec deviation:

  • not used in default/all case
  • runs before detectors from registry

Since the portion of the spec that's tripping us up here has development stability, I'll create an issue to see if we can relax that wording. (edit: open-telemetry/opentelemetry-specification#4570 )

$serviceName = Configuration::has(Variables::OTEL_SERVICE_NAME)
? Configuration::getString(Variables::OTEL_SERVICE_NAME)
: null;

$attributes = [
ResourceAttributes::SERVICE_INSTANCE_ID => $serviceInstanceId,
ResourceAttributes::SERVICE_NAME => $serviceName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about not null check from previous code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I think it's ok because null attributes are dropped. There is a test for the scenario where service name is provided through OTEL_RESOURCE_ATTRIBUTES, which passes with this change (which I think would fail if it was using this null value)

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.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy