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

Offen Anfängerfreundlich
#332 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
76/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
node.js, typescript
Bereich
api, backend

Rechercherichtung

Beginne mit sdk/events.ts und dem Flagsmith-Konstruktor, wo laut Issue die Event-URL ausgewählt und eventProcessorConfig weitergegeben wird. Vergleiche diese URL-Behandlung damit, wie die Analytics-URL aus apiUrl abgeleitet wird. Das Reproduktionsskript zeichnet die Anfrageziele auf; fertig ist es, wenn Events aus einem selbst gehosteten Setup an die vorgesehene Instanz gehen oder beim Erstellen eine Warnung ausgegeben wird, wenn sie an Flagsmith Cloud gehen würden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
TypeScript
Sterne
30
Forks
30
Ø Merge
1 T. 16 Std.
Gemergte PRs (30 T.)
11

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus Flagsmith/flagsmith-nodejs-client

Alle Issues in Flagsmith/flagsmith-nodejs-client

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.