Bundled Applications
What a bundler hides from the LogDrop Node.js agent, and how to keep your libraries traced.
The agent traces a library when your service loads it from node_modules. A bundler (esbuild, webpack, ncc and similar) copies the libraries into one output file, so that never happens and most spans are lost. Keep the libraries outside the bundle and the agent traces them again.
What is lost
A bundled service still sends traces, but they lose detail:
| Still traced in a bundle | Lost in a bundle |
|---|---|
Incoming and outgoing HTTP (http, https, fetch), custom spans | Route names (GET instead of GET /orders/:id), and the database, Redis, RabbitMQ and Kafka spans |
When the agent sees HTTP requests but none of the libraries it traces, it prints one warning:
[logdrop-agent] WARN HTTP requests are traced, but the application looks bundled: …A Docker image is not a bundle: an image with your code and its node_modules is traced fully.
Fix it in your build
Ship node_modules with the service (npm ci --omit=dev) and use one of these:
- Do not bundle the server. Compile TypeScript with
tscand run the output next tonode_modules. - Keep packages outside the bundle. Your own code is still bundled:
- esbuild:
esbuild src/server.ts --bundle --platform=node --packages=external --outfile=dist/server.js - webpack:
externals: [require('webpack-node-externals')()]withtarget: 'node' - ncc:
ncc build src/server.js -e express -e pg …
- esbuild:
- Keep only the traced packages outside:
express,fastify,koa,@koa/router,graphql,@grpc/grpc-js,pg,mysql,mysql2,tedious,mongodb,ioredis,redis,amqplibandkafkajs. Mark them as external in your bundler and install them in the image.
Restart the service. The warning is gone, and route names and dependency spans appear in the next traces.
.png)