opentelemetry-js/experimental/packages/opentelemetry-instrumentati...
Marc Pichler bac68fc7d4
feat: add api release preparation scripts, github release creation scripts (#4704)
* feat: add more scripts for release creation

* Update scripts/extract-latest-release-notes.js

* fix: replace console.log() with console.warn(), ensure get-version.js is a version by checking against a regex

* chore: add comment to describe the regex
2024-05-21 14:36:43 +02:00
..
images chore: split stable and experimental packages into groups using directories (#2462) 2021-09-10 17:14:55 -04:00
src feat(instrumentation): remove default value for config in base instrumentation constructor (#4695) 2024-05-17 10:19:57 +02:00
test docs: spelling corrections (#4530) 2024-03-11 10:18:41 +01:00
.eslintignore chore: split stable and experimental packages into groups using directories (#2462) 2021-09-10 17:14:55 -04:00
.eslintrc.js chore(deps): update dependency eslint to v8.43.0 (#3929) 2023-07-06 15:14:56 +02:00
.npmignore chore: split stable and experimental packages into groups using directories (#2462) 2021-09-10 17:14:55 -04:00
LICENSE chore: split stable and experimental packages into groups using directories (#2462) 2021-09-10 17:14:55 -04:00
README.md doc(instr-fetch): mention instr-undici for Node.js fetch() (#4624) 2024-04-11 10:07:24 +02:00
karma.conf.js chore: split stable and experimental packages into groups using directories (#2462) 2021-09-10 17:14:55 -04:00
package.json feat: add api release preparation scripts, github release creation scripts (#4704) 2024-05-21 14:36:43 +02:00
tsconfig.esm.json chore: automatically generate tsconfigs (#3432) 2022-11-23 23:34:41 +08:00
tsconfig.esnext.json chore: automatically generate tsconfigs (#3432) 2022-11-23 23:34:41 +08:00
tsconfig.json chore: automatically generate tsconfigs (#3432) 2022-11-23 23:34:41 +08:00

README.md

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:

Options Type Description
applyCustomAttributesOnSpan HttpCustomAttributeFunction Function for adding custom attributes
ignoreNetworkEvents boolean Disable network events being added as span events (network events are added by default)

License

Apache 2.0 - See LICENSE for more information.