Skip to content

Commit 640616a

Browse files
committed
Rename unsampled span attribute name and optimize layer pkg json to reduce dependency size
1 parent 5e967ac commit 640616a

File tree

8 files changed

+89
-24
lines changed

8 files changed

+89
-24
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/aws-attribute-keys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const AWS_ATTRIBUTE_KEYS: { [key: string]: string } = {
2222
AWS_IS_LOCAL_ROOT: 'aws.is.local.root',
2323

2424
// Trace Span Unsampled flag
25-
AWS_TRACE_FLAG_UNSAMPLED: 'aws.trace.flag.unsampled',
25+
AWS_TRACE_FLAG_SAMPLED: 'aws.trace.flag.sampled',
2626

2727
// AWS_#_NAME attributes are not supported in JavaScript as they are not part of the Semantic Conventions.
2828
// TODO:Move to Semantic Conventions when these attributes are added.

aws-distro-opentelemetry-node-autoinstrumentation/src/aws-batch-unsampled-span-processor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { BatchSpanProcessorBase } from '@opentelemetry/sdk-trace-base/build/src/
2020
* In particular, the following methods are modified:
2121
*
2222
* 1. `onStart`: This method is modified to detect unsampled spans and add an
23-
* AWS-specific attribute (`AWS_TRACE_FLAG_UNSAMPLED`) to denote that the span
23+
* AWS-specific attribute (`AWS_TRACE_FLAG_SAMPLED`) to denote that the span
2424
* is unsampled. This is done by checking the `traceFlags` of the span.
2525
*
2626
* 2. `onEnd`: The logic here is changed to handle unsampled spans. While the
@@ -37,7 +37,7 @@ import { BatchSpanProcessorBase } from '@opentelemetry/sdk-trace-base/build/src/
3737
export class AwsBatchUnsampledSpanProcessor extends BatchSpanProcessorBase<BufferConfig> {
3838
override onStart(span: Span, _parentContext: Context): void {
3939
if ((span.spanContext().traceFlags & TraceFlags.SAMPLED) === 0) {
40-
span.setAttribute(AWS_ATTRIBUTE_KEYS.AWS_TRACE_FLAG_UNSAMPLED, true);
40+
span.setAttribute(AWS_ATTRIBUTE_KEYS.AWS_TRACE_FLAG_SAMPLED, false);
4141
return;
4242
}
4343
}

aws-distro-opentelemetry-node-autoinstrumentation/test/aws-batch-unsampled-span-processor.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { Resource, ResourceAttributes } from '@opentelemetry/resources';
1919
import { AwsBatchUnsampledSpanProcessor } from '../src/aws-batch-unsampled-span-processor';
2020
import { AlwaysRecordSampler } from '../src/always-record-sampler';
21+
import { AWS_ATTRIBUTE_KEYS } from '../src/aws-attribute-keys';
2122

2223
/**
2324
* This test file is a modified version of `BatchSpanProcessorBase.test.ts`.
@@ -131,6 +132,7 @@ describe('AwsBatchUnsampledSpanProcessor', () => {
131132

132133
processor.onStart(span, ROOT_CONTEXT);
133134
processor.onEnd(span);
135+
assert.strictEqual(span.attributes[AWS_ATTRIBUTE_KEYS.AWS_TRACE_FLAG_SAMPLED], false);
134136

135137
await processor.forceFlush();
136138
// _finishedSpans should be empty after forceFlush

lambda-layer/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# AWS Distro Lambda Layer for NodeJS
22

3-
This package includes the following three components
3+
By default, the layer enables aws-sdk and aws-lambda instrumentation libraries only for better Lambda cold start
4+
performance.
5+
You can use the environment variable `OTEL_NODE_ENABLED_INSTRUMENTATIONS` to enable only certain
6+
instrumentations, OR the environment variable `OTEL_NODE_DISABLED_INSTRUMENTATIONS` to disable only
7+
certain instrumentations, by providing a comma-separated list of the instrumentation
8+
package names without the @opentelemetry/instrumentation- prefix.
9+
Eg, OTEL_NODE_ENABLED_INSTRUMENTATIONS="aws-lambda,aws-sdk,http"
10+
11+
This package includes the following three components,
412

513
1. AWS Lambda Layer implementation for supporting Application Signals in AWS Lambda.
614
2. Lambda Sample App with AWS SDK to demonstrate Application Signals telemetry data generated by Lambda Layer.
@@ -35,5 +43,4 @@ The lambda function(`aws-opentelemetry-distro-nodejs`) will be initialized and t
3543
will be displayed at the end. Send a request to the URL in a browser or using curl to execute the function. Then,
3644
navigate to Lambda function's Monitoring page.
3745
You will see a log stream with an event time and Traces data corresponding to when you issued the request,
38-
open it and you can find
39-
information about the exported spans in the log stream.
46+
open it and you can find information about the exported spans in the log stream.

lambda-layer/build.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@ cd "${SOURCEDIR}/.."
1010

1111
# Install dependencies and compile all projects in the repository
1212
echo "Installing dependencies and compiling projects..."
13+
rm -rf node_modules
1314
rm -rf ./aws-distro-opentelemetry-node-autoinstrumentation/build
1415
rm -rf ./aws-distro-opentelemetry-node-autoinstrumentation/node_modules
1516
npm install
16-
npm run compile
17+
npm run compile || exit
18+
19+
# Build aws distro tar file
20+
cd aws-distro-opentelemetry-node-autoinstrumentation || exit
21+
rm aws-aws-distro-opentelemetry-node-autoinstrumentation-*.tgz
22+
npm pack || exit
23+
24+
# Install Lambda Layer Build Tool
25+
cd ${SOURCEDIR}/packages || exit
26+
rm -rf build
27+
rm -rf node_modules
28+
npm install || exit
1729

1830
# Build Lambda SDK layer
1931
cd ${SOURCEDIR}/packages/layer || exit

lambda-layer/package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "@aws/aws-distro-opentelemetry-node-autoinstrumentatio-sdk-layer",
3+
"version": "0.0.1",
4+
"description": "Lambda Layer including AWS Distro OpenTelemetry SDK for supporting Amazon Application Signals",
5+
"repository": "aws-observability/aws-otel-js-instrumentation",
6+
"author": {
7+
"name": "Amazon Web Services",
8+
"url": "http://aws.amazon.com"
9+
},
10+
"homepage": "https://github.com/aws-observability/aws-otel-js-instrumentation/tree/main/aws-distro-opentelemetry-node-autoinstrumentation#readme",
11+
"license": "Apache-2.0",
12+
"engines": {
13+
"node": ">=16"
14+
},
15+
"publishConfig": {
16+
"access": "public"
17+
},
18+
"scripts": {
19+
"clean": "rimraf build/*",
20+
"lint": "eslint . --ext .ts",
21+
"lint:fix": "eslint . --ext .ts --fix"
22+
},
23+
"keywords": [
24+
"awsdistroopentelemetry",
25+
"opentelemetry",
26+
"awslambda",
27+
"nodejs",
28+
"tracing",
29+
"profiling",
30+
"instrumentation"
31+
],
32+
"devDependencies": {
33+
"copyfiles": "^2.4.1",
34+
"bestzip": "2.2.0"
35+
}
36+
}

lambda-layer/packages/layer/package.json

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,24 @@
3333
"instrumentation"
3434
],
3535
"dependencies": {
36-
"@aws/aws-distro-opentelemetry-node-autoinstrumentation": "file:../../../aws-distro-opentelemetry-node-autoinstrumentation",
37-
"@opentelemetry/api": "1.9.0",
38-
"@opentelemetry/auto-instrumentations-node": "0.48.0",
39-
"@opentelemetry/auto-configuration-propagators": "0.2.0",
40-
"@opentelemetry/exporter-metrics-otlp-grpc": "0.52.1",
41-
"@opentelemetry/exporter-metrics-otlp-http": "0.52.1",
42-
"@opentelemetry/instrumentation": "0.52.1",
43-
"@opentelemetry/id-generator-aws-xray": "1.2.2",
44-
"@opentelemetry/propagator-aws-xray": "1.25.1",
45-
"@opentelemetry/core": "1.25.1",
46-
"@opentelemetry/sdk-trace-base": "1.25.1",
47-
"@opentelemetry/semantic-conventions": "1.25.1",
48-
"@opentelemetry/resources": "1.25.1",
49-
"@opentelemetry/exporter-trace-otlp-proto": "0.52.1",
50-
"@opentelemetry/exporter-zipkin": "1.25.1",
51-
"@opentelemetry/sdk-metrics": "1.25.1"
36+
"@aws/aws-distro-opentelemetry-node-autoinstrumentation": "file:../../../aws-distro-opentelemetry-node-autoinstrumentation/aws-aws-distro-opentelemetry-node-autoinstrumentation-0.1.0-dev0.tgz",
37+
"@opentelemetry/propagator-b3": "1.25.1",
38+
"@opentelemetry/propagator-jaeger": "1.25.1",
39+
"@opentelemetry/resource-detector-azure": "0.2.10",
40+
"@opentelemetry/resource-detector-gcp": "0.29.10",
41+
"@opentelemetry/semantic-conventions": "1.25.1"
42+
},
43+
"overrides": {
44+
"@aws/aws-distro-opentelemetry-node-autoinstrumentation": {
45+
"@opentelemetry/auto-configuration-propagators": {
46+
"@opentelemetry/propagators-b3": "1.25.1"
47+
},
48+
"@opentelemetry/resource-detector-azure": {
49+
"@opentelemetry/semantic-conventions": "1.25.1"
50+
},
51+
"@opentelemetry/resource-detector-gcp": {
52+
"@opentelemetry/semantic-conventions": "1.25.1"
53+
}
54+
}
5255
}
5356
}

lambda-layer/packages/layer/scripts/otel-instrument

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#!/bin/bash
22
export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js"
33
export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=$AWS_REGION,cloud.provider=aws,faas.name=$AWS_LAMBDA_FUNCTION_NAME,faas.version=$AWS_LAMBDA_FUNCTION_VERSION,faas.instance=$AWS_LAMBDA_LOG_STREAM_NAME,aws.log.group.names=$AWS_LAMBDA_LOG_GROUP_NAME";
4-
export OTEL_NODE_ENABLED_INSTRUMENTATIONS="aws-lambda,aws-sdk"
4+
55

66
# - If OTEL_EXPORTER_OTLP_PROTOCOL is not set by user, the default exporting protocol is http/protobuf.
77
if [ -z "${OTEL_EXPORTER_OTLP_PROTOCOL}" ]; then
88
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
99
fi
1010

11+
# - If OTEL_NODE_ENABLED_INSTRUMENTATIONS is not set by user, use default instrumentation
12+
if [ -z "${OTEL_NODE_ENABLED_INSTRUMENTATIONS}" ]; then
13+
export OTEL_NODE_ENABLED_INSTRUMENTATIONS="aws-lambda,aws-sdk"
14+
fi
15+
1116
# - Set the service name
1217
if [ -z "${OTEL_SERVICE_NAME}" ]; then
1318
export OTEL_SERVICE_NAME=$AWS_LAMBDA_FUNCTION_NAME;

0 commit comments

Comments
 (0)