@azure/monitor-opentelemetry
Version:
Azure Monitor OpenTelemetry (Node.js)
56 lines • 2.89 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.LogHandler = void 0;
const monitor_opentelemetry_exporter_1 = require("@azure/monitor-opentelemetry-exporter");
const instrumentation_bunyan_1 = require("@opentelemetry/instrumentation-bunyan");
const instrumentation_winston_1 = require("@opentelemetry/instrumentation-winston");
const logRecordProcessor_js_1 = require("./logRecordProcessor.js");
const batchLogRecordProcessor_js_1 = require("./batchLogRecordProcessor.js");
const logUtils_js_1 = require("../utils/logUtils.js");
/**
* Azure Monitor OpenTelemetry Log Handler
*/
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 monitor_opentelemetry_exporter_1.AzureMonitorLogExporter(config.azureMonitorExporterOptions);
this._azureBatchLogRecordProcessor = new batchLogRecordProcessor_js_1.AzureBatchLogRecordProcessor(this._azureExporter, {
enableTraceBasedSamplingForLogs: this._config.enableTraceBasedSamplingForLogs,
});
this._azureLogRecordProcessor = new logRecordProcessor_js_1.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 instrumentation_bunyan_1.BunyanInstrumentation(Object.assign(Object.assign({}, this._config.instrumentationOptions.bunyan), { logSeverity: logLevelEnv ? (0, logUtils_js_1.logLevelToSeverityNumber)(logLevelEnv) : undefined })));
}
if ((_b = this._config.instrumentationOptions.winston) === null || _b === void 0 ? void 0 : _b.enabled) {
this._instrumentations.push(new instrumentation_winston_1.WinstonInstrumentation(Object.assign(Object.assign({}, this._config.instrumentationOptions.winston), { logSeverity: logLevelEnv ? (0, logUtils_js_1.logLevelToSeverityNumber)(logLevelEnv) : undefined })));
}
}
}
exports.LogHandler = LogHandler;
//# sourceMappingURL=handler.js.map
;