feat(posthog): Added SDK data to header in requests, for Posthog filtering#44
Merged
feat(posthog): Added SDK data to header in requests, for Posthog filtering#44
Conversation
fernandocorreia-galileo
approved these changes
Feb 28, 2026
fernandocorreia-galileo
left a comment
There was a problem hiding this comment.
Approved but please look at the suggestions, if necessary create follow-up tickets.
src/hooks/sdk-identifier.ts
Outdated
| ): Promise<Request> { | ||
| const version = loadVersion(); | ||
| const sdkIdentifier = getSdkIdentifier(version); | ||
| request.headers.set("X-Galileo-SDK", sdkIdentifier); |
There was a problem hiding this comment.
- [Minor]: The
SDKIdentifierHookmutates the incomingRequestobject's headers in place instead of cloning it first.- File:
src/hooks/sdk-identifier.ts(lines 36-37) - Contrast with
TokenManagementHook.beforeRequest(), which doesconst newRequest = request.clone()before mutating. In most practical cases the FetchRequestheaders object is mutable in Node.js (undici), so this works. However, in certain environments or with certainRequestimplementations the headers can be immutable (e.g. aRequestcreated withmode: 'cors'in some browser implementations). Cloning first is also the safer contract: it avoids mutating the caller's object, which could have surprising side effects if the sameRequestinstance is reused or inspected after the hook runs. - Suggestion: Mirror the pattern used in
token-management.ts:const newRequest = request.clone(); newRequest.headers.set("X-Galileo-SDK", sdkIdentifier); return newRequest;
- File:
Contributor
Author
There was a problem hiding this comment.
Adjusted accordingly.
There was a problem hiding this comment.
- [Minor]: No test for the
loadVersion()fallback path ("unknown").- File:
src/tests/hooks/sdk-identifier.test.ts - There is no test that exercises the
catchbranch ofloadVersion()(e.g., by mockingrequireto throw). This means the graceful-degradation path is untested. Particularly relevant given that this path is triggered by the ESM runtime issue described above. - Suggestion: Add a test using
vi.mockto simulate arequirefailure and assert that the header value becomesgalileo-generated/unknownrather than throwing.
- File:
1620f2b to
50a8c51
Compare
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.
User description
Make sure TypeScript SDK usage is being captured on PostHog - [sc-54702]
Description
Obs.: Ticket [sc-56960] was created to enable persistent edits on Speakeasy's configuration, that will allow customizing tsconfig.json, which is necessary to use import instead of require on this hook.
Generated description
Below is a concise technical summary of the changes proposed in this PR:
graph LR SDKIdentifierHook_beforeRequest_("SDKIdentifierHook.beforeRequest"):::added loadVersion_("loadVersion"):::added getSdkIdentifier_("getSdkIdentifier"):::added GALILEO_GENERATED_("GALILEO_GENERATED"):::added initHooks_("initHooks"):::modified SDKIdentifierHook_("SDKIdentifierHook"):::added SDKIdentifierHook_beforeRequest_ -- "Fetches cached package version to set X-Galileo-SDK." --> loadVersion_ SDKIdentifierHook_beforeRequest_ -- "Builds 'galileo-generated/<version>' header value." --> getSdkIdentifier_ loadVersion_ -- "Reads galileo-generated/package.json version into cache." --> GALILEO_GENERATED_ initHooks_ -- "Registers SDKIdentifierHook to add SDK header before requests." --> SDKIdentifierHook_ classDef added stroke:#15AA7A classDef removed stroke:#CD5270 classDef modified stroke:#EDAC4C linkStyle default stroke:#CBD5E1,font-size:13pxImplements a new
SDKIdentifierHookto inject theX-Galileo-SDKheader into outgoing requests, enabling version tracking for PostHog filtering. Registers this hook within the global hook initialization flow to ensure all generated requests include the SDK version metadata.SDKIdentifierHookto verify header injection, version formatting, and error handling.Modified files (1)
Latest Contributors(0)
SDKIdentifierHookclass and registers it ininitHooksto append SDK version information to request headers.Modified files (2)
Latest Contributors(2)