
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@jaymanyoo/microservices-tracing
Advanced tools
A simple OpenTelemetry tracing setup for Node.js microservices
A simple, configurable OpenTelemetry tracing package for Node.js microservices with Jaeger integration.
npm install microservice-tracing
// Import at the very top of your main file, before any other imports
import { initializeTracing } from 'microservice-tracing';
// Initialize tracing
initializeTracing({
serviceName: 'my-service'
});
// Now import and start your application
import express from 'express';
// ... rest of your application
import { initializeTracing } from 'microservice-tracing';
initializeTracing({
serviceName: 'my-service',
serviceVersion: '1.2.3',
environment: 'production',
jaegerEndpoint: 'http://jaeger-collector:14268/api/traces',
ignoreUrls: ['/health', '/metrics', '/custom-ignore'],
instrumentations: {
http: true,
express: true,
mysql: true,
redis: true,
amqp: true,
socketio: false, // Disable if not using Socket.IO
fs: false, // Disabled by default (noisy)
dns: false // Disabled by default (noisy)
}
});
| Option | Type | Default | Description |
|---|---|---|---|
serviceName | string | Required | Name of your service as it appears in Jaeger |
serviceVersion | string | process.env.SERVICE_VERSION || '1.0.0' | Version of your service |
environment | string | process.env.NODE_ENV || 'development' | Deployment environment |
jaegerEndpoint | string | process.env.JAEGER_ENDPOINT || 'http://jaeger:14268/api/traces' | Jaeger collector endpoint |
disabled | boolean | process.env.OTEL_DISABLED === 'true' | Disable tracing entirely |
ignoreUrls | string[] | ['/health', '/ping', '/favicon', '/metrics'] | URLs to ignore in HTTP tracing |
instrumentations | object | See below | Enable/disable specific instrumentations |
instrumentations: {
http: boolean; // HTTP client/server (default: true)
express: boolean; // Express.js framework (default: true)
mysql: boolean; // MySQL/MySQL2 database (default: true)
redis: boolean; // Redis client (default: true)
amqp: boolean; // RabbitMQ/AMQP (default: true)
socketio: boolean; // Socket.IO (default: false)
fs: boolean; // File system operations (default: false)
dns: boolean; // DNS lookups (default: false)
}
You can configure the package using environment variables:
# Disable tracing entirely
OTEL_DISABLED=true
# Set Jaeger endpoint
JAEGER_ENDPOINT=http://jaeger-collector:14268/api/traces
# Set service version
SERVICE_VERSION=1.2.3
# Set environment
NODE_ENV=production
// src/index.ts
import { initializeTracing } from 'microservice-tracing';
// Initialize tracing first
initializeTracing({
serviceName: 'user-service',
instrumentations: {
express: true,
mysql: true,
redis: true
}
});
// Then import your application
import express from 'express';
import { createUserRoutes } from './routes/users';
const app = express();
app.use('/users', createUserRoutes());
app.listen(3000, () => {
console.log('Server running on port 3000');
});
import { initializeTracing } from 'microservice-tracing';
initializeTracing({
serviceName: 'data-service',
instrumentations: {
mysql: true, // Traces MySQL queries
redis: true, // Traces Redis operations
amqp: true // Traces RabbitMQ messages
}
});
// Your database and Redis operations will be automatically traced
import mysql from 'mysql2/promise';
import redis from 'redis';
import { initializeTracing } from 'microservice-tracing';
initializeTracing({
serviceName: 'chat-service',
instrumentations: {
socketio: true, // Enable Socket.IO tracing
mysql: true,
redis: true
}
});
import { Server } from 'socket.io';
// Socket.IO events will be automatically traced
import { initializeTracing } from 'microservice-tracing';
initializeTracing({
serviceName: 'notification-service',
instrumentations: {
amqp: true, // Traces RabbitMQ publish/consume
http: true // Traces outgoing HTTP calls
}
});
// RabbitMQ operations will be automatically traced
import amqp from 'amqplib';
For custom spans and metrics:
import { trace } from 'microservice-tracing';
const tracer = trace.getTracer('my-service');
async function processOrder(orderId: string) {
const span = tracer.startSpan('process-order');
try {
span.setAttributes({
'order.id': orderId,
'operation.type': 'business-logic'
});
// Your business logic here
const result = await performOrderProcessing(orderId);
span.setStatus({ code: 1 }); // OK
return result;
} catch (error) {
span.recordException(error);
span.setStatus({ code: 2, message: error.message }); // ERROR
throw error;
} finally {
span.end();
}
}
The package is optimized for production use with minimal overhead (~1-3%). Key optimizations:
For high-traffic services, you may want to implement sampling:
// Set sampling rate via environment variable
process.env.OTEL_TRACES_SAMPLER = 'traceidratio';
process.env.OTEL_TRACES_SAMPLER_ARG = '0.1'; // Sample 10% of traces
initializeTracing({
serviceName: 'high-traffic-service'
});
# Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
# Set tracing environment variables
ENV JAEGER_ENDPOINT=http://jaeger-collector:14268/api/traces
ENV SERVICE_VERSION=1.0.0
CMD ["node", "dist/index.js"]
# docker-compose.yml or Kubernetes deployment
environment:
- JAEGER_ENDPOINT=http://jaeger-collector:14268/api/traces
- SERVICE_VERSION=1.0.0
- NODE_ENV=production
No traces appearing in Jaeger
JAEGER_ENDPOINT is correctHigh memory usage
Missing spans
Enable debug logging:
DEBUG=@opentelemetry/* node your-app.js
The package automatically ignores common health check endpoints. To verify tracing is working:
# This will be traced
curl http://your-service/api/users
# This will be ignored
curl http://your-service/health
initializeTracing(config: TracingConfig): MicroserviceTracingConvenience function that creates, initializes, and sets up graceful shutdown for tracing.
class MicroserviceTracingconstructor(config: TracingConfig)Creates a new tracing instance.
initialize(): voidInitializes OpenTelemetry tracing.
shutdown(): Promise<void>Gracefully shuts down tracing.
setupGracefulShutdown(): voidSets up process signal handlers for graceful shutdown.
MIT
FAQs
A simple OpenTelemetry tracing setup for Node.js microservices
We found that @jaymanyoo/microservices-tracing demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.