You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
If possible, provide a recipe for reproducing the error.
Have code that looks like this inside a Google Cloud Function:
functions.cloudEvent('lg-stock-check', async () => {
// Omitted code...
const exporter = new StackdriverStatsExporter({
projectId: projectId,
period: 60 * 1000,
onMetricUploadError: (err) => {
log.error(log.entry({err: err}, "Error uploading metrics: " + err));
},
});
globalStats.registerExporter(exporter);
// Omitted code...
await logMetricsFunction(); // Log out some metrics here.
await exporter.export();
// This is horrible, but the exporter calls:
// https://github.com/census-instrumentation/opencensus-node/blob/04ae44cf8875c59b99ea65ed2135b6bc816b49b4/packages/opencensus-exporter-stackdriver/src/stackdriver-monitoring.ts#L182
// Which is an async function we cannot get the promise for.
// So sleeping a bit to try and let it finish.
await sleep(30000); // This still doesn't help.
exporter.stop();
globalStats.unregisterExporter(exporter);
} catch (err) {
console.error("Error: " + err);
}
});
What did you expect to see?
I expected the metrics to get uploaded.
What did you see instead?
The metrics do not get uploaded. They only upload if I run the function locally on my laptop.
Additional context
I suspect this is because of the function getting torn down before the Promise chains here can return:
So I'm wondering what is the recommendation to fix this? Can we have a synchronous way to ensure metrics are written out BEFORE the GCP Function returns?
Happy to make changes with guidance.
The text was updated successfully, but these errors were encountered:
What version of OpenCensus are you using?
0.1.0
What version of Node are you using?
18.7.0
What did you do?
If possible, provide a recipe for reproducing the error.
Have code that looks like this inside a Google Cloud Function:
What did you expect to see?
I expected the metrics to get uploaded.
What did you see instead?
The metrics do not get uploaded. They only upload if I run the function locally on my laptop.
Additional context
I suspect this is because of the function getting torn down before the Promise chains here can return:
opencensus-node/packages/opencensus-exporter-stackdriver/src/stackdriver-monitoring.ts
Line 195 in 04ae44c
I attempted to work around this by calling
export()
manually and thensleeping
a bunch, but this doesn't work either, and it is a total hack.Export calls
createTimeSeries
, but it does not return the Promise thatcreateTimeSeries
returns, so there's no way for anyone to wait on them:opencensus-node/packages/opencensus-exporter-stackdriver/src/stackdriver-monitoring.ts
Line 137 in 04ae44c
So I'm wondering what is the recommendation to fix this? Can we have a synchronous way to ensure metrics are written out BEFORE the GCP Function returns?
Happy to make changes with guidance.
The text was updated successfully, but these errors were encountered: