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

未關閉 適合新手
#332 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
76/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
node.js, typescript
領域
api, backend

研究方向

從 sdk/events.ts 和 Flagsmith 建構函式著手。issue 指出,事件 URL 在此選定,eventProcessorConfig 也在此傳入。將這項 URL 處理方式與從 apiUrl 推導 analytics URL 的方式比較。重現腳本會記錄請求目的地;當 self-hosted 環境中的事件被送往預期的 instance,或在事件將被送往 Flagsmith Cloud 時於建構期間發出警告,即為完成。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
TypeScript
星號
30
分支
30
平均合併
1 天 16 小時
30 天內合併 PR
11

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Flagsmith/flagsmith-nodejs-client 的其他 Issue

查看 Flagsmith/flagsmith-nodejs-client 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。