UNPKG

@azure/monitor-opentelemetry

Version:
63 lines 2.13 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.AzureLogRecordProcessor = void 0; const api_1 = require("@opentelemetry/api"); const index_js_1 = require("../shared/logging/index.js"); const genaiAttributes_js_1 = require("../utils/genaiAttributes.js"); /** * Azure Monitor LogRecord Processor. * @internal */ class AzureLogRecordProcessor { _metricHandler; constructor(metricHandler) { this._metricHandler = metricHandler; } onEmit(logRecord, context) { try { this._propagateMainAgentAttributesFromActiveSpan(logRecord, context); } catch (error) { index_js_1.Logger.getInstance().warn("Error while propagating main agent attributes onEmit", error); } try { this._metricHandler.recordLog(logRecord); } catch (error) { index_js_1.Logger.getInstance().warn("Error while recording log", error); } } _propagateMainAgentAttributesFromActiveSpan(logRecord, context) { if (!context) { return; } const span = api_1.trace.getSpan(context); if (!span) { return; } // The Span returned by trace.getSpan may be a non-recording span or a // foreign implementation that does not expose `attributes`. const spanAttributes = span.attributes; if (!spanAttributes) { return; } // Copy only the spec-defined main-agent attributes rather than scanning // every attribute on the span by prefix. for (const key of genaiAttributes_js_1.MAIN_AGENT_TARGET_ATTRIBUTES) { const value = spanAttributes[key]; if (value !== undefined) { logRecord.setAttribute(key, value); } } } forceFlush() { return Promise.resolve(); } shutdown() { return Promise.resolve(); } } exports.AzureLogRecordProcessor = AzureLogRecordProcessor; //# sourceMappingURL=logRecordProcessor.js.map