@aws/aws-distro-opentelemetry-node-autoinstrumentation
Version:
This package provides Amazon Web Services distribution of the OpenTelemetry Node Instrumentation, which allows for auto-instrumentation of NodeJS applications.
63 lines • 3.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OTLPAwsSpanExporter = void 0;
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
const exporter_trace_otlp_proto_1 = require("@opentelemetry/exporter-trace-otlp-proto");
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
const otlp_transformer_1 = require("@opentelemetry/otlp-transformer");
const otlp_aws_base_exporter_1 = require("../common/otlp-aws-base-exporter");
const llo_handler_1 = require("../../../../llo-handler");
const api_logs_1 = require("@opentelemetry/api-logs");
const utils_1 = require("../../../../utils");
const api_1 = require("@opentelemetry/api");
const sdk_logs_1 = require("@opentelemetry/sdk-logs");
/**
* This exporter extends the functionality of the OTLPProtoTraceExporter to allow spans to be exported
* to the XRay OTLP endpoint https://xray.[AWSRegion].amazonaws.com/v1/traces. Utilizes the aws-sdk
* library to sign and directly inject SigV4 Authentication to the exported request's headers. <a
* href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-OTLPEndpoint.html">...</a>
*
* This only works with version >=16 Node.js environments.
*
* @param endpoint - The AWS X-Ray OTLP endpoint URL
* @param config - Optional OTLP exporter configuration
*/
class OTLPAwsSpanExporter extends otlp_aws_base_exporter_1.OTLPAwsBaseExporter {
constructor(endpoint, config, loggerProvider) {
const modifiedConfig = Object.assign(Object.assign({}, config), { url: endpoint, compression: otlp_exporter_base_1.CompressionAlgorithm.NONE });
super(endpoint, 'xray', new exporter_trace_otlp_proto_1.OTLPTraceExporter(modifiedConfig), otlp_transformer_1.ProtobufTraceSerializer, config === null || config === void 0 ? void 0 : config.compression);
this.lloHandler = undefined;
this.loggerProvider = loggerProvider;
}
// Lazily initialize LLO handler when needed to avoid initialization order issues
ensureLloHandler() {
if (!this.lloHandler && (0, utils_1.isAgentObservabilityEnabled)()) {
// If loggerProvider wasn't provided, try to get the current one
if (!this.loggerProvider) {
try {
this.loggerProvider = api_logs_1.logs.getLoggerProvider();
}
catch (e) {
api_1.diag.debug('Failed to get logger provider', e);
return false;
}
}
if (this.loggerProvider instanceof sdk_logs_1.LoggerProvider) {
this.lloHandler = new llo_handler_1.LLOHandler(this.loggerProvider);
return true;
}
}
return !!this.lloHandler;
}
async export(items, resultCallback) {
let itemsToSerialize = items;
if ((0, utils_1.isAgentObservabilityEnabled)() && this.ensureLloHandler() && this.lloHandler) {
// items to serialize are now the lloProcessedSpans
itemsToSerialize = this.lloHandler.processSpans(items);
}
return super.export(itemsToSerialize, resultCallback);
}
}
exports.OTLPAwsSpanExporter = OTLPAwsSpanExporter;
//# sourceMappingURL=otlp-aws-span-exporter.js.map