Socket
Socket
Sign inDemoInstall

@opentelemetry/instrumentation-koa

Package Overview
Dependencies
Maintainers
4
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-koa

OpenTelemetry Koa automatic instrumentation package.


Version published
Weekly downloads
1.5M
decreased by-20.13%
Maintainers
4
Weekly downloads
 
Created

What is @opentelemetry/instrumentation-koa?

@opentelemetry/instrumentation-koa is an npm package that provides automatic tracing and monitoring for Koa applications using OpenTelemetry. It helps developers gain insights into the performance and behavior of their Koa-based applications by capturing and exporting telemetry data such as traces and metrics.

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

Automatic Tracing

This code sets up automatic tracing for a Koa application. It initializes the OpenTelemetry tracer provider and registers the Koa instrumentation, which automatically captures and exports trace data for incoming HTTP requests.

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

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

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

const Koa = require('koa');
const app = new Koa();

app.use(async (ctx) => {
  ctx.body = 'Hello World';
});

app.listen(3000);

Custom Span Attributes

This code demonstrates how to add custom attributes to spans in a Koa application. The `requestHook` option allows you to modify spans by adding custom attributes, which can be useful for adding additional context to your traces.

const { context, trace } = require('@opentelemetry/api');
const { KoaInstrumentation } = require('@opentelemetry/instrumentation-koa');

const koaInstrumentation = new KoaInstrumentation({
  requestHook: (span, ctx) => {
    span.setAttribute('http.custom_attribute', 'custom_value');
  },
});

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

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

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

const Koa = require('koa');
const app = new Koa();

app.use(async (ctx) => {
  ctx.body = 'Hello World';
});

app.listen(3000);

Other packages similar to @opentelemetry/instrumentation-koa

Keywords

FAQs

Package last updated on 24 Nov 2021

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc