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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const AWS_ATTRIBUTE_KEYS: { [key: string]: string } = {
AWS_IS_LOCAL_ROOT: 'aws.is.local.root',

// Trace Span Unsampled flag
AWS_TRACE_FLAG_UNSAMPLED: 'aws.trace.flag.unsampled',
AWS_TRACE_FLAG_SAMPLED: 'aws.trace.flag.sampled',

// AWS_#_NAME attributes are not supported in JavaScript as they are not part of the Semantic Conventions.
// TODO:Move to Semantic Conventions when these attributes are added.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { BatchSpanProcessorBase } from '@opentelemetry/sdk-trace-base/build/src/
* In particular, the following methods are modified:
*
* 1. `onStart`: This method is modified to detect unsampled spans and add an
* AWS-specific attribute (`AWS_TRACE_FLAG_UNSAMPLED`) to denote that the span
* AWS-specific attribute (`AWS_TRACE_FLAG_SAMPLED`) to denote that the span
* is unsampled. This is done by checking the `traceFlags` of the span.
*
* 2. `onEnd`: The logic here is changed to handle unsampled spans. While the
Expand All @@ -37,7 +37,7 @@ import { BatchSpanProcessorBase } from '@opentelemetry/sdk-trace-base/build/src/
export class AwsBatchUnsampledSpanProcessor extends BatchSpanProcessorBase<BufferConfig> {
override onStart(span: Span, _parentContext: Context): void {
if ((span.spanContext().traceFlags & TraceFlags.SAMPLED) === 0) {
span.setAttribute(AWS_ATTRIBUTE_KEYS.AWS_TRACE_FLAG_UNSAMPLED, true);
span.setAttribute(AWS_ATTRIBUTE_KEYS.AWS_TRACE_FLAG_SAMPLED, false);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { Resource, ResourceAttributes } from '@opentelemetry/resources';
import { AwsBatchUnsampledSpanProcessor } from '../src/aws-batch-unsampled-span-processor';
import { AlwaysRecordSampler } from '../src/always-record-sampler';
import { AWS_ATTRIBUTE_KEYS } from '../src/aws-attribute-keys';

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

processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
assert.strictEqual(span.attributes[AWS_ATTRIBUTE_KEYS.AWS_TRACE_FLAG_SAMPLED], false);

await processor.forceFlush();
// _finishedSpans should be empty after forceFlush
Expand Down
13 changes: 10 additions & 3 deletions lambda-layer/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# AWS Distro Lambda Layer for NodeJS

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

This package includes the following three components,

1. AWS Lambda Layer implementation for supporting Application Signals in AWS Lambda.
2. Lambda Sample App with AWS SDK to demonstrate Application Signals telemetry data generated by Lambda Layer.
Expand Down Expand Up @@ -35,5 +43,4 @@ The lambda function(`aws-opentelemetry-distro-nodejs`) will be initialized and t
will be displayed at the end. Send a request to the URL in a browser or using curl to execute the function. Then,
navigate to Lambda function's Monitoring page.
You will see a log stream with an event time and Traces data corresponding to when you issued the request,
open it and you can find
information about the exported spans in the log stream.
open it and you can find information about the exported spans in the log stream.
14 changes: 13 additions & 1 deletion lambda-layer/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ cd "${SOURCEDIR}/.."

# Install dependencies and compile all projects in the repository
echo "Installing dependencies and compiling projects..."
rm -rf node_modules
rm -rf ./aws-distro-opentelemetry-node-autoinstrumentation/build
rm -rf ./aws-distro-opentelemetry-node-autoinstrumentation/node_modules
npm install
npm run compile
npm run compile || exit

# Build aws distro tar file
cd aws-distro-opentelemetry-node-autoinstrumentation || exit
rm aws-aws-distro-opentelemetry-node-autoinstrumentation-*.tgz
npm pack || exit

# Install Lambda Layer Build Tool
cd ${SOURCEDIR}/packages || exit
rm -rf build
rm -rf node_modules
npm install || exit

# Build Lambda SDK layer
cd ${SOURCEDIR}/packages/layer || exit
Expand Down
36 changes: 36 additions & 0 deletions lambda-layer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@aws/aws-distro-opentelemetry-node-autoinstrumentatio-sdk-layer",
"version": "0.0.1",
"description": "Lambda Layer including AWS Distro OpenTelemetry SDK for supporting Amazon Application Signals",
"repository": "aws-observability/aws-otel-js-instrumentation",
"author": {
"name": "Amazon Web Services",
"url": "http://aws.amazon.com"
},
"homepage": "https://github.com/aws-observability/aws-otel-js-instrumentation/tree/main/aws-distro-opentelemetry-node-autoinstrumentation#readme",
"license": "Apache-2.0",
"engines": {
"node": ">=16"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"clean": "rimraf build/*",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix"
},
"keywords": [
"awsdistroopentelemetry",
"opentelemetry",
"awslambda",
"nodejs",
"tracing",
"profiling",
"instrumentation"
],
"devDependencies": {
"copyfiles": "^2.4.1",
"bestzip": "2.2.0"
}
}
35 changes: 19 additions & 16 deletions lambda-layer/packages/layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@
"instrumentation"
],
"dependencies": {
"@aws/aws-distro-opentelemetry-node-autoinstrumentation": "file:../../../aws-distro-opentelemetry-node-autoinstrumentation",
"@opentelemetry/api": "1.9.0",
"@opentelemetry/auto-instrumentations-node": "0.48.0",
"@opentelemetry/auto-configuration-propagators": "0.2.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "0.52.1",
"@opentelemetry/exporter-metrics-otlp-http": "0.52.1",
"@opentelemetry/instrumentation": "0.52.1",
"@opentelemetry/id-generator-aws-xray": "1.2.2",
"@opentelemetry/propagator-aws-xray": "1.25.1",
"@opentelemetry/core": "1.25.1",
"@opentelemetry/sdk-trace-base": "1.25.1",
"@opentelemetry/semantic-conventions": "1.25.1",
"@opentelemetry/resources": "1.25.1",
"@opentelemetry/exporter-trace-otlp-proto": "0.52.1",
"@opentelemetry/exporter-zipkin": "1.25.1",
"@opentelemetry/sdk-metrics": "1.25.1"
"@aws/aws-distro-opentelemetry-node-autoinstrumentation": "file:../../../aws-distro-opentelemetry-node-autoinstrumentation/aws-aws-distro-opentelemetry-node-autoinstrumentation-0.1.0-dev0.tgz",
"@opentelemetry/propagator-b3": "1.25.1",
"@opentelemetry/propagator-jaeger": "1.25.1",
"@opentelemetry/resource-detector-azure": "0.2.10",
"@opentelemetry/resource-detector-gcp": "0.29.10",
"@opentelemetry/semantic-conventions": "1.25.1"
},
"overrides": {
"@aws/aws-distro-opentelemetry-node-autoinstrumentation": {
"@opentelemetry/auto-configuration-propagators": {
"@opentelemetry/propagators-b3": "1.25.1"
},
"@opentelemetry/resource-detector-azure": {
"@opentelemetry/semantic-conventions": "1.25.1"
},
"@opentelemetry/resource-detector-gcp": {
"@opentelemetry/semantic-conventions": "1.25.1"
}
}
}
}
7 changes: 6 additions & 1 deletion lambda-layer/packages/layer/scripts/otel-instrument
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/bin/bash
export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js"
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";
export OTEL_NODE_ENABLED_INSTRUMENTATIONS="aws-lambda,aws-sdk"


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

# - If OTEL_NODE_ENABLED_INSTRUMENTATIONS is not set by user, use default instrumentation
if [ -z "${OTEL_NODE_ENABLED_INSTRUMENTATIONS}" ]; then
export OTEL_NODE_ENABLED_INSTRUMENTATIONS="aws-lambda,aws-sdk"
fi

# - Set the service name
if [ -z "${OTEL_SERVICE_NAME}" ]; then
export OTEL_SERVICE_NAME=$AWS_LAMBDA_FUNCTION_NAME;
Expand Down
Loading