Skip to content

Commit

Permalink
Enable module loading hook if handler is in an mjs file
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalSumislawski committed Apr 23, 2024
1 parent 2f6ce41 commit 9164686
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
28 changes: 13 additions & 15 deletions nodejs/packages/layer/package-lock.json

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

6 changes: 3 additions & 3 deletions nodejs/packages/layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"node": ">=16.0.0"
},
"dependencies": {
"@opentelemetry/core": "1.22.0",
"@opentelemetry/api": "^1.7.0",
"@opentelemetry/core": "1.22.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "0.49.1",
"@opentelemetry/exporter-trace-otlp-grpc": "0.49.1",
"@opentelemetry/instrumentation": "file:../../../../../oss/opentelemetry-js/experimental/packages/opentelemetry-instrumentation/opentelemetry-instrumentation-0.49.1.tgz",
"@opentelemetry/instrumentation-aws-lambda": "file:../../../../opentelemetry-js-contrib-cx/plugins/node/opentelemetry-instrumentation-aws-lambda/coralogix-instrumentation-aws-lambda-0.39.0.tgz",
"@opentelemetry/instrumentation-aws-sdk": "file:../../../../opentelemetry-js-contrib-cx/plugins/node/opentelemetry-instrumentation-aws-sdk/coralogix-instrumentation-aws-sdk-0.39.0.tgz",
"@opentelemetry/instrumentation-aws-lambda": "file:../../../../opentelemetry-js-contrib-cx/plugins/node/opentelemetry-instrumentation-aws-lambda/opentelemetry-instrumentation-aws-lambda-0.39.0.tgz",
"@opentelemetry/instrumentation-aws-sdk": "file:../../../../opentelemetry-js-contrib-cx/plugins/node/opentelemetry-instrumentation-aws-sdk/opentelemetry-instrumentation-aws-sdk-0.39.0.tgz",
"@opentelemetry/instrumentation-dns": "^0.34.0",
"@opentelemetry/instrumentation-express": "^0.36.1",
"@opentelemetry/instrumentation-graphql": "^0.38.1",
Expand Down
7 changes: 7 additions & 0 deletions nodejs/packages/layer/scripts/otel-handler
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/bash
MJS_FILE="${LAMBDA_TASK_ROOT}/${_HANDLER%.*}.mjs"

# If it's an mjs file, then we enable the hook for node modules loading
if [ -f "${DIR_PATH}" ]; then
# If the file exists, export NODE_OPTIONS
export NODE_OPTIONS="${NODE_OPTIONS} --experimental-loader=@opentelemetry/instrumentation/hook.mjs"
fi

export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js"

Expand Down
4 changes: 0 additions & 4 deletions nodejs/packages/layer/src/wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { register } from "node:module";
import { pathToFileURL } from "node:url";
register("@opentelemetry/instrumentation/hook.mjs", pathToFileURL("./"));

import {
NodeTracerConfig,
NodeTracerProvider,
Expand Down

0 comments on commit 9164686

Please sign in to comment.