in src/package-sources/npmjs/canary/npmjs-package-canary.lambda.ts [73:114]
await metricScope((metrics) => async () => {
// Clear out default dimensions as we don't need those. See https://github.com/awslabs/aws-embedded-metrics-node/issues/73.
metrics.setDimensions();
metrics.setProperty('PackageName', packageName);
metrics.setProperty('PackageVersion', versionState.version);
metrics.setProperty('IsLatest', state.latest.version === versionState.version);
if (!versionState.availableAt) {
if (versionState.version === state.latest.version) {
if (await constructHub.isInCatalog(packageName, versionState.version)) {
versionState.availableAt = new Date();
}
} else {
// Non-current versions will probably never make it to catalog (they're older than the
// current version), so instead, we check whether they have TypeScript documentation.
if (await constructHub.hasTypeScriptDocumentation(packageName, versionState.version)) {
versionState.availableAt = new Date();
}
}
}
if (versionState.availableAt) {
// Tells us how long it's taken for the package to make it to catalog after it was published.
metrics.putMetric(
MetricName.TIME_TO_CATALOG,
(versionState.availableAt.getTime() - versionState.publishedAt.getTime()) / 1_000,
Unit.Seconds,
);
// Stop tracking that version, as it's now available.
if (versionState.version in state.pending) {
delete state.pending[versionState.version];
}
} else {
// Tells us how long we've been waiting for this version to show up, so far.
metrics.putMetric(
MetricName.DWELL_TIME,
(Date.now() - versionState.publishedAt.getTime()) / 1_000,
Unit.Seconds,
);
}
})();