Self-hosted: experiment events go to Flagsmith Cloud unless eventsApiUrl is set

Open Beginner friendly
#332 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
api, backend

Research direction

Start with sdk/events.ts and the Flagsmith constructor, where the issue says the event URL is selected and eventProcessorConfig is passed through. Compare that URL handling with how the analytics URL is derived from apiUrl. The reproduction script records request destinations; done when events from a self-hosted setup go to the intended instance, or construction warns when they would go to Flagsmith Cloud.

Written by the indexing model from the issue text.

Description

With apiUrl pointing at a self-hosted Flagsmith and enableEvents: true, trackEvent and the exposures that getExperimentFlag records are sent to Flagsmith Cloud (https://events.api.flagsmith.com/v1/events), not to the self-hosted instance. Nothing warns: the self-hosted instance never sees the events, its experiments show no data, and each event (the identity's identifier, the event name, any value) plus the environment key leaves the network.

Where: EventProcessor takes opts.eventsApiUrl || DEFAULT_EVENTS_API_URL (sdk/events.ts; DEFAULT_EVENTS_API_URL = 'https://events.api.flagsmith.com/'), and the Flagsmith constructor passes only eventProcessorConfig through, so the default is used whatever apiUrl is. The analytics URL, by contrast, is derived from apiUrl (new URL(ANALYTICS_ENDPOINT, apiUrl)), so a self-hosted setup gets analytics right and events wrong.

Reproduction (no network: a custom fetch records the destinations): https://github.com/tharunkumardeveloper/turnout/blob/main/spikes/sdk-events-url/repro.mjs

apiUrl (self-hosted): http://127.0.0.1:55651/api/v1/
  GET http://127.0.0.1:55651/api/v1/environment-document/
  POST https://events.api.flagsmith.com/v1/events

Same result on 9.4.0 and 9.5.0. Found by accident while writing an example against a self-hosted 2.291.0: its experiment stayed empty while the events went to Cloud.

Suggested fix, either:

  1. When apiUrl is set and isn't Flagsmith's own edge API, derive the events URL from it, as analytics already is: apiUrl without its trailing v1/ as eventsApiUrl, so events go to {host}/api/v1/events on the same instance (what Turnout passes today, and it works against 2.291.0); or
  2. at least log a warning at construction when enableEvents is true, apiUrl is not the default, and eventsApiUrl isn't set.

Option 1 matches how the analytics URL already works. Happy to open a PR for either.

Dominant language
TypeScript
Stars
30
Forks
30
Avg merge
1d 16h
Merged PRs (30d)
11

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Flagsmith/flagsmith-nodejs-client

All issues in Flagsmith/flagsmith-nodejs-client

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.