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

@opentelemetry/instrumentation-fastify

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-fastify

OpenTelemetry instrumentation for `fastify` http web application framework

  • 0.43.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.8M
increased by2.78%
Maintainers
3
Weekly downloads
 
Created

What is @opentelemetry/instrumentation-fastify?

@opentelemetry/instrumentation-fastify is an npm package that provides automatic instrumentation for Fastify applications using OpenTelemetry. It helps in collecting and exporting telemetry data such as traces and metrics, which can be used for monitoring and performance analysis.

What are @opentelemetry/instrumentation-fastify's main functionalities?

Automatic Tracing

This code demonstrates how to set up automatic tracing for a Fastify application using @opentelemetry/instrumentation-fastify. It initializes the OpenTelemetry tracer provider and registers the Fastify instrumentation to automatically collect trace data for incoming requests.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { FastifyInstrumentation } = require('@opentelemetry/instrumentation-fastify');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    new FastifyInstrumentation()
  ],
  tracerProvider: provider,
});

const fastify = require('fastify')();

fastify.get('/hello', async (request, reply) => {
  return { hello: 'world' };
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});

Custom Span Attributes

This code sample shows how to add custom attributes to spans in a Fastify application. The `requestHook` option allows you to modify the span for each request, adding custom attributes that can be useful for more detailed telemetry data.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { FastifyInstrumentation } = require('@opentelemetry/instrumentation-fastify');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    new FastifyInstrumentation({
      requestHook: (span, request) => {
        span.setAttribute('http.custom_attribute', 'custom_value');
      }
    })
  ],
  tracerProvider: provider,
});

const fastify = require('fastify')();

fastify.get('/hello', async (request, reply) => {
  return { hello: 'world' };
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});

Other packages similar to @opentelemetry/instrumentation-fastify

Keywords

FAQs

Package last updated on 05 Dec 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