opentelemetry-js/packages/opentelemetry-sdk-trace-web
legendecas 04f9edd12f
feat(sdk-trace-web): web worker support (#2719)
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
2022-01-20 22:33:54 +01:00
..
src feat(sdk-trace-web): web worker support (#2719) 2022-01-20 22:33:54 +01:00
test feat(sdk-trace-web): web worker support (#2719) 2022-01-20 22:33:54 +01:00
.eslintignore chore: rename sdks to better represent what they are [#2146] (#2340) 2021-08-05 21:13:18 +02:00
.eslintrc.js feat(sdk-trace-web): web worker support (#2719) 2022-01-20 22:33:54 +01:00
.npmignore chore: rename sdks to better represent what they are [#2146] (#2340) 2021-08-05 21:13:18 +02:00
LICENSE chore: rename sdks to better represent what they are [#2146] (#2340) 2021-08-05 21:13:18 +02:00
README.md chore: add markdown link checks (#2657) 2021-12-11 21:31:36 +01:00
karma.conf.js chore: rename sdks to better represent what they are [#2146] (#2340) 2021-08-05 21:13:18 +02:00
karma.worker.js feat(sdk-trace-web): web worker support (#2719) 2022-01-20 22:33:54 +01:00
package.json feat(sdk-trace-web): web worker support (#2719) 2022-01-20 22:33:54 +01:00
tsconfig.all.json chore: add esm2015 entry for web apps aiming at modern browsers (#2556) 2021-12-11 20:02:47 +01:00
tsconfig.esm.json chore: split stable and experimental packages into groups using directories (#2462) 2021-09-10 17:14:55 -04:00
tsconfig.esm2015.json chore: add esm2015 entry for web apps aiming at modern browsers (#2556) 2021-12-11 20:02:47 +01:00
tsconfig.json chore: sort entries in tsconfig (#2402) 2021-08-07 15:38:18 +02:00

README.md

OpenTelemetry Web SDK

NPM Published Version Apache License

This module provides automated instrumentation and tracing for Web applications.

For manual instrumentation see the @opentelemetry/sdk-trace-base package.

How does automatic tracing work

This package exposes a class WebTracerProvider that will be able to automatically trace things in Browser only.

See the example how to use it.

OpenTelemetry comes with a growing number of instrumentations for well know modules (see supported modules) and an API to create custom instrumentations (see the instrumentation developer guide).

Web Tracer currently supports one plugin for document load. Unlike Node Tracer (NodeTracerProvider), the plugins needs to be initialised and passed in configuration. The reason is to give user full control over which plugin will be bundled into web page.

You can choose to use the ZoneContextManager if you want to trace asynchronous operations. Please note that the ZoneContextManager does not work with JS code targeting ES2017+. In order to use the ZoneContextManager, please transpile back to ES2015.

Installation

npm install --save @opentelemetry/sdk-trace-web

Usage

import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { DocumentLoad } from '@opentelemetry/plugin-document-load';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { registerInstrumentations } from '@opentelemetry/instrumentation';

const provider = new WebTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));

provider.register({
  // Changing default contextManager to use ZoneContextManager - supports asynchronous operations - optional
  contextManager: new ZoneContextManager(),
});

// Registering instrumentations / plugins
registerInstrumentations({
  instrumentations: [
    new DocumentLoad(),
  ],
});

License

Apache 2.0 - See LICENSE for more information.