Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/auto-instrumentations-node

Package Overview
Dependencies
Maintainers
3
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/auto-instrumentations-node

Metapackage which bundles opentelemetry node core and contrib instrumentations

  • 0.53.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
738K
decreased by-15.8%
Maintainers
3
Weekly downloads
 
Created

What is @opentelemetry/auto-instrumentations-node?

@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.

What are @opentelemetry/auto-instrumentations-node's main functionalities?

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();
});

Other packages similar to @opentelemetry/auto-instrumentations-node

FAQs

Package last updated on 18 Nov 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc