Skip to content

Commit

Permalink
chore: use WebTracerProvider instead of WebTracer in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bradfrosty committed Dec 1, 2020
1 parent ac686d4 commit e5e57da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 5 additions & 3 deletions packages/opentelemetry-context-zone-peer-dep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ npm install --save @opentelemetry/context-zone-peer-dep

```js
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { WebTracerProvider } from '@opentelemetry/web';
import { ZoneContextManager } from '@opentelemetry/context-zone-peer-dep';

const webTracerWithZone = new WebTracer({
const providerWithZone = new WebTracerProvider();
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
providerWithZone.register({
contextManager: new ZoneContextManager()
});
webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));

// Example how the ZoneContextManager keeps the reference to the correct context during async operations
const webTracerWithZone = providerWithZone.getTracer('default');
const span1 = webTracerWithZone.startSpan('foo1');
webTracerWithZone.withSpan(span1, () => {
console.log('Current span is span1', webTracerWithZone.getCurrentSpan() === span1);
Expand Down
8 changes: 5 additions & 3 deletions packages/opentelemetry-context-zone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ npm install --save @opentelemetry/context-zone

```js
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { WebTracerProvider } from '@opentelemetry/web';
import { ZoneContextManager } from '@opentelemetry/context-zone';

const webTracerWithZone = new WebTracer({
const providerWithZone = new WebTracerProvider();
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register({
contextManager: new ZoneContextManager()
});
webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));

// Example how the ZoneContextManager keeps the reference to the correct context during async operations
const webTracerWithZone = providerWithZone.getTracer('default');
const span1 = webTracerWithZone.startSpan('foo1');
webTracerWithZone.withSpan(span1, () => {
console.log('Current span is span1', webTracerWithZone.getCurrentSpan() === span1);
Expand Down
16 changes: 10 additions & 6 deletions packages/opentelemetry-instrumentation-xml-http-request/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,36 @@ npm install --save @opentelemetry/instrumentation-xml-http-request

```js
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { WebTracerProvider } from '@opentelemetry/web';
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
import { ZoneContextManager } from '@opentelemetry/context-zone';

// this is still possible
const webTracerWithZone = new WebTracer({
contextManager: new ZoneContextManager(),
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 webTracerWithZone = new WebTracer({
const providerWithZone = new WebTracerProvider();
providerWithZone.register({
contextManager: new ZoneContextManager(),
});
xmlHttpRequestInstrumentation.setTracerProvider(webTracerWithZone);
xmlHttpRequestInstrumentation.setTracerProvider(providerWithZone);
/////////////////////////////////////////

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

// and some test
const req = new XMLHttpRequest();
Expand Down

0 comments on commit e5e57da

Please sign in to comment.