@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.
125 lines • 5.21 kB
JavaScript
;
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAccountId = exports.checkDigits = exports.detectConflictingInstrumentation = exports.isInstrumentationDisabled = exports.parseOtelBaggageKeysEnvVar = exports.getAwsRegionFromEnvironment = exports.isAgenticInstrumentationOptIn = exports.isAgentObservabilityEnabled = exports.getNodeVersion = exports.OTEL_BAGGAGE_SPAN_ATTRIBUTE_KEYS = void 0;
const api_1 = require("@opentelemetry/api");
const instrumentation_1 = require("./instrumentation/instrumentation-langchain/instrumentation");
const instrumentation_2 = require("./instrumentation/instrumentation-openai-agents/instrumentation");
const instrumentation_3 = require("./instrumentation/instrumentation-vercel-ai/instrumentation");
const AGENT_OBSERVABILITY_ENABLED = 'AGENT_OBSERVABILITY_ENABLED';
const AWS_AGENTIC_INSTRUMENTATION_OPT_IN = 'AWS_AGENTIC_INSTRUMENTATION_OPT_IN';
exports.OTEL_BAGGAGE_SPAN_ATTRIBUTE_KEYS = 'OTEL_BAGGAGE_SPAN_ATTRIBUTE_KEYS';
const getNodeVersion = () => {
const nodeVersion = process.versions.node;
const versionParts = nodeVersion.split('.');
if (versionParts.length === 0) {
return -1;
}
const majorVersion = parseInt(versionParts[0], 10);
if (isNaN(majorVersion)) {
return -1;
}
return majorVersion;
};
exports.getNodeVersion = getNodeVersion;
const isAgentObservabilityEnabled = () => {
const agentObservabilityEnabled = process.env[AGENT_OBSERVABILITY_ENABLED];
if (agentObservabilityEnabled === undefined) {
return false;
}
return agentObservabilityEnabled.toLowerCase() === 'true';
};
exports.isAgentObservabilityEnabled = isAgentObservabilityEnabled;
const isAgenticInstrumentationOptIn = () => {
const v = process.env[AWS_AGENTIC_INSTRUMENTATION_OPT_IN];
return v !== undefined && v.toLowerCase() === 'true';
};
exports.isAgenticInstrumentationOptIn = isAgenticInstrumentationOptIn;
/**
* Get AWS region from environment or boto3 session.
* Returns the AWS region in the following priority order:
* 1. AWS_REGION environment variable
* 2. AWS_DEFAULT_REGION environment variable
* 3. undefined if no region can be determined
*/
const getAwsRegionFromEnvironment = () => {
var _a;
const region = (_a = process.env.AWS_REGION) !== null && _a !== void 0 ? _a : process.env.AWS_DEFAULT_REGION;
if (region) {
return region;
}
api_1.diag.warn('AWS region not found in environment variables (AWS_REGION, AWS_DEFAULT_REGION). Please set AWS_REGION environment variable explicitly.');
return undefined;
};
exports.getAwsRegionFromEnvironment = getAwsRegionFromEnvironment;
const parseOtelBaggageKeysEnvVar = () => {
var _a;
const raw = (_a = process.env[exports.OTEL_BAGGAGE_SPAN_ATTRIBUTE_KEYS]) !== null && _a !== void 0 ? _a : '';
const keys = new Set();
for (const k of raw.split(',')) {
const trimmed = k.trim();
if (trimmed) {
keys.add(trimmed);
}
}
return keys;
};
exports.parseOtelBaggageKeysEnvVar = parseOtelBaggageKeysEnvVar;
const isInstrumentationDisabled = (shortName) => {
const disabledEnv = process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS;
if (disabledEnv) {
const disabled = disabledEnv.split(',').map(s => s.trim());
if (disabled.includes(shortName)) {
return true;
}
}
const enabledEnv = process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS;
if (enabledEnv) {
const enabled = enabledEnv.split(',').map(s => s.trim());
if (!enabled.includes(shortName)) {
return true;
}
}
return false;
};
exports.isInstrumentationDisabled = isInstrumentationDisabled;
const CONFLICTING_INSTRUMENTATIONS = {
[instrumentation_1.INSTRUMENTATION_SHORT_NAME]: [
'@traceloop/instrumentation-langchain',
'@arizeai/openinference-instrumentation-langchain',
'@arizeai/openinference-instrumentation-langchain-v0',
'@microsoft/agents-a365-observability-extensions-langchain',
'@langfuse/langchain',
],
[instrumentation_2.INSTRUMENTATION_SHORT_NAME]: [
'@respan/instrumentation-openai-agents',
'@microsoft/agents-a365-observability-extensions-openai',
],
[instrumentation_3.INSTRUMENTATION_SHORT_NAME]: ['@monocle.sh/instrumentation-vercel-ai', '@respan/instrumentation-vercel'],
};
const detectConflictingInstrumentation = (shortName) => {
const conflicts = CONFLICTING_INSTRUMENTATIONS[shortName];
if (!conflicts)
return undefined;
for (const pkg of conflicts) {
try {
require.resolve(pkg);
return pkg;
}
catch (_a) {
continue;
}
}
return undefined;
};
exports.detectConflictingInstrumentation = detectConflictingInstrumentation;
const checkDigits = (str) => {
return /^\d+$/.test(str);
};
exports.checkDigits = checkDigits;
const isAccountId = (input) => {
return input != null && (0, exports.checkDigits)(input);
};
exports.isAccountId = isAccountId;
//# sourceMappingURL=utils.js.map