Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions aws-distro-opentelemetry-node-autoinstrumentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"repository": "aws-observability/aws-otel-js-instrumentation",
"scripts": {
"clean": "rimraf build/*",
"compile": "tsc -p .",
"compile:tsc": "tsc -p .",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who will run "compile:tsc" if we shift "compile" to "compile:webpack" as code compiling entry point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably won't be run unless someone wanted to see the previous package structure.

"compile:webpack": "webpack",
"compile": "npm run compile:webpack",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"create-version": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
Expand Down Expand Up @@ -93,12 +95,14 @@
"proxyquire": "^2.1.3",
"rimraf": "5.0.5",
"sinon": "15.2.0",
"ts-loader": "^9.5.2",
"ts-mocha": "10.0.0",
"typescript": "4.4.4"
"typescript": "4.4.4",
"webpack": "^5.98.0",
"webpack-cli": "^6.0.1"
},
"dependencies": {
"@opentelemetry/api": "1.9.0",
"@opentelemetry/auto-configuration-propagators": "0.3.0",
"@opentelemetry/auto-instrumentations-node": "0.50.0",
"@opentelemetry/core": "1.26.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "0.53.0",
Expand All @@ -110,7 +114,8 @@
"@opentelemetry/instrumentation-aws-sdk": "0.44.0",
"@opentelemetry/otlp-transformer": "0.53.0",
"@opentelemetry/propagator-aws-xray": "1.26.0",
"@opentelemetry/resource-detector-aws": "1.6.1",
"@opentelemetry/propagator-aws-xray-lambda": "^0.53.2",
"@opentelemetry/resource-detector-aws": "1.12.0",
"@opentelemetry/resources": "1.26.0",
"@opentelemetry/sdk-metrics": "1.26.0",
"@opentelemetry/sdk-node": "0.53.0",
Expand All @@ -119,8 +124,8 @@
},
"files": [
"build/src/**/*.js",
"build/src/**/*.js.map",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep the compile:tsc command, there's no harm in keeping "build/src/**/*.js.map".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #171

"build/src/**/*.d.ts",
"build/src/**/*.d.ts.map",
"build/src/**/*.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
// Modifications Copyright The OpenTelemetry Authors. Licensed under the Apache License 2.0 License.

import { TextMapPropagator, diag } from '@opentelemetry/api';
import { getPropagator } from '@opentelemetry/auto-configuration-propagators';
import { getResourceDetectors as getResourceDetectorsFromEnv } from '@opentelemetry/auto-instrumentations-node';
import { ENVIRONMENT, TracesSamplerValues, getEnv, getEnvWithoutDefaults } from '@opentelemetry/core';
import {
CompositePropagator,
ENVIRONMENT,
TracesSamplerValues,
getEnv,
getEnvWithoutDefaults,
W3CBaggagePropagator,
W3CTraceContextPropagator,
} from '@opentelemetry/core';
import { OTLPMetricExporter as OTLPGrpcOTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
import {
AggregationTemporalityPreference,
Expand All @@ -17,6 +24,8 @@ import { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/expo
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
import { AWSXRayIdGenerator } from '@opentelemetry/id-generator-aws-xray';
import { Instrumentation } from '@opentelemetry/instrumentation';
import { AWSXRayPropagator } from '@opentelemetry/propagator-aws-xray';
import { AWSXRayLambdaPropagator } from '@opentelemetry/propagator-aws-xray-lambda';
import { awsEc2DetectorSync, awsEcsDetectorSync, awsEksDetectorSync } from '@opentelemetry/resource-detector-aws';
import {
Detector,
Expand Down Expand Up @@ -75,6 +84,13 @@ const FORMAT_OTEL_UNSAMPLED_TRACES_BINARY_PREFIX = 'T1U';
// Follow Python SDK Impl to set the max span batch size
// which will reduce the chance of UDP package size is larger than 64KB
const LAMBDA_SPAN_EXPORT_BATCH_SIZE = 10;

const propagatorMap = new Map<string, () => TextMapPropagator>([
['tracecontext', () => new W3CTraceContextPropagator()],
['baggage', () => new W3CBaggagePropagator()],
['xray', () => new AWSXRayPropagator()],
['xray-lambda', () => new AWSXRayLambdaPropagator()],
]);
/**
* Aws Application Signals Config Provider creates a configuration object that can be provided to
* the OTel NodeJS SDK for Auto Instrumentation with Application Signals Functionality.
Expand Down Expand Up @@ -163,7 +179,7 @@ export class AwsOpentelemetryConfigurator {
this.resource = autoResource;

this.instrumentations = instrumentations;
this.propagator = getPropagator();
this.propagator = this.getPropagator();

// TODO: Consider removing AWSXRayIdGenerator as it is not needed
// Similarly to Java, always use AWS X-Ray Id Generator
Expand All @@ -190,6 +206,32 @@ export class AwsOpentelemetryConfigurator {
return autoResource;
}

private getPropagator(): TextMapPropagator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This can be a regular function outside of this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in #171

if (process.env.OTEL_PROPAGATORS == null || process.env.OTEL_PROPAGATORS.trim() === '') {
return new CompositePropagator({
Comment on lines +209 to +211
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a better option to not rewrite this function by copying it from upstream? can we just patch propagatorMap for auto-configuration-propagators/utils file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #171, we revert to using the upstream dependency

propagators: [new W3CTraceContextPropagator(), new W3CBaggagePropagator()],
});
}
const propagatorsFromEnv = Array.from(
new Set(process.env.OTEL_PROPAGATORS?.split(',').map(value => value.toLowerCase().trim()))
);
const propagators = propagatorsFromEnv.flatMap(propagatorName => {
if (propagatorName === 'none') {
diag.info(
'Not selecting any propagator for value "none" specified in the environment variable OTEL_PROPAGATORS'
);
return [];
}
const propagatorFactoryFunction = propagatorMap.get(propagatorName);
if (propagatorFactoryFunction == null) {
diag.warn(`Invalid propagator "${propagatorName}" specified in the environment variable OTEL_PROPAGATORS`);
return [];
}
return propagatorFactoryFunction();
});
return new CompositePropagator({ propagators });
}

public configure(): Partial<NodeSDKConfiguration> {
// config.autoDetectResources is set to False, as the resources are detected and added to the
// resource ahead of time. The resource is needed to be populated ahead of time instead of letting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function setAwsDefaultEnvironmentVariables(): void {
process.env.OTEL_EXPORTER_OTLP_PROTOCOL = 'http/protobuf';
}
if (!process.env.OTEL_PROPAGATORS) {
process.env.OTEL_PROPAGATORS = 'xray,tracecontext,b3,b3multi';
process.env.OTEL_PROPAGATORS = 'xray,tracecontext';
}
// Disable the following instrumentations by default
// This auto-instrumentation for the `fs` module generates many low-value spans. `dns` is similar.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ describe('AwsOpenTelemetryConfiguratorTest', () => {
function validateConfiguratorEnviron() {
// Set by register.ts
expect('http/protobuf').toEqual(process.env.OTEL_EXPORTER_OTLP_PROTOCOL);
expect('xray,tracecontext,b3,b3multi').toEqual(process.env.OTEL_PROPAGATORS);
expect('xray,tracecontext').toEqual(process.env.OTEL_PROPAGATORS);

// Not set
expect(undefined).toEqual(process.env.OTEL_TRACES_SAMPLER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { AWSXRAY_TRACE_ID_HEADER, AWSXRayPropagator } from '@opentelemetry/propa
import { Context } from 'aws-lambda';
import { SinonStub } from 'sinon';
import { S3 } from '@aws-sdk/client-s3';
import nock = require('nock');
import * as nock from 'nock';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { getTestSpans, registerInstrumentationTesting } from '@opentelemetry/contrib-test-utils';
import { AwsSdkInstrumentationExtended } from '../../src/patches/extended-instrumentations/aws-sdk-instrumentation-extended';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Register', function () {
it('sets AWS Default Environment Variables', () => {
setAwsDefaultEnvironmentVariables();
expect(process.env.OTEL_EXPORTER_OTLP_PROTOCOL).toEqual('http/protobuf');
expect(process.env.OTEL_PROPAGATORS).toEqual('xray,tracecontext,b3,b3multi');
expect(process.env.OTEL_PROPAGATORS).toEqual('xray,tracecontext');
expect(process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS).toEqual('fs');
});

Expand Down Expand Up @@ -79,7 +79,7 @@ describe('Register', function () {

assert.ok(proc.stdout.includes('AWS Distro of OpenTelemetry automatic instrumentation started successfully'));
assert.ok(proc.stdout.includes("Environment variable OTEL_EXPORTER_OTLP_PROTOCOL is set to 'http/protobuf'"));
assert.ok(proc.stdout.includes("Environment variable OTEL_PROPAGATORS is set to 'xray,tracecontext,b3,b3multi'"));
assert.ok(proc.stdout.includes("Environment variable OTEL_PROPAGATORS is set to 'xray,tracecontext'"));

// Check a span has been generated for the GET request done in app.js
assert.ok(proc.stdout.includes("name: 'GET'"), 'console span output in stdout - validate Span Name');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "es2020",
"target": "es2020",
"moduleResolution": "node",
},
Comment on lines +4 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the same target being used by otel lambda upstream?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, see here.

"exclude": [
"node_modules",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const path = require('path');

module.exports = {
entry: './src/register.ts',
target: 'node',
mode: 'production',
externalsPresets: { node: true },
output: {
path: path.resolve('./build/src'),
filename: 'register.js',
library: {
type: 'commonjs2',
}
},
resolve: {
extensions: ['.ts', '.js'],
modules: [
path.resolve('./src'),
'node_modules',
],
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
configFile: 'tsconfig.webpack.json'
},
}
],
exclude: /node_modules/,
},
],
},
optimization: {
minimize: true,
providedExports: true,
usedExports: true,
},
};
2 changes: 1 addition & 1 deletion lambda-layer/packages/layer/scripts/otel-instrument
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fi

# - Set the propagators
if [[ -z "$OTEL_PROPAGATORS" ]]; then
export OTEL_PROPAGATORS="xray,tracecontext,baggage,b3,b3multi"
export OTEL_PROPAGATORS="xray,tracecontext,baggage"
fi

# - Set Application Signals configuration
Expand Down
Loading
Loading