feat: add TracingHook with required feature_flag span event#5
Merged
feat: add TracingHook with required feature_flag span event#5
Conversation
Introduces release-please-driven version bumping, changelog generation, and GitHub Release tagging for this package. Publishing to Packagist is handled via the Packagist GitHub webhook on tag push, so no dedicated publish workflow is needed -- this matches the pattern used by launchdarkly/php-server-sdk, launchdarkly/php-server-sdk-redis-phpredis, and launchdarkly/openfeature-php-server. Files added: - release-please-config.json: release-type php, bump-minor-pre-major, no v prefix or component in tag, standard Features/Bug Fixes changelog sections, extra-files pointing at Package.php. - .release-please-manifest.json: seeded at 0.0.0 so release-please's first release cycle produces 0.1.0. - src/LaunchDarkly/OpenTelemetry/Package.php: holds the package VERSION constant with the x-release-please-version line marker. Replaces the placeholder .gitkeep from PR 1. - .github/workflows/release-please.yml: triggers on push to main, pins googleapis/release-please-action to SHA 16a9c90856f42705d54a6fda1823352bdc62cf38 (v4.4.0) matching launchdarkly/php-server-sdk.
Introduce the first runtime code for the PHP OTEL integration: - src/LaunchDarkly/OpenTelemetry/TracingHookOptions.php: immutable configuration (includeValue, addSpans, environmentId, logger) with environmentId validation that drops empty/whitespace values and warns via the supplied PSR logger when one is provided. - src/LaunchDarkly/OpenTelemetry/Attributes.php: public string constants for every feature_flag.* span attribute the hook will emit in later PRs, plus the fixed PROVIDER_NAME value. - tests/TracingHookOptionsTest.php: defaults, explicit values, environment-id validation (valid, empty, whitespace), and logger behavior (warns once on invalid, silent when no logger). Refs SDK-2249.
Introduce the first real OpenTelemetry integration code. When a LaunchDarkly
variation call executes inside an active OTEL span, the hook's afterEvaluation
stage attaches a `feature_flag` span event carrying the three required
semantic-convention attributes:
- feature_flag.key = the flag key
- feature_flag.provider.name = "LaunchDarkly"
- feature_flag.context.id = the evaluation context's canonical key
Optional attributes (result.value, result.variationIndex,
result.reason.inExperiment), feature_flag.set.id, and the experimental
addSpans behaviour land in follow-up PRs (SDK-2251, SDK-2252, SDK-2253).
Files:
- src/LaunchDarkly/OpenTelemetry/TracingHook.php: the hook class. The
constructor accepts a TracingHookOptions and an injectable TracerInterface
(tests use this; production callers rely on the default, which pulls a
tracer named `launchdarkly` from the global OTEL provider). No top-level
try/catch — HookRunner::safeInvoke in the PHP SDK already isolates hook
errors.
- tests/TracingHookTest.php: PHPUnit suite that builds a per-test
TracerProvider wired to InMemoryExporter + SimpleSpanProcessor and asserts
span-event contents for the happy path, the no-active-span no-op, and the
invalid-span-context no-op. Spec-clause mapping is documented in the class
docblock.
Temporary composer constraint:
- launchdarkly/server-sdk is pinned to `dev-main as 6.8.x-dev` with
minimum-stability=dev and prefer-stable=true. This is necessary because
the hooks system (commit 77a644d on the PHP SDK) merged to main on
2026-04-22 but has not yet been tagged; the next release will be 6.8.0.
A `_comment_sdk_constraint` key in composer.json flags the revert. Once
launchdarkly/server-sdk 6.8.0 is published, a follow-up chore commit will
pin to `^6.8` and drop the stability flags and the comment.
Refs SDK-2250.
keelerm84
commented
Apr 24, 2026
| ): array { | ||
| $span = Span::fromContext(Context::getCurrent()); | ||
|
|
||
| // Spec §1.2.2.1.1: if the surrounding span context is not valid (no |
Member
Author
There was a problem hiding this comment.
Given our recent conversation, do I remove these specific requirement markers from here and the unit tests? Or since this is coming from a more mature spec, we feel safe keeping them for now.
There was a problem hiding this comment.
I think without the full spec details this can get out of sync easily. We would likely need the spec name and the revision that these are targeting.
Member
Author
There was a problem hiding this comment.
I'll merge all these other PRs then and have a cleanup to remove these spec references.
jsonbailey
approved these changes
Apr 24, 2026
keelerm84
added a commit
that referenced
this pull request
Apr 28, 2026
🤖 I have created a release *beep* *boop* --- ## 0.1.0 (2026-04-28) ### Features * add experimental addSpans option for per-evaluation spans ([#8](#8)) ([36b04e4](36b04e4)) * add optional feature_flag attributes (value, variationIndex, inExperiment) ([#6](#6)) ([5f43c4f](5f43c4f)) * add TracingHook with required feature_flag span event ([#5](#5)) ([1a3c016](1a3c016)) * add TracingHookOptions and attribute constants ([#4](#4)) ([ae33939](ae33939)) * emit feature_flag.set.id when environmentId is configured ([#7](#7)) ([26b6670](26b6670)) * honor environmentId from EvaluationSeriesContext ([#13](#13)) ([d761dcb](d761dcb)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Matthew Keeler <mkeeler@launchdarkly.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce the first real OpenTelemetry integration code. When a LaunchDarkly
variation call executes inside an active OTEL span, the hook's afterEvaluation
stage attaches a
feature_flagspan event carrying the three requiredsemantic-convention attributes:
Optional attributes (result.value, result.variationIndex,
result.reason.inExperiment), feature_flag.set.id, and the experimental
addSpans behaviour land in follow-up PRs (SDK-2251, SDK-2252, SDK-2253).
Files:
constructor accepts a TracingHookOptions and an injectable TracerInterface
(tests use this; production callers rely on the default, which pulls a
tracer named
launchdarklyfrom the global OTEL provider). No top-leveltry/catch — HookRunner::safeInvoke in the PHP SDK already isolates hook
errors.
TracerProvider wired to InMemoryExporter + SimpleSpanProcessor and asserts
span-event contents for the happy path, the no-active-span no-op, and the
invalid-span-context no-op. Spec-clause mapping is documented in the class
docblock.
Temporary composer constraint:
dev-main as 6.8.x-devwithminimum-stability=dev and prefer-stable=true. This is necessary because
the hooks system (commit 77a644d on the PHP SDK) merged to main on
2026-04-22 but has not yet been tagged; the next release will be 6.8.0.
A
_comment_sdk_constraintkey in composer.json flags the revert. Oncelaunchdarkly/server-sdk 6.8.0 is published, a follow-up chore commit will
pin to
^6.8and drop the stability flags and the comment.Refs SDK-2250.