a v bad representation of a command line

Update all NPM dependencies for OpenTelemetry in one command line

|

, , ,

When I come back to a project, and the tracing isn’t satisfactory, the first thing I do is update the SDK and all instrumentation libraries.

For a node.js project (or anything that uses NPM), there’s a list of OpenTelemetry dependencies in package.json, like:

 "dependencies": {
    "@opentelemetry/auto-instrumentations-node": "^0.43.0",
    "@opentelemetry/exporter-trace-otlp-proto": "^0.49.1",
    "@opentelemetry/sdk-node": "^0.49.1",
    "express": "^4.18.3",
    "pino": "^9.2.0"
  },

(Sometimes the list is much longer)

I want to update all the OpenTelemetry ones, by running, for instance:

npm install @opentelemetry/auto-instrumentations-node@latest

Here’s a one-liner to do all of them. It works on my mac, with jq installed. jq manipulates JSON data, with its own little programming language. Recommend.

cat package.json | jq '.dependencies | keys[]' -r | grep opentelemetry | sed 's/$/@latest/' |  xargs npm install

This reads package.json; pipes that to jq to access the keys of the dependency array; chooses the OpenTelemetry ones; adds @latest to the end; and gives all those arguments to npm install.

Now that this is on OpenTelemetry In Practice, I can use google to find it and never derive that whole command again.

Latest Articles

Subscribe to
our newsletter

OpenTelemetry in Practice