Outside Kubernetes
Run the LogDrop Node.js agent on a host, with pm2 or systemd, or in a container.
Outside Kubernetes you install the agent from npm, add it to NODE_OPTIONS, and configure it with LOGDROP_* environment variables. Your code does not change.
You need a traces ingest key and the other items in Before you start, and the Node.js requirements.
1. Install the agent and store the key
The agent is the npm package @log-drop/node-agent, which Node.js loads when it starts, and it reads the traces ingest key from a file. Add the agent to your service, next to its other dependencies:
npm install @log-drop/node-agent@0.1.0-alpha1Store the key in a file that only the service user can read:
sudo mkdir -p /etc/logdrop
printf 'Traces key (paste it once, then press Enter): ' && read -rs LOGDROP_TRACE_KEY && echo
if [[ $LOGDROP_TRACE_KEY == ldtk_* && ${#LOGDROP_TRACE_KEY} -eq 71 ]]; then
printf '%s' "$LOGDROP_TRACE_KEY" | sudo tee /etc/logdrop/trace-ingest-key >/dev/null
else
echo 'That is not one traces key (it starts with ldtk_ and has 71 characters). Paste it once.'
fi
unset LOGDROP_TRACE_KEY
sudo chown <service user> /etc/logdrop/trace-ingest-key && sudo chmod 600 /etc/logdrop/trace-ingest-key2. Start Node.js with the agent
--require in NODE_OPTIONS makes Node.js load the agent before your code. The LOGDROP_* variables tell it where to send traces, which key file to read and how your service appears in APM.
Run this in the service's directory, where node_modules is:
export LOGDROP_ENDPOINT=https://otel.logdrop.io
export LOGDROP_INGEST_KEY_FILE=/etc/logdrop/trace-ingest-key
export LOGDROP_SERVICE=orders
export LOGDROP_ENVIRONMENT=production
export LOGDROP_RELEASE=1.4.2
NODE_OPTIONS="--require @log-drop/node-agent/register.js" node server.jsThe process then writes one line to standard error:
[logdrop-agent] INFO LogDrop Node.js agent 0.1.0-alpha1 is tracing service "orders" (environment "production") to otel.logdrop.io.Use --require for both CommonJS and ECMAScript module applications: the agent registers the module hooks that ES modules need on its own. If NODE_OPTIONS already holds flags, add the agent to them, for example NODE_OPTIONS="--max-old-space-size=512 --require @log-drop/node-agent/register.js".
With pm2
If pm2 runs your service, set NODE_OPTIONS and the LOGDROP_* variables in the app's env:
module.exports = {
apps: [{
name: 'orders',
script: 'server.js',
env: {
NODE_OPTIONS: '--require @log-drop/node-agent/register.js',
LOGDROP_ENDPOINT: 'https://otel.logdrop.io',
LOGDROP_INGEST_KEY_FILE: '/etc/logdrop/trace-ingest-key',
LOGDROP_SERVICE: 'orders',
LOGDROP_ENVIRONMENT: 'production',
},
}],
};In cluster mode, each pm2 worker is traced as its own instance of the service.
As a systemd service
If systemd runs your service, set the same variables in its unit file. WorkingDirectory must be the directory that holds node_modules, so that --require finds the agent:
[Service]
WorkingDirectory=/opt/orders
Environment=LOGDROP_ENDPOINT=https://otel.logdrop.io
Environment=LOGDROP_INGEST_KEY_FILE=/etc/logdrop/trace-ingest-key
Environment=LOGDROP_SERVICE=orders
Environment=LOGDROP_ENVIRONMENT=production
Environment="NODE_OPTIONS=--require @log-drop/node-agent/register.js"
ExecStart=/usr/bin/node /opt/orders/server.jsIn a container without Kubernetes
Install the agent in the image with your other dependencies (npm ci --omit=dev), mount the key file read-only and set the same variables:
docker run -v /etc/logdrop/trace-ingest-key:/run/secrets/logdrop-trace-ingest-key:ro \
-e NODE_OPTIONS="--require @log-drop/node-agent/register.js" \
-e LOGDROP_ENDPOINT=https://otel.logdrop.io -e LOGDROP_INGEST_KEY_FILE=/run/secrets/logdrop-trace-ingest-key \
-e LOGDROP_SERVICE=orders -e LOGDROP_ENVIRONMENT=production <your image>The image's working directory must be the one that holds node_modules, or give the full path: --require /app/node_modules/@log-drop/node-agent/register.js.
The key in a file or in a variable
LOGDROP_INGEST_KEY (the key itself in a variable) works too, but prefer the file:
- the agent re-reads the file every 10 seconds, so you can rotate the key without a restart;
- a variable is visible to anyone who can read the process environment.
Set one of the two, not both.
Things to know
- Package manager processes (
npm,npx,yarn,pnpm,corepack) inheritNODE_OPTIONSbut are never traced, sonpm starttraces only your server. - If your build bundles the server into one file, read Bundled applications.
- Outside containers, the agent adds the host ID and host name to every trace.
- Each process gets a new instance ID in APM. Set
LOGDROP_SERVICE_INSTANCE_IDto a stable value if restarts should count as the same instance. - The agent keeps the spans waiting to be sent in memory (at most 2,048 by default), not on disk. When the process runs out of work and exits on its own, the agent sends what is left for up to 10 seconds first. A process that ends with
process.exit()or a signal does not wait: callLogDrop.flushbefore it exits, for example at the end of a batch job.
All settings are listed in Agent settings.
.png)