Skip to content

Commit

Permalink
registerInstrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalSumislawski committed Jun 6, 2024
1 parent 0fd5419 commit d3b162a
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
path: ${{ env.OPENTELEMETRY_JS_CONTRIB_PATH }}
repository: coralogix/opentelemetry-js-contrib
ref: refs/heads/coralogix-autoinstrumentation
ref: refs/heads/nodejs-cx-wrapper
ssh-key: ${{ secrets.OPENTELEMETRY_CI_GITHUB_KEY }}
- uses: actions/checkout@v3
with:
Expand Down
4 changes: 3 additions & 1 deletion ci-scripts/build_nodejs_layer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ npm install \
${OPENTELEMETRY_JS_CONTRIB_PATH}/plugins/node/opentelemetry-instrumentation-aws-sdk/opentelemetry-instrumentation-aws-sdk-*.tgz \
${OPENTELEMETRY_JS_PATH}/experimental/packages/opentelemetry-instrumentation/opentelemetry-instrumentation-*.tgz \
${OPENTELEMETRY_JS_PATH}/packages/opentelemetry-sdk-trace-base/opentelemetry-sdk-trace-base-*.tgz \
${IITM_PATH}/import-in-the-middle-*.tgz
${IITM_PATH}/import-in-the-middle-*.tgz \
${CWD}/nodejs/packages/cx-aws-user-function/cx-aws-user-function-*.tgz
popd > /dev/null

# Build import-in-the-middle
Expand All @@ -117,6 +118,7 @@ npm install \
${OPENTELEMETRY_JS_PATH}/experimental/packages/opentelemetry-instrumentation/opentelemetry-instrumentation-*.tgz \
${OPENTELEMETRY_JS_PATH}/packages/opentelemetry-sdk-trace-base/opentelemetry-sdk-trace-base-*.tgz \
${IITM_PATH}/import-in-the-middle-*.tgz \
${CWD}/nodejs/packages/cx-aws-user-function/cx-aws-user-function-*.tgz \
${CWD}/nodejs/packages/cx-wrapper/cx-wrapper-*.tgz
popd > /dev/null

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
MalformedHandlerName,
ImportModuleError,
UserCodeSyntaxError
} = require("./Errors.cjs");
} = require("./Errors.js");
const path = require("path");
const fs = require("fs");
const FUNCTION_EXPR = /^([^.]*)\.(.*)$/;
Expand Down
23 changes: 23 additions & 0 deletions nodejs/packages/cx-aws-user-function/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "cx-aws-user-function",
"version": "0.0.1",
"private": true,
"description": "",
"repository": "",
"keywords": [
"opentelemetry",
"awslambda",
"nodejs",
"tracing",
"profiling",
"instrumentation"
],
"engines": {
"node": ">=16.0.0"
},
"files": [
"Errors.js",
"*.js",
"*.d.ts"
]
}
16 changes: 6 additions & 10 deletions nodejs/packages/cx-wrapper/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@

import { load } from './aws/aws-user-function.js';
import {
Callback,
Context,
} from 'aws-lambda';

import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lambda';
import { load } from 'cx-aws-user-function';
import { Callback, Context } from 'aws-lambda';
import { Handler } from "aws-lambda/handler";
import {
context as otelContext,
defaultTextMapGetter,
Expand All @@ -14,9 +10,8 @@ import {
propagation,
trace,
} from '@opentelemetry/api';

import { AwsLambdaInstrumentationConfig } from '@opentelemetry/instrumentation-aws-lambda';
import {Handler} from "aws-lambda/handler";
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { AwsLambdaInstrumentation, AwsLambdaInstrumentationConfig } from '@opentelemetry/instrumentation-aws-lambda';

const parseIntEnvvar = (envName: string): number | undefined => {
const envVar = process.env?.[envName];
Expand Down Expand Up @@ -99,6 +94,7 @@ const lambdaAutoInstrumentConfig: AwsLambdaInstrumentationConfig = {
};

const instrumentation = new AwsLambdaInstrumentation(lambdaAutoInstrumentConfig)
registerInstrumentations({instrumentations: [instrumentation]})

if (process.env.CX_ORIGINAL_HANDLER === undefined)
throw Error('CX_ORIGINAL_HANDLER is missing');
Expand Down
13 changes: 13 additions & 0 deletions nodejs/packages/cx-wrapper/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nodejs/packages/cx-wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@opentelemetry/sdk-metrics": "1.22.0",
"@opentelemetry/sdk-trace-base": "file:../../../../../oss/opentelemetry-js/packages/opentelemetry-sdk-trace-base/opentelemetry-sdk-trace-base-1.22.0.tgz",
"@opentelemetry/sdk-trace-node": "1.22.0",
"cx-aws-user-function": "file:../cx-aws-user-function/cx-aws-user-function-0.0.1.tgz",
"import-in-the-middle": "file:../../../../import-in-the-middle/import-in-the-middle-1.7.3.tgz"
},
"overrides": {
Expand Down
1 change: 1 addition & 0 deletions nodejs/packages/cx-wrapper/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion nodejs/packages/layer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nodejs/packages/layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@opentelemetry/sdk-metrics": "1.22.0",
"@opentelemetry/sdk-trace-base": "file:../../../../../oss/opentelemetry-js/packages/opentelemetry-sdk-trace-base/opentelemetry-sdk-trace-base-1.22.0.tgz",
"@opentelemetry/sdk-trace-node": "1.22.0",
"cx-aws-user-function": "file:../cx-aws-user-function/cx-aws-user-function-0.0.1.tgz",
"cx-wrapper": "file:../cx-wrapper/cx-wrapper-0.0.1.tgz",
"import-in-the-middle": "file:../../../../import-in-the-middle/import-in-the-middle-1.7.3.tgz"
},
Expand Down
2 changes: 1 addition & 1 deletion nodejs/packages/layer/scripts/otel-handler
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
fi

export CX_ORIGINAL_HANDLER="${_HANDLER}"
export _HANDLER="${MAGIC_HANDLER}"
export _HANDLER="cx-wrapper.handler"

exec "$@"

0 comments on commit d3b162a

Please sign in to comment.