- Notifications
You must be signed in to change notification settings - Fork 201
feat(flags): add evaluation_environments to node and react-native SDKs #2417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6 files reviewed, 4 comments
| const posthogWithEnvs = new PostHog('TEST_API_KEY', { | ||
| host: 'http://example.com', | ||
| evaluationEnvironments: ['production', 'backend'], | ||
| ...posthogImmediateResolveOptions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider extracting posthogImmediateResolveOptions to a shared constant at the top of the file for better maintainability
Context Used: Context from dashboard - When defining constants, such as template IDs, use a constants file or define them at the top of the... (source)
Prompt To Fix With AI
This is a comment left during a code review. Path: packages/node/src/__tests__/posthog-node.spec.ts Line: 2483:2483 Comment: **style:** Consider extracting `posthogImmediateResolveOptions` to a shared constant at the top of the file for better maintainability **Context Used:** Context from `dashboard` - When defining constants, such as template IDs, use a constants file or define them at the top of the... ([source](https://app.greptile.com/review/custom-context?memory=046b860e-6d45-4e24-be8e-6e1727a1b550)) How can I resolve this? If you propose a fix, please make it concise.| 'http://example.com/flags/?v=2&config=true', | ||
| expect.objectContaining({ | ||
| method: 'POST', | ||
| body: expect.stringContaining('"evaluation_environments":["production","backend"]'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: This string assertion is fragile. Consider using JSON.parse() on the body and asserting against the parsed object structure instead
Prompt To Fix With AI
This is a comment left during a code review. Path: packages/node/src/__tests__/posthog-node.spec.ts Line: 2492:2492 Comment: **style:** This string assertion is fragile. Consider using `JSON.parse()` on the body and asserting against the parsed object structure instead How can I resolve this? If you propose a fix, please make it concise.| expect.stringContaining('/flags/?v=2&config=true'), | ||
| expect.objectContaining({ | ||
| method: 'POST', | ||
| body: expect.stringContaining('"evaluation_environments":["production","mobile"]'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The test uses string matching on the request body, which could be brittle if the JSON serialization order changes. Consider using JSON.parse() to validate the presence of the field more reliably.
Prompt To Fix With AI
This is a comment left during a code review. Path: packages/react-native/test/posthog.spec.ts Line: 24:24 Comment: **style:** The test uses string matching on the request body, which could be brittle if the JSON serialization order changes. Consider using JSON.parse() to validate the presence of the field more reliably. How can I resolve this? If you propose a fix, please make it concise.| this.disableGeoip = options?.disableGeoip ?? true | ||
| this.disabled = options?.disabled ?? false | ||
| this.historicalMigration = options?.historicalMigration ?? false | ||
| this.evaluationEnvironments = options?.evaluationEnvironments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Missing property declaration for evaluationEnvironments. This will cause a TypeScript compilation error since the property is not declared in the class.
| this.evaluationEnvironments = options?.evaluationEnvironments | |
| // Evaluation environments configuration | |
| private evaluationEnvironments?: string[]; | |
| constructor(apiKey: string, options?: PostHogCoreOptions) { | |
| assert(apiKey, "You must pass your PostHog project's api key.") | |
| this.apiKey = apiKey | |
| this.host = removeTrailingSlash(options?.host || 'https://us.i.posthog.com') | |
| this.flushAt = options?.flushAt ? Math.max(options?.flushAt, 1) : 20 | |
| this.maxBatchSize = Math.max(this.flushAt, options?.maxBatchSize ?? 100) | |
| this.maxQueueSize = Math.max(this.flushAt, options?.maxQueueSize ?? 1000) | |
| this.flushInterval = options?.flushInterval ?? 10000 | |
| this.preloadFeatureFlags = options?.preloadFeatureFlags ?? true | |
| // If enable is explicitly set to false we override the optout | |
| this.defaultOptIn = options?.defaultOptIn ?? true | |
| this.disableSurveys = options?.disableSurveys ?? false | |
| this._retryOptions = { | |
| retryCount: options?.fetchRetryCount ?? 3, | |
| retryDelay: options?.fetchRetryDelay ?? 3000, // 3 seconds | |
| retryCheck: isPostHogFetchError, | |
| } | |
| this.requestTimeout = options?.requestTimeout ?? 10000 // 10 seconds | |
| this.featureFlagsRequestTimeoutMs = options?.featureFlagsRequestTimeoutMs ?? 3000 // 3 seconds | |
| this.remoteConfigRequestTimeoutMs = options?.remoteConfigRequestTimeoutMs ?? 3000 // 3 seconds | |
| this.disableGeoip = options?.disableGeoip ?? true | |
| this.disabled = options?.disabled ?? false | |
| this.historicalMigration = options?.historicalMigration ?? false | |
| this.evaluationEnvironments = options?.evaluationEnvironments | |
| // Init promise allows the derived class to block calls until it is ready | |
| this._initPromise = Promise.resolve() | |
| this._isInitialized = true | |
| this.disableCompression = !isGzipSupported() || (options?.disableCompression ?? false) | |
| } |
Prompt To Fix With AI
This is a comment left during a code review. Path: packages/core/src/posthog-core-stateless.ts Line: 166:166 Comment: **syntax:** Missing property declaration for `evaluationEnvironments`. This will cause a TypeScript compilation error since the property is not declared in the class. ```suggestion // Evaluation environments configuration private evaluationEnvironments?: string[]; constructor(apiKey: string, options?: PostHogCoreOptions) { assert(apiKey, "You must pass your PostHog project's api key.") this.apiKey = apiKey this.host = removeTrailingSlash(options?.host || 'https://us.i.posthog.com') this.flushAt = options?.flushAt ? Math.max(options?.flushAt, 1) : 20 this.maxBatchSize = Math.max(this.flushAt, options?.maxBatchSize ?? 100) this.maxQueueSize = Math.max(this.flushAt, options?.maxQueueSize ?? 1000) this.flushInterval = options?.flushInterval ?? 10000 this.preloadFeatureFlags = options?.preloadFeatureFlags ?? true // If enable is explicitly set to false we override the optout this.defaultOptIn = options?.defaultOptIn ?? true this.disableSurveys = options?.disableSurveys ?? false this._retryOptions = { retryCount: options?.fetchRetryCount ?? 3, retryDelay: options?.fetchRetryDelay ?? 3000, // 3 seconds retryCheck: isPostHogFetchError, } this.requestTimeout = options?.requestTimeout ?? 10000 // 10 seconds this.featureFlagsRequestTimeoutMs = options?.featureFlagsRequestTimeoutMs ?? 3000 // 3 seconds this.remoteConfigRequestTimeoutMs = options?.remoteConfigRequestTimeoutMs ?? 3000 // 3 seconds this.disableGeoip = options?.disableGeoip ?? true this.disabled = options?.disabled ?? false this.historicalMigration = options?.historicalMigration ?? false this.evaluationEnvironments = options?.evaluationEnvironments // Init promise allows the derived class to block calls until it is ready this._initPromise = Promise.resolve() this._isInitialized = true this.disableCompression = !isGzipSupported() || (options?.disableCompression ?? false) } ``` How can I resolve this? If you propose a fix, please make it concise.| Size Change: +468 B (+0.01%) Total Size: 4.81 MB
ℹ️ View Unchanged
|
c634df2 to 78b9c93 Compare 78b9c93 to b403154 Compare
Changes
This PR implements support for evaluation environments, allowing users to specify which environment tags their SDK instance should use when evaluating feature flags.
Key changes:
['production', 'web', 'checkout'])/flagsendpoint to includeevaluation_environmentsin the request payload when configuredThis implementation follows the specification outlined in:
When configured, only feature flags that have at least one matching evaluation tag will be evaluated. Feature flags with no evaluation tags will always be evaluated for backward compatibility.
Basically, I'm doing what I did here, in response to a customer request.
This should be perfectly safe; this field is backward compatible and won't affect existing versions of the app.