@azure/monitor-opentelemetry
Version:
Azure Monitor OpenTelemetry (Node.js)
101 lines • 3.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuickpulseMetricExporter = void 0;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
const api_1 = require("@opentelemetry/api");
const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
const core_1 = require("@opentelemetry/core");
const sender_js_1 = require("./sender.js");
const utils_js_1 = require("../utils.js");
/**
* Quickpulse Metric Exporter.
*/
class QuickpulseMetricExporter {
sender;
postCallback;
getDocumentsFn;
// Monitoring data point with common properties
baseMonitoringDataPoint;
etag;
getErrorsFn;
getDerivedMetricValuesFn;
/**
* Initializes a new instance of the AzureMonitorMetricExporter class.
* @param AzureExporterConfig - Exporter configuration.
*/
constructor(options) {
this.sender = new sender_js_1.QuickpulseSender({
endpointUrl: options.endpointUrl,
instrumentationKey: options.instrumentationKey,
credential: options.credential,
credentialScopes: options.credentialScopes,
});
this.postCallback = options.postCallback;
this.getDocumentsFn = options.getDocumentsFn;
this.baseMonitoringDataPoint = options.baseMonitoringDataPoint;
this.getErrorsFn = options.getErrorsFn;
this.etag = "";
this.getDerivedMetricValuesFn = options.getDerivedMetricValuesFn;
api_1.diag.debug("QuickpulseMetricExporter was successfully setup");
}
/**
* Export OpenTelemetry resource metrics.
* @param metrics - Resource metrics to export.
* @param resultCallback - Result callback.
*/
// eslint-disable-next-line @typescript-eslint/no-misused-promises
async export(metrics, resultCallback) {
api_1.diag.info(`Exporting Live metrics(s). Converting to envelopes...`);
const optionalParams = {
monitoringDataPoints: (0, utils_js_1.resourceMetricsToQuickpulseDataPoint)(metrics, this.baseMonitoringDataPoint, this.getDocumentsFn(), this.getErrorsFn(), this.getDerivedMetricValuesFn()),
transmissionTime: (0, utils_js_1.getTransmissionTime)(),
configurationEtag: this.etag,
};
// Supress tracing until OpenTelemetry Metrics SDK support it
await api_1.context.with((0, core_1.suppressTracing)(api_1.context.active()), async () => {
try {
this.postCallback(await this.sender.publish(optionalParams));
resultCallback({ code: core_1.ExportResultCode.SUCCESS });
}
catch (error) {
this.postCallback(undefined);
resultCallback({ code: core_1.ExportResultCode.FAILED });
}
});
}
/**
* Shutdown Exporter.
*/
async shutdown() {
api_1.diag.info("QuickpulseMetricExporter shutting down");
return Promise.resolve();
}
/**
* Select aggregation temporality
*/
selectAggregationTemporality(instrumentType) {
if (instrumentType === sdk_metrics_1.InstrumentType.UP_DOWN_COUNTER ||
instrumentType === sdk_metrics_1.InstrumentType.OBSERVABLE_UP_DOWN_COUNTER) {
return sdk_metrics_1.AggregationTemporality.CUMULATIVE;
}
return sdk_metrics_1.AggregationTemporality.DELTA;
}
/**
* Force flush
*/
async forceFlush() {
return Promise.resolve();
}
/**
* Get Sender
*/
getSender() {
return this.sender;
}
setEtag(etag) {
this.etag = etag;
}
}
exports.QuickpulseMetricExporter = QuickpulseMetricExporter;
//# sourceMappingURL=exporter.js.map