feat: expose environmentId on EvaluationSeriesContext#242
Merged
Conversation
Captures the X-Ld-Envid header from LaunchDarkly polling responses and surfaces the resulting environment ID on EvaluationSeriesContext so downstream hooks (notably the future OpenTelemetry tracing hook) can implement OTEL Integration spec §1.2.2.9.2. Implementation: - New internal EnvironmentIdProvider value holder, owned by LDClient and injected into the feature requester via $options['_environment_id_provider']. - GuzzleFeatureRequester reads X-Ld-Envid on each response (success and BadResponseException paths — LD's polling endpoints emit the header on 4xx/5xx too) and writes it into the holder. - LDClient builds EvaluationSeriesContext twice per variation call: once before evaluation (env ID may be null on the very first variation in a process; populated on subsequent calls) and once after (always sees the env ID captured by the call's own fetch). Caveats baked in: - Persistent-store feature requesters (Redis, Consul, DynamoDB) never write to the holder, so environmentId stays null when the SDK isn't fetching directly from LaunchDarkly. - The first variation in a PHP process sees null in beforeEvaluation; the fetch happens during evaluation, so the value is only known by the time afterEvaluation runs. - environmentId on TrackSeriesContext is intentionally deferred; can be added later using the same holder if needed. The FeatureRequester subsystem interface is unchanged — third-party persistent-store packages do not need to be updated.
jsonbailey
approved these changes
Apr 27, 2026
keelerm84
pushed a commit
that referenced
this pull request
Apr 28, 2026
🤖 I have created a release *beep* *boop* --- ## [6.8.0](6.7.0...6.8.0) (2026-04-28) ### Features * add hooks support ([#240](#240)) ([77a644d](77a644d)) * expose environmentId on EvaluationSeriesContext ([#242](#242)) ([5fcbce4](5fcbce4)) --- 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>
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.
Captures the X-Ld-Envid header from LaunchDarkly polling responses and
surfaces the resulting environment ID on EvaluationSeriesContext so
downstream hooks (notably the future OpenTelemetry tracing hook) can
implement OTEL Integration spec §1.2.2.9.2.
Implementation:
injected into the feature requester via $options['_environment_id_provider'].
BadResponseException paths — LD's polling endpoints emit the header on
4xx/5xx too) and writes it into the holder.
before evaluation (env ID may be null on the very first variation in a
process; populated on subsequent calls) and once after (always sees the
env ID captured by the call's own fetch).
Caveats baked in:
write to the holder, so environmentId stays null when the SDK isn't
fetching directly from LaunchDarkly.
fetch happens during evaluation, so the value is only known by the time
afterEvaluation runs.
added later using the same holder if needed.
The FeatureRequester subsystem interface is unchanged — third-party
persistent-store packages do not need to be updated.
Note
Medium Risk
Medium risk because it changes hook context construction during every flag evaluation and adds header-capture behavior to the HTTP feature requester; mistakes could affect hook consumers or error-handling paths.
Overview
Surfaces the LaunchDarkly
environmentIdto evaluation hooks by adding an optionalenvironmentIdfield toEvaluationSeriesContextand documenting when it may benull.Adds an internal
EnvironmentIdProviderowned byLDClient, injects it into the feature requester via options, and updatesGuzzleFeatureRequesterto captureX-Ld-Envidfrom all polling responses (success and error) so subsequent hook contexts can observe it.Updates
LDClientto build separateEvaluationSeriesContextinstances forbeforeEvaluationandafterEvaluation, re-reading the provider after evaluation soafterEvaluationcan see an env ID captured during the same call. Includes new unit tests covering provider behavior, header capture, and hook-stage visibility across first vs subsequent evaluations.Reviewed by Cursor Bugbot for commit 46131de. Bugbot is set up for automated code reviews on this repo. Configure here.