in packages/opentelemetry-cloud-monitoring-exporter/src/monitoring.ts [240:267]
private async _createMetricDescriptorIfNeeded(
metric: MetricData
): Promise<boolean> {
const authClient = await this._authorize();
const descriptor = transformMetricDescriptor(metric, this._metricPrefix);
const projectIdPath = mountProjectIdPath(this._projectId as string);
try {
const descriptorExists = await this._checkIfDescriptorExists(
descriptor,
projectIdPath,
authClient
);
if (!descriptorExists) {
await this._monitoring.projects.metricDescriptors.create({
name: projectIdPath,
requestBody: descriptor,
auth: authClient,
});
diag.debug('sent metric descriptor', descriptor);
}
return true;
} catch (e) {
const err = asError(e);
diag.error('Failed to create metric descriptor: %s', err.message);
return false;
}
}