Skip to content

feat: add TracingHook with required feature_flag span event#5

Merged
keelerm84 merged 3 commits intomainfrom
mk/sdk-2250/tracing-hook-skeleton
Apr 27, 2026
Merged

feat: add TracingHook with required feature_flag span event#5
keelerm84 merged 3 commits intomainfrom
mk/sdk-2250/tracing-hook-skeleton

Conversation

@keelerm84
Copy link
Copy Markdown
Member

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.

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.
): array {
$span = Span::fromContext(Context::getCurrent());

// Spec §1.2.2.1.1: if the surrounding span context is not valid (no
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll merge all these other PRs then and have a cleanup to remove these spec references.

@keelerm84 keelerm84 marked this pull request as ready for review April 24, 2026 19:32
@keelerm84 keelerm84 requested a review from a team as a code owner April 24, 2026 19:32
@keelerm84 keelerm84 requested a review from kinyoklion April 24, 2026 19:34
Base automatically changed from mk/sdk-2249/tracing-hook-options to main April 27, 2026 13:06
@keelerm84 keelerm84 merged commit 1a3c016 into main Apr 27, 2026
21 checks passed
@keelerm84 keelerm84 deleted the mk/sdk-2250/tracing-hook-skeleton branch April 27, 2026 13:07
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>
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