@azure/monitor-opentelemetry
Version:
Azure Monitor OpenTelemetry (Node.js)
63 lines • 2.63 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 {
_azureExporter;
_azureLogRecordProcessor;
_azureBatchLogRecordProcessor;
_metricHandler;
_config;
_instrumentations;
/**
* 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() {
const logLevelEnv = process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL;
if (this._config.instrumentationOptions.bunyan?.enabled) {
this._instrumentations.push(new BunyanInstrumentation({
...this._config.instrumentationOptions.bunyan,
logSeverity: logLevelEnv ? logLevelToSeverityNumber(logLevelEnv) : undefined,
}));
}
if (this._config.instrumentationOptions.winston?.enabled) {
this._instrumentations.push(new WinstonInstrumentation({
...this._config.instrumentationOptions.winston,
logSeverity: logLevelEnv ? logLevelToSeverityNumber(logLevelEnv) : undefined,
}));
}
}
}
//# sourceMappingURL=handler.js.map