OpenTelemetry XMLHttpRequest Instrumentation for web
![Apache License](https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat)
This module provides auto instrumentation for web using XMLHttpRequest .
Installation
npm install --save @opentelemetry/instrumentation-xml-http-request
Usage
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracerProvider } from '@opentelemetry/web';
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
const providerWithZone = new WebTracerProvider();
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
providerWithZone.register({
contextManager: new ZoneContextManager(),
});
registerInstrumentations({
instrumentations: [
new XMLHttpRequestInstrumentation({
propagateTraceHeaderCorsUrls: ['http://localhost:8090']
}),
],
});
const webTracerWithZone = providerWithZone.getTracer('default');
const xmlHttpRequestInstrumentation = new XMLHttpRequestInstrumentation({
propagateTraceHeaderCorsUrls: ['http://localhost:8090']
});
const providerWithZone = new WebTracerProvider();
providerWithZone.register({
contextManager: new ZoneContextManager(),
});
xmlHttpRequestInstrumentation.setTracerProvider(providerWithZone);
const req = new XMLHttpRequest();
req.open('GET', 'http://localhost:8090/xml-http-request.js', true);
req.send();
Example Screenshots
![Screenshot of the running example](https://github.com/open-telemetry/opentelemetry-js/raw/HEAD/images/cors.jpg)
See examples/tracer-web for a short example.
Useful links
License
Apache 2.0 - See LICENSE for more information.