feat: add X-LaunchDarkly-Instance-Id header to server-node SDK (SDK-2358)#1377
feat: add X-LaunchDarkly-Instance-Id header to server-node SDK (SDK-2358)#1377keelerm84 wants to merge 2 commits into
Conversation
…K-2358) Per SCMP-server-connection-minutes-polling section 1.1, server SDKs must send a per-instance v4 GUID on every polling request to enable Server Connection Minutes estimation. The GUID is generated once per SDK instance and stable for that instance's lifetime. We attach the GUID to the shared base headers in LDClientImpl (constructFDv1 and constructFDv2), so it rides on every outbound request -- polling, streaming, and events -- matching the cross-SDK contract tests. The shared defaultHeaders helper now accepts an optional instanceId parameter so client / edge SDKs are not affected. Section 1.3 (polling-interval header) is out of scope for this ticket. Changes: - packages/shared/common/src/utils/http.ts: extend LDHeaders and defaultHeaders to support an optional instanceId - packages/shared/sdk-server/src/LDClientImpl.ts: generate one UUID per client (via platform.crypto.randomUUID) and pass it to defaultHeaders - packages/sdk/server-node/contract-tests: register "instance-id" capability - Unit tests for both layers; updated bigSegments test mock crypto
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/browser size report |
|
@launchdarkly/js-client-sdk-common size report |
|
@launchdarkly/js-client-sdk size report |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default mode and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3996e7e. Configure here.
The previous commit (3996e7e) called platform.crypto.randomUUID() from LDClientImpl.constructFDv1/constructFDv2, but LDClientImpl is also the base class for the Akamai, Cloudflare, Fastly, Vercel, and Shopify Oxygen edge SDKs. Those edge platforms either don't provide a working randomUUID() in their test mocks (Akamai) or shouldn't be advertising instance-id at all. This commit moves UUID generation to LDClientNode, which uses the Node platform's always-available crypto.randomUUID, and threads the generated value through ServerInternalOptions.instanceId. LDClientImpl attaches the header only when instanceId is supplied, leaving edge SDKs unaffected. Also reverts the workaround in the big-segments test crypto mock — no longer needed now that LDClientImpl doesn't call randomUUID on its own. Tests: - @launchdarkly/js-server-sdk-common: 989 passing (5 skipped) - @launchdarkly/node-server-sdk: 65 passing (+2 new instance-id tests) - @launchdarkly/akamai-server-base-sdk: 6 passing (previously 6 failing) - Lint clean

Summary
Adds the
X-LaunchDarkly-Instance-Idheader to every outbound polling, streaming, and event request from@launchdarkly/node-server-sdk. Value is a v4 UUID generated once perLDClientImplviaplatform.crypto.randomUUID()and shared with the requestor, streaming processor, and event processor throughbaseHeaders.The
instanceIdparameter on the shareddefaultHeadershelper is opt-in so the client SDK and edge SDKs in this monorepo (akamai-base, cloudflare, fastly, vercel, shopify-oxygen, server-ai) are unaffected — they go through different code paths and continue to omit the header.Test plan
Note
Medium Risk
Modifies shared request header construction and server SDK initialization to propagate a new per-instance UUID header on all outbound requests, which could affect integrations that depend on exact headers or request caching behavior.
Overview
Adds opt-in support for the
X-LaunchDarkly-Instance-Idheader by extending shareddefaultHeadersto accept aninstanceIdand include it only when provided.Updates the shared server implementation (
LDClientImpl) to threadinternalOptions.instanceIdinto its base headers for both FDv1 and FDv2 paths, and updates the Node server SDK (LDClientNode) to generate a per-client v4 UUID viaplatform.crypto.randomUUID()and pass it throughinternalOptions.Expands coverage with new unit tests validating header presence/absence and UUID behavior, and advertises the new
instance-idcapability in the Node contract test service.Reviewed by Cursor Bugbot for commit 8fa11d7. Bugbot is set up for automated code reviews on this repo. Configure here.