Skip to content

fix: code-level cleanup surfaced during psalm/phan upgrade work - #613

Open
nickmarden wants to merge 2 commits into
open-telemetry:mainfrom
nickmarden:ci-fix/code-fixes-from-579
Open

fix: code-level cleanup surfaced during psalm/phan upgrade work#613
nickmarden wants to merge 2 commits into
open-telemetry:mainfrom
nickmarden:ci-fix/code-fixes-from-579

Conversation

@nickmarden

@nickmarden nickmarden commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Small set of correctness fixes surfaced while investigating CI failures from the psalm/phan upgrade work (PR #579, now superseded by the revert in #600). These are clean code-level changes with no suppressions beyond one narrow phan annotation.

Each of the three projects touched here is currently failing on main, and these are the fixes for those failures.

Aws — phan, all PHP versions

main reports:

src/AwsSdkInstrumentation.php:26 PhanDeprecatedInterface Using a deprecated interface \OpenTelemetry\API\Instrumentation\InstrumentationInterface
src/AwsSdkInstrumentation.php:26 PhanDeprecatedTrait Using a deprecated trait \OpenTelemetry\API\Instrumentation\InstrumentationTrait

AwsSdkInstrumentation already implemented every interface method itself, so the interface and trait are dropped. The two properties the trait contributed ($propagator, $tracerProvider) are now declared explicitly, and a constructor installs the same NoopTextMapPropagator / NoopTracerProvider defaults that the trait's constructor used to set, so an instance stays usable before setPropagator() / setTracerProvider() are called.

Also adds @phan-suppress-next-line PhanTypeMismatchArgument for the TransportInterface generic type narrowing on OtlpExporter construction in AwsLambdaWrapper.

Instrumentation/PDO — phpstan, PHP 8.2 / 8.3 / 8.4

main reports the same error on every version:

Class Pdo\Sqlite referenced with incorrect case: PDO\Sqlite.

The cause is the use PDO; import in PDOInstrumentationTest: class aliases are case-insensitive, so the relative @var Pdo\Sqlite resolves through it to PDO\Sqlite. Fully qualifying it as @var \Pdo\Sqlite fixes it.

With that resolved, the Pdo\Sqlite ignore patterns are all obsolete — PHPStan ships PHP 8.4 stubs whatever version it runs on, so the class and its methods always resolve and the patterns went unmatched (which is itself an error under reportUnmatchedIgnoredErrors). Only PDO::connect() still needs ignoring below 8.4.

ResourceDetectors/Container — phpunit, all PHP versions

ContainerTest::test_valid_v1 asserts ResourceAttributes::SCHEMA_URL while the detector emits Version::VERSION_1_38_0->url(), so it fails on main.

An earlier revision of this PR resolved the mismatch by changing the detector. As @ChrisLightfootWild pointed out in review, that silently downgrades the detector's semantic conventions claim from 1.38.0 to 1.32.0 via the deprecated ResourceAttributes class. The detector is now left alone and the test is corrected instead, in its own commit. The package already requires open-telemetry/sem-conv: ^1.38.

Test plan

Full make all-checks (style, composer validate, phan, psalm, phpstan, phpunit) run locally in the project's Docker images:

Project PHP Result
Aws 8.1, 8.4 pass (81 tests)
ResourceDetectors/Container 8.1, 8.4 pass (9 tests)
Instrumentation/PDO 8.2, 8.4 pass (23 tests)

On 8.4 the Pdo\Sqlite subclass test runs for real rather than skipping.

The remaining red jobs in this PR's matrix (Symfony, Yii, Psr3, Monolog, Sampler/RuleBased, Laravel, ReactPHP, HttpConfig, CodeIgniter, ExtRdKafka) are pre-existing failures on main and are untouched here.

@nickmarden
nickmarden requested a review from a team as a code owner June 11, 2026 19:12
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.12%. Comparing base (176b3fc) to head (f05606e).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #613      +/-   ##
============================================
+ Coverage     81.69%   82.12%   +0.43%     
+ Complexity     1821     1689     -132     
============================================
  Files           129      108      -21     
  Lines          7144     6211     -933     
============================================
- Hits           5836     5101     -735     
+ Misses         1308     1110     -198     
Flag Coverage Δ
Aws 93.50% <100.00%> (?)
Context/Swoole 0.00% <ø> (ø)
Exporter/Instana 49.80% <ø> (ø)
Instrumentation/AwsSdk 82.14% <ø> (ø)
Instrumentation/CakePHP 20.42% <ø> (ø)
Instrumentation/CodeIgniter 79.31% <ø> (ø)
Instrumentation/Curl 86.88% <ø> (ø)
Instrumentation/Doctrine 92.82% <ø> (ø)
Instrumentation/ExtAmqp 88.80% <ø> (ø)
Instrumentation/ExtRdKafka ?
Instrumentation/Guzzle 79.76% <ø> (ø)
Instrumentation/HttpAsyncClient 78.94% <ø> (ø)
Instrumentation/HttpConfig 28.76% <ø> (ø)
Instrumentation/IO 0.00% <ø> (ø)
Instrumentation/Laravel ?
Instrumentation/Magento2 88.12% <ø> (ø)
Instrumentation/MongoDB 76.84% <ø> (ø)
Instrumentation/MySqli ?
Instrumentation/OpenAIPHP 86.71% <ø> (ø)
Instrumentation/PDO 85.67% <ø> (?)
Instrumentation/PostgreSql 91.36% <ø> (ø)
Instrumentation/Psr14 77.41% <ø> (ø)
Instrumentation/Psr15 89.74% <ø> (ø)
Instrumentation/Psr16 97.43% <ø> (ø)
Instrumentation/Psr18 79.41% <ø> (ø)
Instrumentation/Psr6 97.56% <ø> (ø)
Instrumentation/ReactPHP 99.41% <ø> (ø)
Instrumentation/Session 94.28% <ø> (ø)
Instrumentation/Slim 84.21% <ø> (ø)
Metrics/Runtime ?
Propagation/CloudTrace 90.69% <ø> (ø)
Propagation/Instana 98.07% <ø> (ø)
Propagation/ServerTiming 94.73% <ø> (ø)
Propagation/TraceResponse 94.73% <ø> (ø)
ResourceDetectors/Azure 91.66% <ø> (ø)
ResourceDetectors/Container 93.02% <ø> (?)
ResourceDetectors/DigitalOcean 100.00% <ø> (ø)
Sampler/Xray 78.38% <ø> (ø)
Shims/OpenTracing 92.99% <ø> (ø)
SqlCommenter 95.58% <ø> (ø)
Utils/Test 87.79% <ø> (ø)

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

Files with missing lines Coverage Δ
src/Aws/src/AwsSdkInstrumentation.php 95.65% <100.00%> (ø)
src/Aws/src/Lambda/AwsLambdaWrapper.php 97.50% <ø> (ø)

... and 45 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 176b3fc...f05606e. Read the comment docs.

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

@ChrisLightfootWild ChrisLightfootWild 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.

@nickmarden thanks for picking some of these changes out from your previous PR.

Happy to move the psalm dependencies forward etc if you can get the working combination that seemed to elude renovate-bot. 😬

}

return ResourceInfo::create(Attributes::create($attributes), Version::VERSION_1_38_0->url());
return ResourceInfo::create(Attributes::create($attributes), ResourceAttributes::SCHEMA_URL);

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.

Prior to this change, the instrumentation claims to emit telemetry adhering to 1.38.0 of the semantic conventions.

Changing to the deprecated ResourceAttributes class downgrades that claim to 1.32.0 (and then it may not be correct for that version).

I think this should be reverted.

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.

Agreed, and reverted. The detector keeps Version::VERSION_1_38_0->url().

For context on why I touched it at all: ContainerTest::test_valid_v1 asserts ResourceAttributes::SCHEMA_URL, so it disagrees with the detector and fails on main today, independently of this PR. I had fixed the mismatch from the wrong end. It now fixes the test instead, in a separate commit so it is easy to review on its own.

- Remove deprecated InstrumentationInterface/InstrumentationTrait from
  AwsSdkInstrumentation. The interface methods were already implemented
  by the class itself; the two properties the trait contributed are now
  declared explicitly, and a constructor keeps the Noop defaults the
  trait's constructor used to install so behaviour is unchanged.
- Add @phan-suppress-next-line for TransportInterface generic type
  narrowing in AwsLambdaWrapper OtlpExporter construction
- PDO: fully qualify the `@var \Pdo\Sqlite` annotation. The `use PDO;`
  import made the relative `Pdo\Sqlite` resolve to `PDO\Sqlite` (class
  aliases are case-insensitive), which PHPStan reported as a class
  referenced with incorrect case on 8.2, 8.3 and 8.4.
- PDO: drop the Sqlite ignore patterns. PHPStan ships PHP 8.4 stubs
  whatever version it runs on, so Pdo\Sqlite and its methods always
  resolve and the patterns went unmatched. Only PDO::connect() still
  needs ignoring below 8.4.
ContainerTest asserted ResourceAttributes::SCHEMA_URL while the detector
emits Version::VERSION_1_38_0->url(), so the test failed on main.

An earlier revision of this PR resolved the mismatch by changing the
detector to ResourceAttributes::SCHEMA_URL. As pointed out in review,
that silently downgrades the detector's semantic conventions claim from
1.38.0 to 1.32.0 (via the deprecated ResourceAttributes class), and the
attributes may not even be correct for 1.32.0. The detector is left
alone and the test is corrected instead.

The package already requires open-telemetry/sem-conv ^1.38, so
Version::VERSION_1_38_0 is guaranteed to be available.
@nickmarden
nickmarden force-pushed the ci-fix/code-fixes-from-579 branch from f62ab5c to f05606e Compare July 27, 2026 17:26
@nickmarden

Copy link
Copy Markdown
Contributor Author

@ChrisLightfootWild lemme know if you need anything more on this PR, thanks.

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.

2 participants