Skip to content

Commit

Permalink
feat: do not run nodejs agent for unsupported node runtimes (#1528)
Browse files Browse the repository at this point in the history
At the moment, nodejs agent will import all it's dependencies when it
starts. Those might pull in code that is not compatible with old node
runtimes, and cause an exception in agent code.

This PR makes it so that the agent is only loaded if the nodejs version
is supported, and silently catch and ignore any exception from the
agent.

This PR extract the compiling of the nodejs agent to a separate docker
build stage, a bit simplifying the dockerfile


If the nodejs runtime version was detected in language detection, the
instrumentation device should not even be injected and the agent should
not be loaded. However, if the runtime details is not detected, or some
other situation causes the agent to run on an old node runtime, the
agent should handle it and not cause any issues for application
  • Loading branch information
blumamir authored Sep 20, 2024
1 parent fdd037b commit fda3173
Show file tree
Hide file tree
Showing 6 changed files with 1,022 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ verify-nodejs-agent:

.PHONY: build-odiglet-with-agents
build-odiglet-with-agents:
docker build -t $(ORG)/odigos-odiglet:$(TAG) . -f odiglet/Dockerfile --build-arg ODIGOS_VERSION=$(TAG) --build-context nodejs-agent-native-community-src=../opentelemetry-node
docker build -t $(ORG)/odigos-odiglet:$(TAG) . -f odiglet/Dockerfile --build-arg ODIGOS_VERSION=$(TAG) --build-context nodejs-agent-src=../opentelemetry-node

.PHONY: build-autoscaler
build-autoscaler:
Expand Down
1 change: 1 addition & 0 deletions agents/nodejs-native-community/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
10 changes: 10 additions & 0 deletions agents/nodejs-native-community/autoinstrumentation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
const [major] = process.versions.node.split('.').map(Number);
if (major < 14) {
console.error('Odigos: Unsupported Node.js version for OpenTelemetry auto-instrumentation');
} else {
require('@odigos/opentelemetry-node')
}
} catch (e) {
console.error('Odigos: Failed to load OpenTelemetry auto-instrumentation', e);
}
8 changes: 8 additions & 0 deletions agents/nodejs-native-community/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@odigos/opentelemetry-node-native-community",
"version": "0.0.1",
"main": "index.js",
"dependencies": {
"@odigos/opentelemetry-node": "file:../../../opentelemetry-node"
}
}
Loading

0 comments on commit fda3173

Please sign in to comment.