Last active
April 22, 2022 18:14
-
-
Save tore-statsig/bc759e43fd3fbac4619e5635d8ba9353 to your computer and use it in GitHub Desktop.
gcp cloud function using statsig-node server sdk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const statsig = require('statsig-node'); | |
let requestsHandled = 0; | |
const initStart = Date.now(); | |
let initEnd = 0; | |
let initialized = false; | |
const initializationPromise = statsig.initialize(process.env.sdkKey).then(() => { | |
initEnd = Date.now(); | |
initialized = true; | |
}); | |
/** | |
* Responds to any HTTP request. | |
* | |
* @param {!express:Request} req HTTP request context. | |
* @param {!express:Response} res HTTP response context. | |
*/ | |
exports.statsig = async (req, res) => { | |
const functionStart = Date.now(); | |
requestsHandled++; | |
if (!initialized) { | |
await initializationPromise; | |
} | |
const alwaysOnGateValue = await statsig.checkGate({userID: 'gcp'}, 'always_on_gate'); | |
const functionEnd = Date.now(); | |
res.status(200).send({ | |
initStart, | |
initEnd, | |
functionStart, | |
functionEnd, | |
requestsHandled, | |
initializeTime: initEnd - initStart, | |
functionTime: functionEnd - functionStart, | |
alwaysOnGateValue: alwaysOnGateValue, | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment