Skip to content

feat(node): Add timestamp tracking for debugging local feature flag evaluation#3163

Merged
gustavohstrassburger merged 6 commits intomainfrom
gustavo/local-evaluation-timestamps
Feb 27, 2026
Merged

feat(node): Add timestamp tracking for debugging local feature flag evaluation#3163
gustavohstrassburger merged 6 commits intomainfrom
gustavo/local-evaluation-timestamps

Conversation

@gustavohstrassburger
Copy link
Contributor

@gustavohstrassburger gustavohstrassburger commented Feb 26, 2026

Problem

Local feature flag evaluation in posthog-node was missing the timestamp tracking that's available in remote evaluation, making it difficult to debug timing-related issues when troubleshooting flag behavior.

When debugging cache TTL problems or investigating timing between flag definition loading and evaluation, developers had no visibility into:

  • When flag definitions were loaded from the server
  • When individual flags were evaluated for comparison with remote evaluation behavior

Changes

Added simple timestamp tracking to improve debugging and observability for local feature flag evaluation:

  • Track when flag definitions are loaded from server (flagDefinitionsLoadedAt)
  • Include timestamps in $feature_flag_called events for locally evaluated flags
  • Provide equivalent timing information to what remote evaluation already includes

The implementation uses a straightforward approach with inline Date.now() calls based on code review feedback, avoiding complex data structures while providing the necessary debugging information.

This ensures locally evaluated flags include the same timestamp data as remotely evaluated flags in analytics events, making it easier to debug timing-related issues and maintain consistency between evaluation methods.

Release info Sub-libraries affected

Libraries affected

  • All of them
  • posthog-js (web)
  • posthog-js-lite (web lite)
  • posthog-node
  • posthog-react-native
  • @posthog/react
  • @posthog/ai
  • @posthog/convex
  • @posthog/nextjs-config
  • @posthog/nuxt
  • @posthog/rollup-plugin
  • @posthog/webpack-plugin
  • @posthog/types

Checklist

  • Tests for new code
  • Accounted for the impact of any changes across different platforms
  • Accounted for backwards compatibility of any changes (no breaking changes!)
  • Took care not to unnecessarily increase the bundle size

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the "release" label to the PR to indicate we're publishing new versions for the affected packages

@vercel
Copy link

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
posthog-js Error Error Feb 27, 2026 9:44pm
posthog-nextjs-config Ready Ready Preview Feb 27, 2026 9:44pm

Request Review

@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

Size Change: +1.05 kB (+0.02%)

Total Size: 6.69 MB

Filename Size Change
packages/node/dist/client.js 33.3 kB +371 B (+1.13%)
packages/node/dist/client.mjs 31.3 kB +371 B (+1.2%)
packages/node/dist/extensions/feature-flags/feature-flags.js 33.9 kB +153 B (+0.45%)
packages/node/dist/extensions/feature-flags/feature-flags.mjs 31.9 kB +153 B (+0.48%)
ℹ️ View Unchanged
Filename Size Change
packages/ai/dist/anthropic/index.cjs 20 kB 0 B
packages/ai/dist/anthropic/index.mjs 19.7 kB 0 B
packages/ai/dist/gemini/index.cjs 26.9 kB 0 B
packages/ai/dist/gemini/index.mjs 26.8 kB 0 B
packages/ai/dist/index.cjs 186 kB 0 B
packages/ai/dist/index.mjs 185 kB 0 B
packages/ai/dist/langchain/index.cjs 42.7 kB 0 B
packages/ai/dist/langchain/index.mjs 42.1 kB 0 B
packages/ai/dist/openai/index.cjs 46.4 kB 0 B
packages/ai/dist/openai/index.mjs 46.1 kB 0 B
packages/ai/dist/otel/index.cjs 36.4 kB 0 B
packages/ai/dist/otel/index.mjs 36.3 kB 0 B
packages/ai/dist/vercel/index.cjs 35.3 kB 0 B
packages/ai/dist/vercel/index.mjs 35.2 kB 0 B
packages/browser/dist/all-external-dependencies.js 268 kB 0 B
packages/browser/dist/array.full.es5.js 327 kB 0 B
packages/browser/dist/array.full.js 426 kB 0 B
packages/browser/dist/array.full.no-external.js 446 kB 0 B
packages/browser/dist/array.js 181 kB 0 B
packages/browser/dist/array.no-external.js 196 kB 0 B
packages/browser/dist/conversations.js 64.5 kB 0 B
packages/browser/dist/crisp-chat-integration.js 2.11 kB 0 B
packages/browser/dist/customizations.full.js 18.5 kB 0 B
packages/browser/dist/dead-clicks-autocapture.js 13.1 kB 0 B
packages/browser/dist/default-extensions.js 179 kB 0 B
packages/browser/dist/element-inference.js 5.85 kB 0 B
packages/browser/dist/exception-autocapture.js 11.9 kB 0 B
packages/browser/dist/external-scripts-loader.js 3.04 kB 0 B
packages/browser/dist/intercom-integration.js 2.16 kB 0 B
packages/browser/dist/lazy-recorder.js 152 kB 0 B
packages/browser/dist/logs.js 39 kB 0 B
packages/browser/dist/main.js 183 kB 0 B
packages/browser/dist/module.full.js 427 kB 0 B
packages/browser/dist/module.full.no-external.js 447 kB 0 B
packages/browser/dist/module.js 182 kB 0 B
packages/browser/dist/module.no-external.js 197 kB 0 B
packages/browser/dist/module.slim.js 147 kB 0 B
packages/browser/dist/module.slim.no-external.js 156 kB 0 B
packages/browser/dist/posthog-recorder.js 252 kB 0 B
packages/browser/dist/product-tours-preview.js 76.7 kB 0 B
packages/browser/dist/product-tours.js 118 kB 0 B
packages/browser/dist/recorder-v2.js 113 kB 0 B
packages/browser/dist/recorder.js 113 kB 0 B
packages/browser/dist/surveys-preview.js 76.4 kB 0 B
packages/browser/dist/surveys.js 90.1 kB 0 B
packages/browser/dist/tracing-headers.js 1.93 kB 0 B
packages/browser/dist/web-vitals-with-attribution.js 12 kB 0 B
packages/browser/dist/web-vitals.js 6.6 kB 0 B
packages/browser/react/dist/esm/index.js 20.5 kB 0 B
packages/browser/react/dist/esm/surveys/index.js 4.54 kB 0 B
packages/browser/react/dist/umd/index.js 23.8 kB 0 B
packages/browser/react/dist/umd/surveys/index.js 5.49 kB 0 B
packages/convex/dist/client/index.js 7.43 kB 0 B
packages/convex/dist/component/_generated/api.js 712 B 0 B
packages/convex/dist/component/_generated/component.js 212 B 0 B
packages/convex/dist/component/_generated/dataModel.js 230 B 0 B
packages/convex/dist/component/_generated/server.js 3.71 kB 0 B
packages/convex/dist/component/convex.config.js 133 B 0 B
packages/convex/dist/component/lib.js 7.49 kB 0 B
packages/convex/dist/component/schema.js 113 B 0 B
packages/core/dist/error-tracking/chunk-ids.js 2.54 kB 0 B
packages/core/dist/error-tracking/chunk-ids.mjs 1.31 kB 0 B
packages/core/dist/error-tracking/coercers/dom-exception-coercer.js 2.3 kB 0 B
packages/core/dist/error-tracking/coercers/dom-exception-coercer.mjs 993 B 0 B
packages/core/dist/error-tracking/coercers/error-coercer.js 2.02 kB 0 B
packages/core/dist/error-tracking/coercers/error-coercer.mjs 794 B 0 B
packages/core/dist/error-tracking/coercers/error-event-coercer.js 1.76 kB 0 B
packages/core/dist/error-tracking/coercers/error-event-coercer.mjs 513 B 0 B
packages/core/dist/error-tracking/coercers/event-coercer.js 1.82 kB 0 B
packages/core/dist/error-tracking/coercers/event-coercer.mjs 548 B 0 B
packages/core/dist/error-tracking/coercers/index.js 6.79 kB 0 B
packages/core/dist/error-tracking/coercers/index.mjs 326 B 0 B
packages/core/dist/error-tracking/coercers/object-coercer.js 3.46 kB 0 B
packages/core/dist/error-tracking/coercers/object-coercer.mjs 2.07 kB 0 B
packages/core/dist/error-tracking/coercers/primitive-coercer.js 1.67 kB 0 B
packages/core/dist/error-tracking/coercers/primitive-coercer.mjs 419 B 0 B
packages/core/dist/error-tracking/coercers/promise-rejection-event.js 2.25 kB 0 B
packages/core/dist/error-tracking/coercers/promise-rejection-event.mjs 904 B 0 B
packages/core/dist/error-tracking/coercers/string-coercer.js 2.01 kB 0 B
packages/core/dist/error-tracking/coercers/string-coercer.mjs 820 B 0 B
packages/core/dist/error-tracking/coercers/utils.js 2.06 kB 0 B
packages/core/dist/error-tracking/coercers/utils.mjs 716 B 0 B
packages/core/dist/error-tracking/error-properties-builder.js 5.56 kB 0 B
packages/core/dist/error-tracking/error-properties-builder.mjs 4.23 kB 0 B
packages/core/dist/error-tracking/index.js 4.11 kB 0 B
packages/core/dist/error-tracking/index.mjs 152 B 0 B
packages/core/dist/error-tracking/parsers/base.js 1.83 kB 0 B
packages/core/dist/error-tracking/parsers/base.mjs 464 B 0 B
packages/core/dist/error-tracking/parsers/chrome.js 2.73 kB 0 B
packages/core/dist/error-tracking/parsers/chrome.mjs 1.32 kB 0 B
packages/core/dist/error-tracking/parsers/gecko.js 2.47 kB 0 B
packages/core/dist/error-tracking/parsers/gecko.mjs 1.13 kB 0 B
packages/core/dist/error-tracking/parsers/index.js 4.75 kB 0 B
packages/core/dist/error-tracking/parsers/index.mjs 2.1 kB 0 B
packages/core/dist/error-tracking/parsers/node.js 3.94 kB 0 B
packages/core/dist/error-tracking/parsers/node.mjs 2.68 kB 0 B
packages/core/dist/error-tracking/parsers/opera.js 2.26 kB 0 B
packages/core/dist/error-tracking/parsers/opera.mjs 746 B 0 B
packages/core/dist/error-tracking/parsers/safari.js 1.88 kB 0 B
packages/core/dist/error-tracking/parsers/safari.mjs 574 B 0 B
packages/core/dist/error-tracking/parsers/winjs.js 1.72 kB 0 B
packages/core/dist/error-tracking/parsers/winjs.mjs 426 B 0 B
packages/core/dist/error-tracking/types.js 1.33 kB 0 B
packages/core/dist/error-tracking/types.mjs 131 B 0 B
packages/core/dist/error-tracking/utils.js 1.8 kB 0 B
packages/core/dist/error-tracking/utils.mjs 604 B 0 B
packages/core/dist/eventemitter.js 1.78 kB 0 B
packages/core/dist/eventemitter.mjs 571 B 0 B
packages/core/dist/featureFlagUtils.js 6.8 kB 0 B
packages/core/dist/featureFlagUtils.mjs 4.32 kB 0 B
packages/core/dist/gzip.js 1.88 kB 0 B
packages/core/dist/gzip.mjs 577 B 0 B
packages/core/dist/index.js 6.87 kB 0 B
packages/core/dist/index.mjs 650 B 0 B
packages/core/dist/posthog-core-stateless.js 31.1 kB 0 B
packages/core/dist/posthog-core-stateless.mjs 28.6 kB 0 B
packages/core/dist/posthog-core.js 41.1 kB 0 B
packages/core/dist/posthog-core.mjs 36.1 kB 0 B
packages/core/dist/process/index.js 2.77 kB 0 B
packages/core/dist/process/index.mjs 114 B 0 B
packages/core/dist/process/spawn-local.js 1.82 kB 0 B
packages/core/dist/process/spawn-local.mjs 568 B 0 B
packages/core/dist/process/utils.js 3.27 kB 0 B
packages/core/dist/process/utils.mjs 1.3 kB 0 B
packages/core/dist/surveys/validation.js 3.06 kB 0 B
packages/core/dist/surveys/validation.mjs 1.51 kB 0 B
packages/core/dist/testing/index.js 2.93 kB 0 B
packages/core/dist/testing/index.mjs 79 B 0 B
packages/core/dist/testing/PostHogCoreTestClient.js 3.15 kB 0 B
packages/core/dist/testing/PostHogCoreTestClient.mjs 1.74 kB 0 B
packages/core/dist/testing/test-utils.js 2.77 kB 0 B
packages/core/dist/testing/test-utils.mjs 1.09 kB 0 B
packages/core/dist/types.js 9.5 kB 0 B
packages/core/dist/types.mjs 6.95 kB 0 B
packages/core/dist/utils/bot-detection.js 3.28 kB 0 B
packages/core/dist/utils/bot-detection.mjs 1.95 kB 0 B
packages/core/dist/utils/bucketed-rate-limiter.js 3 kB 0 B
packages/core/dist/utils/bucketed-rate-limiter.mjs 1.62 kB 0 B
packages/core/dist/utils/index.js 11.9 kB 0 B
packages/core/dist/utils/index.mjs 1.98 kB 0 B
packages/core/dist/utils/logger.js 2.5 kB 0 B
packages/core/dist/utils/logger.mjs 1.22 kB 0 B
packages/core/dist/utils/number-utils.js 2 kB 0 B
packages/core/dist/utils/number-utils.mjs 735 B 0 B
packages/core/dist/utils/promise-queue.js 2 kB 0 B
packages/core/dist/utils/promise-queue.mjs 768 B 0 B
packages/core/dist/utils/string-utils.js 2.73 kB 0 B
packages/core/dist/utils/string-utils.mjs 1.09 kB 0 B
packages/core/dist/utils/type-utils.js 7.03 kB 0 B
packages/core/dist/utils/type-utils.mjs 3.1 kB 0 B
packages/core/dist/utils/user-agent-utils.js 14.9 kB 0 B
packages/core/dist/utils/user-agent-utils.mjs 11.9 kB 0 B
packages/core/dist/vendor/uuidv7.js 8.29 kB 0 B
packages/core/dist/vendor/uuidv7.mjs 6.72 kB 0 B
packages/nextjs-config/dist/config.js 4.97 kB 0 B
packages/nextjs-config/dist/config.mjs 3.48 kB 0 B
packages/nextjs-config/dist/index.js 2.24 kB 0 B
packages/nextjs-config/dist/index.mjs 30 B 0 B
packages/nextjs-config/dist/utils.js 4 kB 0 B
packages/nextjs-config/dist/utils.mjs 1.89 kB 0 B
packages/node/dist/entrypoints/index.edge.js 4.25 kB 0 B
packages/node/dist/entrypoints/index.edge.mjs 723 B 0 B
packages/node/dist/entrypoints/index.node.js 5.55 kB 0 B
packages/node/dist/entrypoints/index.node.mjs 1.08 kB 0 B
packages/node/dist/experimental.js 603 B 0 B
packages/node/dist/experimental.mjs 0 B 0 B 🆕
packages/node/dist/exports.js 4.22 kB 0 B
packages/node/dist/exports.mjs 203 B 0 B
packages/node/dist/extensions/context/context.js 2.13 kB 0 B
packages/node/dist/extensions/context/context.mjs 863 B 0 B
packages/node/dist/extensions/context/types.js 603 B 0 B
packages/node/dist/extensions/context/types.mjs 0 B 0 B 🆕
packages/node/dist/extensions/error-tracking/autocapture.js 2.66 kB 0 B
packages/node/dist/extensions/error-tracking/autocapture.mjs 1.24 kB 0 B
packages/node/dist/extensions/error-tracking/index.js 4.25 kB 0 B
packages/node/dist/extensions/error-tracking/index.mjs 2.96 kB 0 B
packages/node/dist/extensions/error-tracking/modifiers/context-lines.node.js 8.81 kB 0 B
packages/node/dist/extensions/error-tracking/modifiers/context-lines.node.mjs 7.15 kB 0 B
packages/node/dist/extensions/error-tracking/modifiers/module.node.js 2.78 kB 0 B
packages/node/dist/extensions/error-tracking/modifiers/module.node.mjs 1.45 kB 0 B
packages/node/dist/extensions/express.js 2.84 kB 0 B
packages/node/dist/extensions/express.mjs 1.25 kB 0 B
packages/node/dist/extensions/feature-flags/cache.js 603 B 0 B
packages/node/dist/extensions/feature-flags/cache.mjs 0 B 0 B 🆕
packages/node/dist/extensions/feature-flags/crypto.js 1.57 kB 0 B
packages/node/dist/extensions/feature-flags/crypto.mjs 395 B 0 B
packages/node/dist/extensions/sentry-integration.js 4.66 kB 0 B
packages/node/dist/extensions/sentry-integration.mjs 3.17 kB 0 B
packages/node/dist/storage-memory.js 1.52 kB 0 B
packages/node/dist/storage-memory.mjs 297 B 0 B
packages/node/dist/types.js 1.43 kB 0 B
packages/node/dist/types.mjs 224 B 0 B
packages/node/dist/version.js 1.21 kB 0 B
packages/node/dist/version.mjs 46 B 0 B
packages/nuxt/dist/module.mjs 4.59 kB 0 B
packages/nuxt/dist/runtime/composables/useFeatureFlagEnabled.js 566 B 0 B
packages/nuxt/dist/runtime/composables/useFeatureFlagPayload.js 597 B 0 B
packages/nuxt/dist/runtime/composables/useFeatureFlagVariantKey.js 591 B 0 B
packages/nuxt/dist/runtime/composables/usePostHog.js 128 B 0 B
packages/nuxt/dist/runtime/nitro-plugin.js 1.08 kB 0 B
packages/nuxt/dist/runtime/vue-plugin.js 1.14 kB 0 B
packages/react-native/dist/autocapture.js 5.05 kB 0 B
packages/react-native/dist/error-tracking/index.js 7.24 kB 0 B
packages/react-native/dist/error-tracking/utils.js 2.58 kB 0 B
packages/react-native/dist/frameworks/wix-navigation.js 1.3 kB 0 B
packages/react-native/dist/hooks/useFeatureFlag.js 1.7 kB 0 B
packages/react-native/dist/hooks/useFeatureFlagResult.js 963 B 0 B
packages/react-native/dist/hooks/useFeatureFlags.js 921 B 0 B
packages/react-native/dist/hooks/useNavigationTracker.js 2.45 kB 0 B
packages/react-native/dist/hooks/usePostHog.js 544 B 0 B
packages/react-native/dist/hooks/utils.js 988 B 0 B
packages/react-native/dist/index.js 4.33 kB 0 B
packages/react-native/dist/native-deps.js 8 kB 0 B
packages/react-native/dist/optional/OptionalAsyncStorage.js 299 B 0 B
packages/react-native/dist/optional/OptionalExpoApplication.js 377 B 0 B
packages/react-native/dist/optional/OptionalExpoDevice.js 347 B 0 B
packages/react-native/dist/optional/OptionalExpoFileSystem.js 386 B 0 B
packages/react-native/dist/optional/OptionalExpoFileSystemLegacy.js 423 B 0 B
packages/react-native/dist/optional/OptionalExpoLocalization.js 383 B 0 B
packages/react-native/dist/optional/OptionalReactNativeDeviceInfo.js 415 B 0 B
packages/react-native/dist/optional/OptionalReactNativeLocalize.js 303 B 0 B
packages/react-native/dist/optional/OptionalReactNativeNavigation.js 415 B 0 B
packages/react-native/dist/optional/OptionalReactNativeNavigationWix.js 443 B 0 B
packages/react-native/dist/optional/OptionalReactNativeSafeArea.js 644 B 0 B
packages/react-native/dist/optional/OptionalSessionReplay.js 455 B 0 B
packages/react-native/dist/posthog-rn.js 38.4 kB 0 B
packages/react-native/dist/PostHogContext.js 329 B 0 B
packages/react-native/dist/PostHogErrorBoundary.js 3.19 kB 0 B
packages/react-native/dist/PostHogMaskView.js 1.66 kB 0 B
packages/react-native/dist/PostHogProvider.js 4.77 kB 0 B
packages/react-native/dist/storage.js 4.49 kB 0 B
packages/react-native/dist/surveys/components/BottomSection.js 1.46 kB 0 B
packages/react-native/dist/surveys/components/Cancel.js 909 B 0 B
packages/react-native/dist/surveys/components/ConfirmationMessage.js 1.65 kB 0 B
packages/react-native/dist/surveys/components/QuestionHeader.js 1.37 kB 0 B
packages/react-native/dist/surveys/components/QuestionTypes.js 12.7 kB 0 B
packages/react-native/dist/surveys/components/SurveyModal.js 4.01 kB 0 B
packages/react-native/dist/surveys/components/Surveys.js 7.22 kB 0 B
packages/react-native/dist/surveys/getActiveMatchingSurveys.js 2.64 kB 0 B
packages/react-native/dist/surveys/icons.js 8.86 kB 0 B
packages/react-native/dist/surveys/index.js 600 B 0 B
packages/react-native/dist/surveys/PostHogSurveyProvider.js 5.71 kB 0 B
packages/react-native/dist/surveys/surveys-utils.js 12.7 kB 0 B
packages/react-native/dist/surveys/useActivatedSurveys.js 3.67 kB 0 B
packages/react-native/dist/surveys/useSurveyStorage.js 2.16 kB 0 B
packages/react-native/dist/tooling/expoconfig.js 2.63 kB 0 B
packages/react-native/dist/tooling/metroconfig.js 2.32 kB 0 B
packages/react-native/dist/tooling/posthogMetroSerializer.js 4.86 kB 0 B
packages/react-native/dist/tooling/utils.js 4.05 kB 0 B
packages/react-native/dist/tooling/vendor/expo/expoconfig.js 70 B 0 B
packages/react-native/dist/tooling/vendor/metro/countLines.js 237 B 0 B
packages/react-native/dist/tooling/vendor/metro/utils.js 3.35 kB 0 B
packages/react-native/dist/types.js 70 B 0 B
packages/react-native/dist/utils.js 1.27 kB 0 B
packages/react-native/dist/version.js 130 B 0 B
packages/react/dist/esm/index.js 20.5 kB 0 B
packages/react/dist/esm/surveys/index.js 4.54 kB 0 B
packages/react/dist/umd/index.js 23.8 kB 0 B
packages/react/dist/umd/surveys/index.js 5.49 kB 0 B
packages/rollup-plugin/dist/index.js 5.15 kB 0 B
packages/types/dist/capture.js 603 B 0 B
packages/types/dist/capture.mjs 0 B 0 B 🆕
packages/types/dist/common.js 603 B 0 B
packages/types/dist/common.mjs 0 B 0 B 🆕
packages/types/dist/feature-flags.js 603 B 0 B
packages/types/dist/feature-flags.mjs 0 B 0 B 🆕
packages/types/dist/index.js 603 B 0 B
packages/types/dist/index.mjs 0 B 0 B 🆕
packages/types/dist/posthog-config.js 603 B 0 B
packages/types/dist/posthog-config.mjs 0 B 0 B 🆕
packages/types/dist/posthog.js 603 B 0 B
packages/types/dist/posthog.mjs 0 B 0 B 🆕
packages/types/dist/request.js 603 B 0 B
packages/types/dist/request.mjs 0 B 0 B 🆕
packages/types/dist/segment.js 603 B 0 B
packages/types/dist/segment.mjs 0 B 0 B 🆕
packages/types/dist/session-recording.js 603 B 0 B
packages/types/dist/session-recording.mjs 0 B 0 B 🆕
packages/types/dist/survey.js 603 B 0 B
packages/types/dist/survey.mjs 0 B 0 B 🆕
packages/types/dist/toolbar.js 603 B 0 B
packages/types/dist/toolbar.mjs 0 B 0 B 🆕
packages/web/dist/index.cjs 13.8 kB 0 B
packages/web/dist/index.mjs 13.7 kB 0 B
packages/webpack-plugin/dist/config.js 3.15 kB 0 B
packages/webpack-plugin/dist/config.mjs 2.14 kB 0 B
packages/webpack-plugin/dist/index.js 6.53 kB 0 B
packages/webpack-plugin/dist/index.mjs 3.12 kB 0 B
tooling/changelog/dist/index.js 3.31 kB 0 B
tooling/rollup-utils/dist/index.js 1.17 kB 0 B

compressed-size-action

Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

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

Okay, this is a valid problem and I'm glad you're tackling it. I am not sure it's exactly the right way to go about it though; here's what I'm thinking:

  1. The evaluationTimestampCache design is awkward. The context is created fresh per-request, so the "cache" is set during evaluation and read moments later in the same call. It's not really caching anything
    across requests - it's just a roundabout way to pass Date.now() from the evaluation point to the event emission.
  2. Over-engineering? For local evaluation, the flag is computed synchronously. The evaluation timestamp is essentially "now." Why not just capture Date.now() directly when building the event properties, rather than storing it in a context object first?
  3. The flagDefinitionsLoadedAt part makes sense - knowing when your cached definitions were fetched is useful for cache TTL management and debugging staleness issues.
  4. The per-flag timestamp seems less useful - For remote evaluation, evaluatedAt comes from the server and tells you when the server made the decision (which could differ from request time due to network latency). For local evaluation, evaluation happens immediately when you call the method - the timestamp is always "right now."

A simpler approach might be:

  • Keep flagDefinitionsLoadedAt
  • Drop the evaluationTimestampCache complexity and just use Date.now() inline when setting $feature_flag_evaluated_at for locally evaluated flags (unless there's a specific use case where you evaluate a flag, then later send the event and need to preserve the original evaluation time – but that doesn't seem like the common pattern here)

Remove evaluationTimestampCache complexity and use inline Date.now()
for local flag evaluation timestamps. The cache was unnecessary since
evaluation happens synchronously and timestamps are used immediately.

- Remove evaluationTimestampCache from FeatureFlagEvaluationContext
- Remove getFlagEvaluatedAt method from FeatureFlagsPoller
- Use Date.now() inline when setting $feature_flag_evaluated_at
- Update tests to verify timestamp functionality via event capture
- Keep flagDefinitionsLoadedAt for cache TTL management

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@gustavohstrassburger
Copy link
Contributor Author

gustavohstrassburger commented Feb 27, 2026

Hey @dmarticus,

Appreciate the feedback, it actually made me realize that I got something wrong in terms of the flow of local eval.
I was under the impression that after locally evaluating the flags we were caching the value, this is why I decided to store both timestamps.

I'll simplify this PR with your suggestions.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Rename and update changeset to emphasize the new timestamp tracking
feature for local evaluation rather than implementation details.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@gustavohstrassburger gustavohstrassburger changed the title feat(node): Add timestamp tracking for local feature flag evaluation fix(node): Add timestamp tracking for debugging local feature flag evaluation Feb 27, 2026
Change from minor to patch version bump and reframe as debugging
improvement rather than major feature addition.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@gustavohstrassburger gustavohstrassburger changed the title fix(node): Add timestamp tracking for debugging local feature flag evaluation feat(node): Add timestamp tracking for debugging local feature flag evaluation Feb 27, 2026
Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

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

Looks good — this is a nice simplification from the earlier version. The inline Date.now() approach is much cleaner than the cache abstraction.

Two minor nits:

  1. $feature_flag_evaluated_at gets set twice for local evaluations — It's first set to evaluatedAt (which is undefined for local evals) in the initial properties object, then overridden with Date.now() in the new block. This works but is slightly confusing to read. You could set it once:

    $feature_flag_evaluated_at: flagWasLocallyEvaluated ? Date.now() : evaluatedAt,

    ...and then the new if block only needs to handle $feature_flag_definitions_loaded_at. Minor nit though, not blocking.

  2. flagDefinitionsLoadedAt semantics when loading from cacheupdateFlagState is called from both the network fetch path and the cache load path. This means if definitions are loaded from cache, flagDefinitionsLoadedAt reflects when the cache was read, not when the definitions were originally fetched from the server. If the goal is debugging staleness, you might want the original fetch time instead. Worth a comment clarifying the intended semantics either way.

Neither of these is blocking — approving as-is.

Address Dylan's feedback:
- Consolidate $feature_flag_evaluated_at setting using ternary operator
- Fix flagDefinitionsLoadedAt to only reflect original server fetch time
- Preserve cache load efficiency by not setting timestamp on cache hits

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@gustavohstrassburger gustavohstrassburger merged commit 0dc03b0 into main Feb 27, 2026
41 of 42 checks passed
@gustavohstrassburger gustavohstrassburger deleted the gustavo/local-evaluation-timestamps branch February 27, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants