[sdk/local-evaluation] getEnvironmentFlags() evaluations are not tracked for analytics
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- Unter einer Stunde
- Anfängerfreundlichkeit
- 85/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- nodejs, typescript
- Bereich
- analytics
Rechercherichtung
Das Issue verweist auf getEnvironmentFlagsFromDocument in sdk/index.ts etwa in Zeile 640, wo Flags.fromEvaluationResult ohne den Analytics-Processor aufgerufen wird. Vergleiche das mit getIdentityFlagsFromDocument nahe Zeile 669, die bereits this.analyticsProcessor übergibt. Führe das Reproduktionsskript aus dem Issue aus. Fertig ist es, wenn der lokale Lauf {"my_feature":5} meldet, wie der Remote-Lauf.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Problem
With enableLocalEvaluation: true, flag evaluations from getEnvironmentFlags() are never counted towards analytics. The same code against the same environment reports usage correctly when local evaluation is off, so flag analytics are effectively unavailable to anyone evaluating locally.
The cause looks like a missed argument in getEnvironmentFlagsFromDocument:
// sdk/index.ts:640
const flags = Flags.fromEvaluationResult(evaluationResult);
The other three evaluation paths all pass the processor through:
getIdentityFlagsFromDocument(local) ->sdk/index.ts:669, passesthis.analyticsProcessorgetEnvironmentFlagsFromApi(remote) ->sdk/index.ts:689getIdentityFlagsFromApi(remote) ->sdk/index.ts:710
Since the other local path already tracks, this doesn't look like a deliberate decision to skip analytics during local evaluation.
For what it's worth, the Python client passes it in the equivalent method, so the two SDKs behave differently here:
# flagsmith/flagsmith.py:535, _get_environment_flags_from_document
return Flags.from_evaluation_result(
evaluation_result=evaluation_result,
analytics_processor=self._analytics_processor,
default_flag_handler=self.default_flag_handler,
)
Impact
getEnvironmentFlags() is the common path for server-side usage, and local evaluation is the recommended mode there, so this combination silently reports no usage at all. Nothing warns or errors, and the dashboard just shows the flag as unused. We ran into it while using analytics to decide which stale flags were safe to delete, where a flag wrongly showing zero evaluations is the dangerous direction to be wrong in.
Reproduction
Standalone script, no account needed; it stubs the API locally and compares the two modes.
const http = require('node:http');
const { Flagsmith } = require('flagsmith-nodejs');
const ENV_DOC = {
api_key: 'ser.repro',
project: { id: 1, name: 'repro', organisation: { id: 1, name: 'org', feature_analytics: true,
stop_serving_flags: false, persist_trait_data: true }, hide_disabled_flags: false, segments: [] },
feature_states: [{ feature: { id: 1, name: 'my_feature', type: 'STANDARD' },
enabled: true, feature_state_value: null, featurestate_uuid: 'fs-1', multivariate_feature_state_values: [] }],
identity_overrides: []
};
const API_FLAGS = [{ feature: { id: 1, name: 'my_feature', type: 'STANDARD' },
enabled: true, feature_state_value: null }];
(async () => {
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
if (req.url.includes('environment-document')) return res.end(JSON.stringify(ENV_DOC));
if (req.url.includes('/flags')) return res.end(JSON.stringify(API_FLAGS));
res.end('{}');
});
await new Promise(r => server.listen(0, '127.0.0.1', r));
const apiUrl = `http://127.0.0.1:${server.address().port}/api/v1/`;
async function run(local) {
const f = new Flagsmith({ environmentKey: 'ser.repro', apiUrl,
enableLocalEvaluation: local, enableAnalytics: true });
const flags = await f.getEnvironmentFlags();
for (let i = 0; i < 5; i++) await flags.isFeatureEnabled('my_feature');
const buf = { ...(f.analyticsProcessor?.analyticsData ?? {}) };
f.environmentDataPollingManager?.stop();
console.log(`${local ? 'LOCAL ' : 'REMOTE'} -> buffer ${JSON.stringify(buf)}`);
}
await run(true);
await run(false);
server.close();
})();
Observed:
LOCAL -> buffer {}
REMOTE -> buffer {"my_feature":5}
Expected: both report {"my_feature":5}.
Version: [email protected] (current npm latest), Node 24.13.0. Line numbers above are from main as of today, which still has the same call.
Workaround
Calling trackFeature(name) on the processor after each evaluation restores the counts, which is what we're doing for now.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 30
- Forks
- 28
- Ø Merge
- 7 T. 23 Std.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus Flagsmith/flagsmith-nodejs-client
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 65/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
-
Dependency DashboardOffen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
Flagsmith/flagsmith-nodejs-client#273 · 1 Kommentar ·
-
[sdk/local-evaluation] Duplicate identity override entries silently drop feature overridesEvtl. vergeben @xolott-ark hat das vor 158 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
Flagsmith/flagsmith-nodejs-client#267 · 5 Kommentare ·
Alle Issues in Flagsmith/flagsmith-nodejs-client
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
apache/rocketmq-dashboard#6610 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
nextjs-tracking
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 69/100
cloudflare/vinext#3920 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Team:Dashboards
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
elastic/kibana#297299 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
analytics beginner friendly community contributions-welcome good first issue hacktoberfest help wanted up-for-grabs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
affected/v17 affected/v18 area/frontend type/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
umbraco/Umbraco-CMS#24186 ·
Maintainer antworten meist innerhalb von 2 Tagen