fix(streaming): identify the SDK on the WebSocket handshake - #72
Open
karlwaldman wants to merge 1 commit into
Open
fix(streaming): identify the SDK on the WebSocket handshake#72karlwaldman wants to merge 1 commit into
karlwaldman wants to merge 1 commit into
Conversation
The ActionCable upgrade request is an ordinary HTTP request, but the streaming client sent only `Authorization` on it. A streaming connection was therefore indistinguishable from a hand-rolled WebSocket client and dropped out of SDK attribution entirely, while the HTTP path has always been attributed correctly. The Go SDK already sets a User-Agent on its handshake (stream.go); this brings Node into line and adds the X-SDK-* pair the HTTP path sends. Also pins the server-side attribution contract from the SDK side. The server parses sdk_language/sdk_version out of the User-Agent with `/oilpriceapi-([a-z0-9-]+)\/v?([\d]+\.[\d]+\.?[\d]*)/i` (MinimalAnalyticsService#detect_sdk_info). A UA that stops matching it still returns 200 — the request succeeds and the SDK silently vanishes from adoption reporting. Nothing on either side guarded that shape, so the new tests assert the parsed language and version, not just a substring, across the HTTP, demo and WebSocket paths. Proven red-capable: rewriting buildUserAgent to emit `oilpriceapi-node-v1.2.6` fails 4 tests (2 pre-existing, 2 new); the new WebSocket test failed before the fix and passes after. Verified: npm run build clean; 508 tests pass, 1 skipped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JKAExynd9zoKwt6rYA66EA
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
What this is not
This started as "make
sdk_versionpopulate" (it sits at 1.65% of requests). That premise is refuted. I verified in production that every SDK which sends a User-Agent is already parsed correctly —oilpriceapi-node/1.2.6 node/v22.23.2arrives withsdk_language=node, sdk_version=1.2.6. There is no client-side or server-parsing defect on the HTTP path.The 1.65% is a denominator artefact plus contamination, not a bug in this repo (details in the session summary; the fixes are server-side and are being routed separately). Notably the bucket named
sdk-nodeis 8 requests ours out of 27,874 — the rest is genericnode/axios/node-fetchtraffic the server files under the same name.What this actually fixes
One real, verified gap in this repo: the WebSocket handshake sent no SDK identification at all.
src/resources/streaming.tssent onlyAuthorizationon the ActionCable upgrade. That upgrade is an ordinary HTTP request, so a streaming client was indistinguishable from a hand-rolled WebSocket and dropped out of SDK attribution entirely — while the HTTP path was attributed correctly all along.The Go SDK already does this properly (
stream.gosetsUser-Agent). Node and Python did not. This brings Node into line.Honest scope of the benefit
This does not by itself make streaming measurable.
ApplicationCable::Connection#track_connectionin oilpriceapi-api deliberately does not recorduser_agent— issue #1291 removed it as fingerprinting data under data minimisation. So this is a prerequisite, not a win: the client now sends what a server could attribute, and whether the server should record it is a separate privacy decision, not something this PR presumes.I would rather say that plainly than imply a metric will move.
The regression guard is the durable half
The server parses attribution with exactly:
A User-Agent that stops matching it still returns 200. The request succeeds and the SDK silently disappears from adoption reporting — a failure no HTTP-level test would ever catch, and nothing on either side guarded the shape. The new tests assert the parsed language and version, not a substring, across the HTTP, demo and WebSocket paths.
Red-capability proven
Rewriting
buildUserAgent()to emitoilpriceapi-node-v1.2.6fails 4 tests (2 pre-existing, 2 new). The WebSocket test failed before the fix and passes after. Reverted before commit.Verification
Please do not merge yet
Per house rules an SDK release changes what customers run. Leaving this open for review.
🤖 Generated with Claude Code
https://claude.ai/code/session_01JKAExynd9zoKwt6rYA66EA