Socket
Socket
Sign inDemoInstall

@opentelemetry/instrumentation-fetch

Package Overview
Dependencies
31
Maintainers
3
Versions
176
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @opentelemetry/instrumentation-fetch

OpenTelemetry fetch automatic instrumentation package.


Version published
Weekly downloads
141K
decreased by-5.81%
Maintainers
3
Install size
6.88 MB
Created
Weekly downloads
 

Readme

Source

OpenTelemetry Fetch Instrumentation for web

NPM Published Version Apache License

Note: This is an experimental package under active development. New releases may include breaking changes.

This module provides auto instrumentation for web using fetch. (Note: This instrumentation does not instrument Node.js' fetch. See @opentelemetry/instrumentation-undici for that.)

Installation

npm install --save @opentelemetry/instrumentation-fetch

Usage

import {
  ConsoleSpanExporter,
  SimpleSpanProcessor,
  WebTracerProvider,
} from '@opentelemetry/sdk-trace-web';
import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { registerInstrumentations } from '@opentelemetry/instrumentation';

const provider = new WebTracerProvider();

provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));

provider.register({
  contextManager: new ZoneContextManager(),
});

registerInstrumentations({
  instrumentations: [new FetchInstrumentation()],
});

// or plugin can be also initialised separately and then set the tracer provider or meter provider
const fetchInstrumentation = new FetchInstrumentation();
const provider = new WebTracerProvider();
provider.register({
  contextManager: new ZoneContextManager(),
});
fetchInstrumentation.setTracerProvider(provider);

provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));


// and some test

fetch('http://localhost:8090/fetch.js');

Example Screenshots

Screenshot of the running example Screenshot of the running example Screenshot of the running example

See examples/tracer-web/fetch for a short example.

Fetch Instrumentation options

Fetch instrumentation plugin has few options available to choose from. You can set the following:

OptionsTypeDescription
applyCustomAttributesOnSpanHttpCustomAttributeFunctionFunction for adding custom attributes
ignoreNetworkEventsbooleanDisable network events being added as span events (network events are added by default)

License

Apache 2.0 - See LICENSE for more information.

Keywords

FAQs

Last updated on 24 Apr 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc