opentelemetry-js/experimental/packages/opentelemetry-instrumentati...
David Luna db14633cc4
feat(sdk-trace-base): add `spanProcessors` property in `TracerConfig` interface (#5138)
2024-11-12 15:48:00 +00:00
..
images chore: split stable and experimental packages into groups using directories (#2462) 2021-09-10 17:14:55 -04:00
src refactor: remove "export *" in favor of explicit named exports (#4880) 2024-08-09 10:42:38 +00:00
test refactor(instrumentation-xhr): use exported strings for semantic attr… (#4681) 2024-06-04 08:24:09 +00: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 feat(sdk-trace-base): add `spanProcessors` property in `TracerConfig` interface (#5138) 2024-11-12 15:48:00 +00: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 chore: prepare next release (#5120) 2024-11-07 12:42:00 +00:00
tsconfig.esm.json chore(semconv): Separate SemConv releases to allow different versioning (#4904) 2024-08-20 21:29:59 +00:00
tsconfig.esnext.json chore(semconv): Separate SemConv releases to allow different versioning (#4904) 2024-08-20 21:29:59 +00:00
tsconfig.json chore(semconv): Separate SemConv releases to allow different versioning (#4904) 2024-08-20 21:29:59 +00:00

README.md

OpenTelemetry XMLHttpRequest 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 XMLHttpRequest .

Installation

npm install --save @opentelemetry/instrumentation-xml-http-request

Usage

import {
  ConsoleSpanExporter,
  SimpleSpanProcessor,
  WebTracerProvider,
} from '@opentelemetry/sdk-trace-web';
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { registerInstrumentations } from '@opentelemetry/instrumentation';

const providerWithZone = new WebTracerProvider({
  spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())]
});

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

registerInstrumentations({
  instrumentations: [
    new XMLHttpRequestInstrumentation({
      propagateTraceHeaderCorsUrls: ['http://localhost:8090']
    }),
  ],
});


const webTracerWithZone = providerWithZone.getTracer('default');

/////////////////////////////////////////

// or plugin can be also initialised separately and then set the tracer provider or meter provider
const xmlHttpRequestInstrumentation = new XMLHttpRequestInstrumentation({
  propagateTraceHeaderCorsUrls: ['http://localhost:8090']
});
const providerWithZone = new WebTracerProvider();
providerWithZone.register({
  contextManager: new ZoneContextManager(),
});
xmlHttpRequestInstrumentation.setTracerProvider(providerWithZone);
/////////////////////////////////////////


// and some test
const req = new XMLHttpRequest();
req.open('GET', 'http://localhost:8090/xml-http-request.js', true);
req.send();

XHR Instrumentation options

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

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

Example Screenshots

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

See examples/tracer-web for a short example.

License

Apache 2.0 - See LICENSE for more information.