Skip to content

Commit

Permalink
chore: use withSpan where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Feb 26, 2020
1 parent b323afe commit acdae62
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
8 changes: 4 additions & 4 deletions packages/opentelemetry-node/test/NodeTracerProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('NodeTracerProvider', () => {
it('should run scope with AsyncHooksScopeManager scope manager', done => {
provider = new NodeTracerProvider({});
const span = provider.getTracer('default').startSpan('my-span');
context.with(setActiveSpan(context.active(), span), () => {
provider.getTracer('default').withSpan(span, () => {
assert.deepStrictEqual(
provider.getTracer('default').getCurrentSpan(),
span
Expand All @@ -190,15 +190,15 @@ describe('NodeTracerProvider', () => {
it('should run scope with AsyncHooksScopeManager scope manager with multiple spans', done => {
provider = new NodeTracerProvider({});
const span = provider.getTracer('default').startSpan('my-span');
context.with(setActiveSpan(context.active(), span), () => {
provider.getTracer('default').withSpan(span, () => {
assert.deepStrictEqual(
provider.getTracer('default').getCurrentSpan(),
span
);

const span1 = provider.getTracer('default').startSpan('my-span1');

context.with(setActiveSpan(context.active(), span1), () => {
provider.getTracer('default').withSpan(span1, () => {
assert.deepStrictEqual(
provider.getTracer('default').getCurrentSpan(),
span1
Expand All @@ -221,7 +221,7 @@ describe('NodeTracerProvider', () => {
it('should find correct scope with promises', async () => {
provider = new NodeTracerProvider();
const span = provider.getTracer('default').startSpan('my-span');
await context.with(setActiveSpan(context.active(), span), async () => {
await provider.getTracer('default').withSpan(span, async () => {
for (let i = 0; i < 3; i++) {
await sleep(5).then(() => {
assert.deepStrictEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
import {
BasePlugin,
otperformance,
setActiveSpan,
TRACE_PARENT_HEADER,
} from '@opentelemetry/core';
import {
Expand Down Expand Up @@ -119,14 +118,14 @@ export class DocumentLoad extends BasePlugin<unknown> {
if (!rootSpan) {
return;
}
context.with(setActiveSpan(context.active(), rootSpan), () => {
this._tracer.withSpan(rootSpan, () => {
const fetchSpan = this._startSpan(
AttributeNames.DOCUMENT_FETCH,
PTN.FETCH_START,
entries
);
if (fetchSpan) {
context.with(setActiveSpan(context.active(), fetchSpan), () => {
this._tracer.withSpan(fetchSpan, () => {
this._addSpanNetworkEvents(fetchSpan, entries);
this._endSpan(fetchSpan, PTN.RESPONSE_END, entries);
});
Expand Down
3 changes: 1 addition & 2 deletions packages/opentelemetry-plugin-xml-http-request/src/xhr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
isWrapped,
otperformance,
urlMatches,
setActiveSpan,
} from '@opentelemetry/core';
import {
addSpanNetworkEvent,
Expand Down Expand Up @@ -133,7 +132,7 @@ export class XMLHttpRequestPlugin extends BasePlugin<XMLHttpRequest> {
span: api.Span,
corsPreFlightRequest: PerformanceResourceTiming
): void {
api.context.with(setActiveSpan(api.context.active(), span), () => {
this._tracer.withSpan(span, () => {
const childSpan = this._tracer.startSpan('CORS Preflight', {
startTime: corsPreFlightRequest[PTN.FETCH_START],
});
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-web/test/WebTracerProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('WebTracerProvider', () => {

const rootSpan = webTracerWithZone.startSpan('rootSpan');

context.with(setActiveSpan(context.active(), rootSpan), () => {
webTracerWithZone.withSpan(rootSpan, () => {
assert.ok(
webTracerWithZone.getCurrentSpan() === rootSpan,
'Current span is rootSpan'
Expand All @@ -96,7 +96,7 @@ describe('WebTracerProvider', () => {
'concurrentSpan2'
);

context.with(setActiveSpan(context.active(), concurrentSpan1), () => {
webTracerWithZone.withSpan(concurrentSpan1, () => {
setTimeout(() => {
assert.ok(
webTracerWithZone.getCurrentSpan() === concurrentSpan1,
Expand All @@ -105,7 +105,7 @@ describe('WebTracerProvider', () => {
}, 10);
});

context.with(setActiveSpan(context.active(), concurrentSpan2), () => {
webTracerWithZone.withSpan(concurrentSpan2, () => {
setTimeout(() => {
assert.ok(
webTracerWithZone.getCurrentSpan() === concurrentSpan2,
Expand Down

0 comments on commit acdae62

Please sign in to comment.