Skip to content
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

feat: support running without a STATSIG_API_KEY #6403

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jeanregisser
Copy link
Member

Description

As the title says.

Before this, running the app without a STATSIG_API_KEY was throwing a bunch of errors. And crashing in dev mode in the settings.
See mobilestack-xyz#2 (comment)

Test plan

  • Tests pass

Related issues

Backwards compatibility

Yes

Network scalability

If a new NetworkId and/or Network are added in the future, the changes in this PR will:

  • Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)

// dummy key as fallback for e2e tests, which use local mode
'client-key'
export const STATSIG_API_KEY = keyOrUndefined(secretsFile, DEFAULT_TESTNET, 'STATSIG_API_KEY')
export const STATSIG_ENABLED = !isE2EEnv && !!STATSIG_API_KEY
Copy link
Member Author

Choose a reason for hiding this comment

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

Kept isE2EEnv here as when running locally, the secrets are decrypted, but we should still keep statsig disabled.

I think with the move to the runtime we'll update "secrets" management and will just use env variables. So this special case of e2e env will not be needed anymore.

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 94.44444% with 3 lines in your changes missing coverage. Please review.

Project coverage is 89.12%. Comparing base (f284f7c) to head (ad0c04e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/analytics/AppAnalytics.ts 89.65% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6403      +/-   ##
==========================================
+ Coverage   89.09%   89.12%   +0.02%     
==========================================
  Files         736      737       +1     
  Lines       31840    31897      +57     
  Branches     6040     5750     -290     
==========================================
+ Hits        28367    28427      +60     
+ Misses       3425     3422       -3     
  Partials       48       48              
Files with missing lines Coverage Δ
src/config.ts 96.26% <100.00%> (-0.07%) ⬇️
src/navigator/SettingsMenu.tsx 94.94% <100.00%> (+0.05%) ⬆️
src/statsig/index.ts 98.93% <100.00%> (+0.20%) ⬆️
src/analytics/AppAnalytics.ts 70.18% <89.65%> (+2.26%) ⬆️

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f284f7c...ad0c04e. Read the comment docs.

// StableID should match Segment anonymousId
overrideStableID,
environment: STATSIG_ENV,
localMode: isE2EEnv,
Copy link
Contributor

@satish-ravi satish-ravi Jan 10, 2025

Choose a reason for hiding this comment

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

Should we just initialize the statsig client in local mode if statsig is disabled? That way we can avoid the custom gate overrides code too. And we can avoid the noisy logs by tweaking the logging condition.

Also, it seems like for statsig to be enabled, we'll need the segment key too because of the stable id dependency. Wonder if we should remove that dependency. We can probably let statsig set it's own anonymous id in cases where segment is not enabled.

Copy link
Member Author

@jeanregisser jeanregisser Jan 10, 2025

Choose a reason for hiding this comment

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

ah I didn't know about the localMode option.
However my intention is to be able to run even if the statsig lib is not installed. So the approach here of not instantiating the client is preferrable I think. We're planning to make 3rd party deps like segment, clevertap, etc optional in the modular runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, it seems like for statsig to be enabled, we'll need the segment key too because of the stable id dependency. Wonder if we should remove that dependency. We can probably let statsig set it's own anonymous id in cases where segment is not enabled.

Yes I thought about that, and was on the fence whether to make that change now.
I'm not sure if we'll need statsig enabled without segment.
To run experiments we need segment to be connected to statsig, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense re running without installing those libraries.
For experiments, yes segment is needed but it doesn't need to be. Metrics can potentially go to statsig directly without segment. Also, maybe there's a case where statsig is just needed for dynamic config. But I guess we could do that separately.

should we just drop the localMode option now that it is always going to be false?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes definitely I'll remove it.

// StableID should match Segment anonymousId
overrideStableID,
environment: STATSIG_ENV,
localMode: isE2EEnv,
Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense re running without installing those libraries.
For experiments, yes segment is needed but it doesn't need to be. Metrics can potentially go to statsig directly without segment. Also, maybe there's a case where statsig is just needed for dynamic config. But I guess we could do that separately.

should we just drop the localMode option now that it is always going to be false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants