Skip to content

Commit

Permalink
chore: update API to 0.21.0 (open-telemetry#2255)
Browse files Browse the repository at this point in the history
* chore: update API to 0.21.0

* chore: revert accidentally renamed argument

* chore: fix test

* chore: make tsdocs more clear
  • Loading branch information
dyladan authored Jun 5, 2021
1 parent 4a07850 commit d4df2f7
Show file tree
Hide file tree
Showing 49 changed files with 135 additions and 125 deletions.
2 changes: 1 addition & 1 deletion examples/basic-tracer-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"@opentelemetry/exporter-jaeger": "0.20.0",
"@opentelemetry/tracing": "0.20.0"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/collector-exporter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"@opentelemetry/core": "0.20.0",
"@opentelemetry/exporter-collector": "0.20.0",
"@opentelemetry/exporter-collector-grpc": "0.20.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@grpc/grpc-js": "^1.2.12",
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"@opentelemetry/exporter-jaeger": "0.20.0",
"@opentelemetry/exporter-zipkin": "0.20.0",
"@opentelemetry/instrumentation": "0.20.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"@opentelemetry/exporter-jaeger": "0.20.0",
"@opentelemetry/exporter-zipkin": "0.20.0",
"@opentelemetry/instrumentation": "0.20.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"@opentelemetry/exporter-jaeger": "0.20.0",
"@opentelemetry/exporter-zipkin": "0.20.0",
"@opentelemetry/instrumentation": "0.20.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/https/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"@opentelemetry/exporter-jaeger": "0.20.0",
"@opentelemetry/exporter-zipkin": "0.20.0",
"@opentelemetry/instrumentation": "0.20.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/tracer-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"webpack-merge": "^4.2.2"
},
"dependencies": {
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"@opentelemetry/context-zone": "0.20.0",
"@opentelemetry/core": "0.20.0",
"@opentelemetry/exporter-collector": "0.20.0",
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/propagation-validation-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"express": "4.17.1"
},
"devDependencies": {
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"typescript": "4.3.2"
},
"peerDependencies": {
"@opentelemetry/api": "^0.20.0"
"@opentelemetry/api": "^0.21.0"
}
}
4 changes: 2 additions & 2 deletions packages/opentelemetry-api-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"access": "public"
},
"peerDependencies": {
"@opentelemetry/api": "^0.20.0"
"@opentelemetry/api": "^0.21.0"
},
"devDependencies": {
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"@types/mocha": "8.2.2",
"@types/node": "14.14.43",
"@types/webpack-env": "1.16.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-context-async-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"@types/mocha": "8.2.2",
"@types/node": "14.14.43",
"@types/shimmer": "1.0.1",
Expand All @@ -53,6 +53,6 @@
"typescript": "4.3.2"
},
"peerDependencies": {
"@opentelemetry/api": "^0.20.0"
"@opentelemetry/api": "^0.21.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ export abstract class AbstractAsyncHooksContextManager

abstract disable(): this;

bind<T>(target: T, context: Context = this.active()): T {
/**
* Binds a the certain context or the active one to the target function and then returns the target
* @param context A context (span) to be bind to target
* @param target a function or event emitter. When target or one of its callbacks is called,
* the provided context will be used as the active context for the duration of the call.
*/
bind<T>(context: Context, target: T): T {
if (target instanceof EventEmitter) {
return this._bindEventEmitter(target, context);
}
Expand Down Expand Up @@ -180,7 +186,7 @@ export abstract class AbstractAsyncHooksContextManager
listeners = new WeakMap();
map[event] = listeners;
}
const patchedListener = contextManager.bind(listener, context);
const patchedListener = contextManager.bind(context, listener);
// store a weak reference of the user listener to ours
listeners.set(listener, patchedListener);
return original.call(this, event, patchedListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,26 +299,26 @@ for (const contextManagerClass of [
describe('.bind(function)', () => {
it('should return the same target (when enabled)', () => {
const test = { a: 1 };
assert.deepStrictEqual(contextManager.bind(test, ROOT_CONTEXT), test);
assert.deepStrictEqual(contextManager.bind(ROOT_CONTEXT, test), test);
});

it('should return the same target (when disabled)', () => {
contextManager.disable();
const test = { a: 1 };
assert.deepStrictEqual(contextManager.bind(test, ROOT_CONTEXT), test);
assert.deepStrictEqual(contextManager.bind(ROOT_CONTEXT, test), test);
contextManager.enable();
});

it('should return current context (when enabled)', done => {
const context = ROOT_CONTEXT.setValue(key1, 1);
const fn = contextManager.bind(() => {
const fn = contextManager.bind(context, () => {
assert.strictEqual(
contextManager.active(),
context,
'should have context'
);
return done();
}, context);
});
fn();
});

Expand All @@ -329,20 +329,20 @@ for (const contextManagerClass of [
it('should return current context (when disabled)', done => {
contextManager.disable();
const context = ROOT_CONTEXT.setValue(key1, 1);
const fn = contextManager.bind(() => {
const fn = contextManager.bind(context, () => {
assert.strictEqual(
contextManager.active(),
context,
'should have context'
);
return done();
}, context);
});
fn();
});

it('should fail to return current context with async op', done => {
const context = ROOT_CONTEXT.setValue(key1, 1);
const fn = contextManager.bind(() => {
const fn = contextManager.bind(context, () => {
assert.strictEqual(contextManager.active(), context);
setTimeout(() => {
assert.strictEqual(
Expand All @@ -352,7 +352,7 @@ for (const contextManagerClass of [
);
return done();
}, 100);
}, context);
});
fn();
});

Expand All @@ -363,32 +363,31 @@ for (const contextManagerClass of [
const context = ROOT_CONTEXT.setValue(key1, 2);
const otherContext = ROOT_CONTEXT.setValue(key1, 3);
const fn = otherContextManager.bind(
contextManager.bind(() => {
otherContext,
contextManager.bind(context, () => {
assert.strictEqual(contextManager.active(), context);
assert.strictEqual(otherContextManager.active(), otherContext);
}, context),
otherContext
);
}));
fn();
});
});

describe('.bind(event-emitter)', () => {
it('should return the same target (when enabled)', () => {
const ee = new EventEmitter();
assert.deepStrictEqual(contextManager.bind(ee, ROOT_CONTEXT), ee);
assert.deepStrictEqual(contextManager.bind(ROOT_CONTEXT, ee), ee);
});

it('should return the same target (when disabled)', () => {
const ee = new EventEmitter();
contextManager.disable();
assert.deepStrictEqual(contextManager.bind(ee, ROOT_CONTEXT), ee);
assert.deepStrictEqual(contextManager.bind(ROOT_CONTEXT, ee), ee);
});

it('should return current context and removeListener (when enabled)', done => {
const ee = new EventEmitter();
const context = ROOT_CONTEXT.setValue(key1, 1);
const patchedEE = contextManager.bind(ee, context);
const patchedEE = contextManager.bind(context, ee);
const handler = () => {
assert.deepStrictEqual(contextManager.active(), context);
patchedEE.removeListener('test', handler);
Expand All @@ -403,7 +402,7 @@ for (const contextManagerClass of [
it('should return current context and removeAllListener (when enabled)', done => {
const ee = new EventEmitter();
const context = ROOT_CONTEXT.setValue(key1, 1);
const patchedEE = contextManager.bind(ee, context);
const patchedEE = contextManager.bind(context, ee);
const handler = () => {
assert.deepStrictEqual(contextManager.active(), context);
patchedEE.removeAllListeners('test');
Expand All @@ -418,7 +417,7 @@ for (const contextManagerClass of [
it('should return current context and removeAllListeners (when enabled)', done => {
const ee = new EventEmitter();
const context = ROOT_CONTEXT.setValue(key1, 1);
const patchedEE = contextManager.bind(ee, context);
const patchedEE = contextManager.bind(context, ee);
const handler = () => {
assert.deepStrictEqual(contextManager.active(), context);
patchedEE.removeAllListeners();
Expand All @@ -441,7 +440,7 @@ for (const contextManagerClass of [
contextManager.disable();
const ee = new EventEmitter();
const context = ROOT_CONTEXT.setValue(key1, 1);
const patchedEE = contextManager.bind(ee, context);
const patchedEE = contextManager.bind(context, ee);
const handler = () => {
assert.deepStrictEqual(contextManager.active(), context);
patchedEE.removeListener('test', handler);
Expand All @@ -456,7 +455,7 @@ for (const contextManagerClass of [
it('should not return current context with async op', done => {
const ee = new EventEmitter();
const context = ROOT_CONTEXT.setValue(key1, 1);
const patchedEE = contextManager.bind(ee, context);
const patchedEE = contextManager.bind(context, ee);
const handler = () => {
assert.deepStrictEqual(contextManager.active(), context);
setImmediate(() => {
Expand All @@ -479,8 +478,8 @@ for (const contextManagerClass of [
const context = ROOT_CONTEXT.setValue(key1, 2);
const otherContext = ROOT_CONTEXT.setValue(key1, 3);
const patchedEE = otherContextManager.bind(
contextManager.bind(ee, context),
otherContext
otherContext,
contextManager.bind(context, ee),
);
const handler = () => {
assert.strictEqual(contextManager.active(), context);
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-context-zone-peer-dep/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"devDependencies": {
"@babel/core": "7.14.0",
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"@types/mocha": "8.2.2",
"@types/node": "14.14.43",
"@types/sinon": "9.0.11",
Expand Down Expand Up @@ -74,7 +74,7 @@
"zone.js": "0.11.4"
},
"peerDependencies": {
"@opentelemetry/api": "^0.20.0",
"@opentelemetry/api": "^0.21.0",
"zone.js": "^0.10.2 || ^0.11.0"
},
"sideEffects": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class ZoneContextManager implements ContextManager {
listeners = new WeakMap();
target.__ot_listeners[event] = listeners;
}
const patchedListener = contextManager.bind(listener, context);
const patchedListener = contextManager.bind(context, listener);
// store a weak reference of the user listener to ours
listeners.set(listener, patchedListener);
return original.call(this, event, patchedListener, opts);
Expand Down Expand Up @@ -202,10 +202,11 @@ export class ZoneContextManager implements ContextManager {

/**
* Binds a the certain context or the active one to the target function and then returns the target
* @param target
* @param context A context (span) to be bind to target
* @param target a function or event emitter. When target or one of its callbacks is called,
* the provided context will be used as the active context for the duration of the call.
*/
bind<T>(target: T | TargetWithEvents, context: Context): T {
bind<T>(context: Context, target: T | TargetWithEvents): T {
// if no specific context to propagate is given, we use the current one
if (context === undefined) {
context = this.active();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,54 +251,56 @@ describe('ZoneContextManager', () => {
const ctx = ROOT_CONTEXT.setValue(key1, obj1);
obj1.title = 'a2';
const obj2 = new Obj('b1');
const wrapper: any = contextManager.bind(obj2.getTitle, ctx);
const wrapper: any = contextManager.bind(ctx, obj2.getTitle);
assert.ok(wrapper(), 'a2');
});

it('should return the same target (when enabled)', () => {
const test = { a: 1 };
assert.deepStrictEqual(contextManager.bind(test, ROOT_CONTEXT), test);
assert.deepStrictEqual(contextManager.bind(ROOT_CONTEXT, test), test);
});

it('should return the same target (when disabled)', () => {
contextManager.disable();
const test = { a: 1 };
assert.deepStrictEqual(contextManager.bind(test, ROOT_CONTEXT), test);
assert.deepStrictEqual(contextManager.bind(ROOT_CONTEXT, test), test);
contextManager.enable();
});

it('should return current context (when enabled)', done => {
const context = ROOT_CONTEXT.setValue(key1, { a: 1 });
const fn: any = contextManager.bind(() => {
const fn: any = contextManager.bind(
context,
() => {
assert.strictEqual(
contextManager.active(),
context,
'should have context'
);
return done();
}, context);
});
fn();
});

it('should return root context (when disabled)', done => {
contextManager.disable();
const context = ROOT_CONTEXT.setValue(key1, { a: 1 });
const fn: any = contextManager.bind(() => {
const fn: any = contextManager.bind(context, () => {
assert.strictEqual(
contextManager.active(),
ROOT_CONTEXT,
'should have context'
);
return done();
}, context);
});
fn();
});

it('should bind the the certain context to the target "addEventListener" function', done => {
const ctx1 = ROOT_CONTEXT.setValue(key1, 1);
const element = document.createElement('div');

contextManager.bind(element, ctx1);
contextManager.bind(ctx1, element);

element.addEventListener('click', () => {
assert.strictEqual(contextManager.active(), ctx1);
Expand All @@ -322,7 +324,7 @@ describe('ZoneContextManager', () => {
const ctx1 = ROOT_CONTEXT.setValue(key1, 1);
const element = document.createElement('div');

contextManager.bind(element, ctx1);
contextManager.bind(ctx1, element);

element.addEventListener('click', () => {
assert.strictEqual(contextManager.active(), ctx1);
Expand Down
Loading

0 comments on commit d4df2f7

Please sign in to comment.