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
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-fastify

OpenTelemetry fastify automatic instrumentation package.

  • 0.32.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
decreased by-56.88%
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 13 Nov 2023

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