opentelemetry-js/packages/opentelemetry-instrumentati...
Bartlomiej Obecny 9cfa92c4a5
Use instrumentation loader to load plugins and instrumentations (#1855)
* chore: removing plugin loader from node, updating usage and docs

* chore: testing and updating examples

* chore: lint

* chore: adding comment about usage

* chore: adding upgrading guidelines
2021-02-05 19:02:29 +01:00
..
images feat: replacing base plugin with instrumentation for xml-http-request (#1659) 2020-11-10 17:56:38 +01:00
src chore: update to typescript 4.1 and gts 3 (#1890) 2021-02-03 11:53:25 -05:00
test Use instrumentation loader to load plugins and instrumentations (#1855) 2021-02-05 19:02:29 +01:00
.eslintignore feat: replacing base plugin with instrumentation for xml-http-request (#1659) 2020-11-10 17:56:38 +01:00
.eslintrc.js feat: replacing base plugin with instrumentation for xml-http-request (#1659) 2020-11-10 17:56:38 +01:00
.npmignore feat: replacing base plugin with instrumentation for xml-http-request (#1659) 2020-11-10 17:56:38 +01:00
LICENSE feat: replacing base plugin with instrumentation for xml-http-request (#1659) 2020-11-10 17:56:38 +01:00
README.md chore: remove all gitter links and replace with dicussions (#1866) 2021-01-27 09:34:54 -05:00
karma.conf.js feat: replacing base plugin with instrumentation for xml-http-request (#1659) 2020-11-10 17:56:38 +01:00
package.json chore: update to typescript 4.1 and gts 3 (#1890) 2021-02-03 11:53:25 -05:00
tsconfig.json chore: speed up builds (#1748) 2020-12-18 09:16:18 -05:00

README.md

OpenTelemetry XMLHttpRequest Instrumentation for web

NPM Published Version dependencies devDependencies Apache License

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';

// this is still possible
const providerWithZone = new WebTracerProvider({
  plugins: [
    new XMLHttpRequestInstrumentation({
      propagateTraceHeaderCorsUrls: ['http://localhost:8090']
    })
  ]
});
providerWithZone.register({
  contextManager: new ZoneContextManager(),
});
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);
/////////////////////////////////////////

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

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

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.