Skip to content

fix: send analytics with the client fetch, agent and custom headers - #334

Open
pcbeingused33 wants to merge 2 commits into
Flagsmith:mainfrom
pcbeingused33:fix/analytics-transport-options
Open

pcbeingused33 wants to merge 2 commits into
Flagsmith:mainfrom
pcbeingused33:fix/analytics-transport-options

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Nov 29, 2026 •

Copy link
Copy Markdown

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

With enableAnalytics: true, the fetch, agent and customHeaders client options were not applied to the analytics requests. FlagsmithConfig documents them as used for HTTP requests, and flag and event requests already use them, but the AnalyticsProcessor was constructed without any of the three. Behind a proxy agent, or a gateway that requires a custom header, flags work while analytics posts fail.

The client now passes all three to AnalyticsProcessor, which uses them in flush(). customHeaders is typed as HeadersInit, so analytics accepts a record, a Headers instance or a list of name/value tuples. As in the event processor, the SDK's own X-Environment-Key, Content-Type and User-Agent take precedence over custom headers with the same name, regardless of casing.

#329 also changes flush(); whichever lands second will need a small rebase.

How did you test this code?

Added a parameterized test in tests/sdk/analytics.test.ts that builds a client with a custom fetch, agent and headers (as a record, a Headers instance and tuples, including lowercase x-environment-key, content-type and user-agent), evaluates a flag and flushes analytics. It fails before the change and passes after it. The full unit suite (508 tests) and the CommonJS and ESM builds pass; the engine e2e suite was not run because its test data submodule was not checked out.

This change was prepared with AI assistance.

@pcbeingused33
pcbeingused33 requested a review from a team as a code owner November 29, 2026 00:18
@pcbeingused33
pcbeingused33 requested review from emyller and removed request for a team November 29, 2026 00:18

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread sdk/analytics.ts Resolved
Comment thread sdk/analytics.ts Resolved
@pcbeingused33

Copy link
Copy Markdown
Author

The follow-up normalizes all three forms of HeadersInit for analytics and keeps the SDK's environment key, content type and user agent when a custom header uses the same name with different casing. The SDK suite passes. #329 is also open and changes flush(). Once either PR merges, the other can merge the updated base while preserving both the header normalization and the in-flight buffer changes.

This comment was drafted with Claude Code.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval skipped because this PR is from an external contributor.

Re-trigger cubic

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.

1 participant