Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
@opentelemetry/auto-instrumentations-node
Advanced tools
Metapackage which bundles opentelemetry node core and contrib instrumentations
@opentelemetry/auto-instrumentations-node is a package that provides automatic instrumentation for Node.js applications. It simplifies the process of collecting telemetry data such as traces and metrics by automatically instrumenting various Node.js libraries and frameworks.
Automatic HTTP Instrumentation
This feature automatically instruments HTTP requests and responses, allowing you to collect telemetry data without manually adding instrumentation code.
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const provider = new NodeTracerProvider();
provider.register();
registerInstrumentations({
instrumentations: [getNodeAutoInstrumentations()]
});
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
});
server.listen(3000, '127.0.0.1', () => {
console.log('Server running at http://127.0.0.1:3000/');
});
Automatic Database Instrumentation
This feature automatically instruments database operations, such as those performed with MongoDB, to collect telemetry data on database queries and commands.
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { MongoClient } = require('mongodb');
const provider = new NodeTracerProvider();
provider.register();
registerInstrumentations({
instrumentations: [getNodeAutoInstrumentations()]
});
const url = 'mongodb://localhost:27017';
const client = new MongoClient(url);
async function run() {
try {
await client.connect();
console.log('Connected to database');
const db = client.db('test');
const collection = db.collection('documents');
await collection.insertOne({ a: 1 });
console.log('Document inserted');
} finally {
await client.close();
}
}
run().catch(console.dir);
Automatic gRPC Instrumentation
This feature automatically instruments gRPC calls, enabling the collection of telemetry data for gRPC-based microservices.
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const provider = new NodeTracerProvider();
provider.register();
registerInstrumentations({
instrumentations: [getNodeAutoInstrumentations()]
});
const packageDefinition = protoLoader.loadSync('helloworld.proto', {});
const helloProto = grpc.loadPackageDefinition(packageDefinition).helloworld;
function sayHello(call, callback) {
callback(null, { message: 'Hello ' + call.request.name });
}
const server = new grpc.Server();
server.addService(helloProto.Greeter.service, { sayHello: sayHello });
server.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => {
server.start();
});
elastic-apm-node is an official Elastic APM agent for Node.js. It provides automatic instrumentation for various Node.js frameworks and libraries, similar to @opentelemetry/auto-instrumentations-node. However, it is specifically designed to work with the Elastic APM server and the Elastic Stack.
newrelic is the official New Relic APM agent for Node.js. It offers automatic instrumentation for a wide range of Node.js modules and frameworks. Unlike @opentelemetry/auto-instrumentations-node, it is tailored to work with New Relic's monitoring and observability platform.
This module provides a simple way to initialize multiple Node instrumentations.
Compatible with OpenTelemetry JS API and SDK 1.0+
.
npm install --save @opentelemetry/auto-instrumentations-node
OpenTelemetry Meta Packages for Node automatically loads instrumentations for Node builtin modules and common packages.
Custom configuration for each of the instrumentations can be passed to the function, by providing an object with the name of the instrumentation as a key, and its configuration as the value.
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const exporter = new CollectorTraceExporter();
const provider = new NodeTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'basic-service',
}),
});
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.register();
registerInstrumentations({
instrumentations: [
getNodeAutoInstrumentations({
// load custom configuration for http instrumentation
'@opentelemetry/instrumentation-http': {
applyCustomAttributesOnSpan: (span) => {
span.setAttribute('foo2', 'bar2');
},
},
}),
],
});
APACHE 2.0 - See LICENSE for more information.
FAQs
Metapackage which bundles opentelemetry node core and contrib instrumentations
The npm package @opentelemetry/auto-instrumentations-node receives a total of 723,063 weekly downloads. As such, @opentelemetry/auto-instrumentations-node popularity was classified as popular.
We found that @opentelemetry/auto-instrumentations-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.