Skip to content

Commit

Permalink
Merge branch 'master' into propagate-context-api
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud authored Sep 21, 2020
2 parents 0b482fc + 3bc4d57 commit c241d6c
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 11 deletions.
6 changes: 4 additions & 2 deletions getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ This guide uses the example application provided in the `example` directory, but

([link to TypeScript version](ts-example/README.md#install-the-required-opentelemetry-libraries))

To create traces on NodeJS, you will need `@opentelemetry/node`, `@opentelemetry/core`, and any plugins required by your application such as gRPC, or HTTP. If you are using the example application, you will need to install `@opentelemetry/plugin-http`.
To create traces on NodeJS, you will need `@opentelemetry/node`, `@opentelemetry/core`, and any plugins required by your application such as gRPC, or HTTP. If you are using the example application, you will need to install `@opentelemetry/plugin-http`, `@opentelemetry/plugin-https` and `@opentelemetry/plugin-express`.

```sh
$ npm install \
@opentelemetry/core \
@opentelemetry/node \
@opentelemetry/plugin-http
@opentelemetry/plugin-http \
@opentelemetry/plugin-https \
@opentelemetry/plugin-express
```

#### Initialize a global tracer
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"devDependencies": {
"@commitlint/cli": "9.1.1",
"@commitlint/config-conventional": "9.1.1",
"@typescript-eslint/eslint-plugin": "3.9.0",
"@typescript-eslint/parser": "3.9.0",
"@typescript-eslint/eslint-plugin": "4.1.1",
"@typescript-eslint/parser": "4.1.1",
"beautify-benchmark": "0.2.4",
"benchmark": "2.1.4",
"eslint": "7.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"devDependencies": {
"@types/mocha": "8.0.2",
"@types/node": "14.0.27",
"@types/sinon": "4.3.1",
"@types/sinon": "9.0.5",
"@types/webpack-env": "1.15.2",
"codecov": "3.7.2",
"gts": "2.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ export class AsyncHooksContextManager extends AbstractAsyncHooksContextManager {
* Init hook will be called when userland create a async context, setting the
* context as the current one if it exist.
* @param uid id of the async context
* @param type the resource type
*/
private _init(uid: number) {
private _init(uid: number, type: string) {
// ignore TIMERWRAP as they combine timers with same timeout which can lead to
// false context propagation. TIMERWRAP has been removed in node 11
// every timer has it's own `Timeout` resource anyway which is used to propagete
// context.
if (type === 'TIMERWRAP') return;

const context = this._stack[this._stack.length - 1];
if (context !== undefined) {
this._contexts.set(uid, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,34 @@ for (const contextManagerClass of [
});
assert.strictEqual(contextManager.active(), Context.ROOT_CONTEXT);
});

it('should work with timers using the same timeout', done => {
let cnt = 3;
function countDown() {
cnt--;
if (cnt === 0) done();
if (cnt < 0) throw new Error('too many calls to countDown()');
}

const time1 = 2;
const time2 = time1 + 1;
const rootCtx = contextManager.active();
const innerCtx = rootCtx.setValue(Symbol('test'), 23);
contextManager.with(innerCtx, () => {
setTimeout(() => {
assert.strictEqual(contextManager.active(), innerCtx);
countDown();
}, time1);
});
setTimeout(() => {
assert.strictEqual(contextManager.active(), rootCtx);
countDown();
}, time1);
setTimeout(() => {
assert.strictEqual(contextManager.active(), rootCtx);
countDown();
}, time2);
});
});

describe('.bind(function)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"build/src/**/*.proto",
"build/protos/**/*.proto",
"doc",
"LICENSE",
"README.md"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"build/src/**/*.proto",
"build/protos/**/*.proto",
"doc",
"LICENSE",
"README.md"
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-plugin-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@types/mocha": "8.0.2",
"@types/node": "14.0.27",
"@types/shimmer": "1.0.1",
"@types/sinon": "7.5.2",
"@types/sinon": "9.0.5",
"@types/webpack-env": "1.15.2",
"babel-loader": "8.1.0",
"codecov": "3.7.2",
Expand All @@ -65,7 +65,7 @@
"mocha": "7.2.0",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"sinon": "7.5.0",
"sinon": "9.0.3",
"ts-loader": "8.0.2",
"ts-mocha": "7.0.0",
"ts-node": "8.10.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-sdk-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"nyc": "15.1.0",
"semver": "7.3.2",
"sinon": "9.0.3",
"ts-loader": "7.0.5",
"ts-loader": "8.0.4",
"ts-mocha": "7.0.0",
"typescript": "3.9.7"
}
Expand Down

0 comments on commit c241d6c

Please sign in to comment.