Skip to content

fix(sdk): don't emit placeholder service.version in Composer detector#2004

Merged
bobstrecansky merged 2 commits into
open-telemetry:mainfrom
PuvaanRaaj:fix/1320-composer-service-version
Jul 13, 2026
Merged

fix(sdk): don't emit placeholder service.version in Composer detector#2004
bobstrecansky merged 2 commits into
open-telemetry:mainfrom
PuvaanRaaj:fix/1320-composer-service-version

Conversation

@PuvaanRaaj

@PuvaanRaaj PuvaanRaaj commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #1320.

When a Composer root package has no explicit version, Composer substitutes the placeholder pretty version 1.0.0+no-version-set (Composer\Package\RootPackage::DEFAULT_PRETTY_VERSION). The Composer resource detector passed pretty_version straight through, so any application that never declares a version — e.g. the OpenTelemetry demo — ended up with a misleading service.version = 1.0.0+no-version-set.

Likewise, when no package name is set Composer substitutes the placeholder __root__, which should not surface as service.name.

Other language SDKs do not set service.version by default, as discussed in the issue.

Fix

  • Skip the service.version attribute when Composer reports the 1.0.0+no-version-set placeholder.
  • Skip the service.name attribute when Composer reports the __root__ placeholder.
  • A real, explicitly-set name/version is still reported as before.

The detector reads InstalledVersions::getRootPackage() directly (no constructor injection). Tests drive the placeholder paths by swapping the installed-versions dataset via InstalledVersions::reload(), restoring the real data in tearDown().

Tests

  • test_reports_service_version_when_set — explicit version is emitted.
  • test_omits_service_version_when_composer_reports_placeholder1.0.0+no-version-set is dropped.
  • test_omits_service_name_when_composer_reports_placeholder__root__ is dropped.
  • Existing detector tests still pass; no state leaks across the suite.

@PuvaanRaaj
PuvaanRaaj requested a review from a team as a code owner July 8, 2026 04:13
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 8, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: PuvaanRaaj / name: PuvaanRaaj (1524d2f)

@PuvaanRaaj

Copy link
Copy Markdown
Contributor Author

@open-telemetry/php-approvers small SDK fix for #1320 (Composer resource detector) with unit tests — review welcome when convenient. 🙏

When a Composer root package has no explicit version, Composer reports a
placeholder pretty_version of `1.0.0+no-version-set`. The Composer resource
detector passed this straight through as service.version, so applications that
never set a version (e.g. the OTel demo) got a misleading `1.0.0+no-version-set`
attribute. Other language SDKs do not set service.version by default.

Skip the attribute when Composer reports the placeholder. An optional
rootPackage constructor argument is added to make the branch testable.

Fixes open-telemetry#1320

- Rollback: revert commit; restores unconditional service.version.

Risk-Level: low
AI-Agent: claude-opus-4-8
@PuvaanRaaj
PuvaanRaaj force-pushed the fix/1320-composer-service-version branch from 067fea1 to 1524d2f Compare July 8, 2026 07:25
@PuvaanRaaj

Copy link
Copy Markdown
Contributor Author

/easycla

Comment thread src/SDK/Resource/Detectors/Composer.php Outdated
$attributes = [
ServiceAttributes::SERVICE_NAME => InstalledVersions::getRootPackage()['name'],
ServiceAttributes::SERVICE_VERSION => InstalledVersions::getRootPackage()['pretty_version'],
ServiceAttributes::SERVICE_NAME => $rootPackage['name'] ?? null,

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.

Should skip setting service.name if __root__.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — now also skips service.name when the root package name is 'root'.

Comment thread src/SDK/Resource/Detectors/Composer.php Outdated
private const UNSET_VERSION = '1.0.0+no-version-set';

/**
* @param array{name?: string, pretty_version?: ?string}|null $rootPackage overrides

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.

Suggested change
* @param array{name?: string, pretty_version?: ?string}|null $rootPackage overrides
* @param array{name: string, pretty_version: string, ...}|null $rootPackage overrides

If we keep the parameter; to match InstalledVersions::getRootPackage().

IMO we should instead InstalledVersions::reload() the test data to keep the implementation clean.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reworked as suggested: dropped the $rootPackage constructor param and read InstalledVersions::getRootPackage() directly; tests now inject via InstalledVersions::reload(). Cleaner. Thanks!

…ge param

Per review on open-telemetry#2004: also omit service.name when the Composer root
package name is the placeholder '__root__'; remove the ?array
$rootPackage constructor param and read InstalledVersions::getRootPackage()
directly, with tests injecting data via InstalledVersions::reload().
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.07%. Comparing base (697aefd) to head (938cc7b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #2004      +/-   ##
============================================
+ Coverage     68.00%   68.07%   +0.07%     
- Complexity     3078     3080       +2     
============================================
  Files           459      459              
  Lines          9023     9025       +2     
============================================
+ Hits           6136     6144       +8     
+ Misses         2887     2881       -6     
Flag Coverage Δ
8.1 67.73% <100.00%> (-0.02%) ⬇️
8.2 67.97% <100.00%> (+0.06%) ⬆️
8.3 67.91% <100.00%> (+<0.01%) ⬆️
8.4 68.00% <100.00%> (+0.09%) ⬆️
8.5 67.91% <100.00%> (-0.06%) ⬇️

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

Files with missing lines Coverage Δ
src/SDK/Resource/Detectors/Composer.php 90.00% <100.00%> (+2.50%) ⬆️

... and 7 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

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

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

Copilot AI 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.

Pull request overview

This PR updates the SDK’s Composer resource detector to avoid emitting misleading resource attributes when Composer reports placeholder metadata for the root package (notably service.version = 1.0.0+no-version-set), aligning behavior with other OpenTelemetry SDKs and addressing #1320.

Changes:

  • Skip emitting service.version when Composer reports the 1.0.0+no-version-set placeholder.
  • Skip emitting service.name when Composer reports the __root__ placeholder name.
  • Add unit tests that simulate different root package metadata via InstalledVersions::reload().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/SDK/Resource/Detectors/Composer.php Adds placeholder constants and conditionally omits service.name/service.version when Composer reports default placeholder values.
tests/Unit/SDK/Resource/Detectors/ComposerTest.php Adds tests covering explicit version emission and placeholder omission using InstalledVersions::reload() + reflection reset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +39 to +41
$rootPackage = InstalledVersions::getRootPackage();

$attributes = [];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR description to match the implementation — the constructor-injection mention is gone; it now describes reading InstalledVersions::getRootPackage() directly with tests driven via InstalledVersions::reload(). Thanks.

@bobstrecansky
bobstrecansky merged commit 27de493 into open-telemetry:main Jul 13, 2026
12 checks passed
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.

service.version being set by Composer

4 participants