@azure/monitor-opentelemetry
Version:
Azure Monitor OpenTelemetry (Node.js)
52 lines • 2.57 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { AzureMonitorLogExporter } from "@azure/monitor-opentelemetry-exporter";
import { BunyanInstrumentation } from "@opentelemetry/instrumentation-bunyan";
import { WinstonInstrumentation } from "@opentelemetry/instrumentation-winston";
import { AzureLogRecordProcessor } from "./logRecordProcessor.js";
import { AzureBatchLogRecordProcessor } from "./batchLogRecordProcessor.js";
import { logLevelToSeverityNumber } from "../utils/logUtils.js";
/**
* Azure Monitor OpenTelemetry Log Handler
*/
export class LogHandler {
/**
* Initializes a new instance of the TraceHandler class.
* @param _config - Distro configuration.
* @param _metricHandler - MetricHandler.
*/
constructor(config, metricHandler) {
this._config = config;
this._metricHandler = metricHandler;
this._azureExporter = new AzureMonitorLogExporter(config.azureMonitorExporterOptions);
this._azureBatchLogRecordProcessor = new AzureBatchLogRecordProcessor(this._azureExporter, {
enableTraceBasedSamplingForLogs: this._config.enableTraceBasedSamplingForLogs,
});
this._azureLogRecordProcessor = new AzureLogRecordProcessor(this._metricHandler);
this._instrumentations = [];
this._initializeInstrumentations();
}
getAzureLogRecordProcessor() {
return this._azureLogRecordProcessor;
}
getBatchLogRecordProcessor() {
return this._azureBatchLogRecordProcessor;
}
getInstrumentations() {
return this._instrumentations;
}
/**
* Start auto collection of telemetry
*/
_initializeInstrumentations() {
var _a, _b;
const logLevelEnv = process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL;
if ((_a = this._config.instrumentationOptions.bunyan) === null || _a === void 0 ? void 0 : _a.enabled) {
this._instrumentations.push(new BunyanInstrumentation(Object.assign(Object.assign({}, this._config.instrumentationOptions.bunyan), { logSeverity: logLevelEnv ? logLevelToSeverityNumber(logLevelEnv) : undefined })));
}
if ((_b = this._config.instrumentationOptions.winston) === null || _b === void 0 ? void 0 : _b.enabled) {
this._instrumentations.push(new WinstonInstrumentation(Object.assign(Object.assign({}, this._config.instrumentationOptions.winston), { logSeverity: logLevelEnv ? logLevelToSeverityNumber(logLevelEnv) : undefined })));
}
}
}
//# sourceMappingURL=handler.js.map