Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Lambda Layer cold start time #2 #171

Merged
Merged
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
11 changes: 9 additions & 2 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 .",
"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,8 +95,11 @@
"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",
Expand All @@ -110,6 +115,7 @@
"@opentelemetry/instrumentation-aws-sdk": "0.49.0",
"@opentelemetry/otlp-transformer": "0.57.1",
"@opentelemetry/propagator-aws-xray": "1.26.2",
"@opentelemetry/propagator-aws-xray-lambda": "^0.54.0",
"@opentelemetry/resource-detector-aws": "1.12.0",
"@opentelemetry/resources": "1.30.1",
"@opentelemetry/sdk-metrics": "1.30.1",
Expand All @@ -121,6 +127,7 @@
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"build/src/**/*.d.ts.map",
"build/src/**/*.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ 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;

/**
* 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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 @@ -506,7 +506,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 @@ -25,7 +25,7 @@ import { AWSXRAY_TRACE_ID_HEADER, AWSXRayPropagator } from '@opentelemetry/propa
import { Context } from 'aws-lambda';
import { SinonStub } from 'sinon';
import { Lambda } from '@aws-sdk/client-lambda';
import nock = require('nock');
import * as nock from 'nock';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { getTestSpans } from '@opentelemetry/contrib-test-utils';
import { instrumentationConfigs } from '../../src/register';
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",
},
"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