Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Implement a form of the Scope Manager RFC
Browse files Browse the repository at this point in the history
See https://github.com/opentracing/specification/blob/f7ca62c9/rfc/scope_manager.md
However, use continuation passing style which better fits JS and available APIs.

Implementations:
* AsyncHookSpanManager - uses Node.js async_hooks
* AsyncWrapSpanManager - uses async-hook-jl which uses Node.js AsyncWrap
* ZoneSpanManager - uses Zone.js
  • Loading branch information
pauldraper committed Aug 19, 2018
1 parent 0f14554 commit 0974d2f
Show file tree
Hide file tree
Showing 17 changed files with 1,410 additions and 906 deletions.
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ node_js:

env:
matrix:
- TEST_NODE_VERSION=0.10
- TEST_NODE_VERSION=0.10 TEST_ZONE_JS=true
- TEST_NODE_VERSION=0.12
- TEST_NODE_VERSION=0.12 TEST_ZONE_JS=true
- TEST_NODE_VERSION=4
- TEST_NODE_VERSION=4 TEST_ZONE_JS=true
- TEST_NODE_VERSION=6
- TEST_NODE_VERSION=node
- TEST_NODE_VERSION=6 TEST_ZONE_JS=true
- TEST_NODE_VERSION=8
- TEST_NODE_VERSION=8 TEST_ZONE_JS=true
- TEST_NODE_VERSION=10
- TEST_NODE_VERSION=10 TEST_ZONE_JS=true
global:
- secure: CV7Q6AHwuTCg2yi5iHC9mNexD7dgPoroZ1qdV8h+AAMUHFjO9GvCDy295l0zpqqJSb+b24GxPjx2gzK2klWMm0B55HORTBAbqJB8O7Y3dDtjycHZK23n5ph/JqhCGm4/XhxTmgDngF+0C98uWLvFKILYpTadWuOudLCc/NP4p4xykHeL2XgNA4TMg+FMYCy0k0/Xy5GNsjeHeQCJm3G1caX8jbQCRsoOiFol7Md/m5llXvY6KQzbmpis2LbPTM2mla8Ixn7bAdBX65xzcBjoWJ0dIrOghTh0z0AnEThYZHBWSvOwAkiVM3el3a4sfyUlvUfLn1ZPCK8u20uD3FQLL/q3aijmqiDORa0a6nJ67D6glRDjW1IgOyJ1iXL9GUzKBnrfdR2S78kSYGEyYDqd5Mro7InnkQ+5wgOUka0VHsJAv79tFe4ylOy3FNWzgXLmao7X/SsmV6LTXg99OpNB3zWPyFm48e5XCfWk2XR2jbeFAXc7u9W6WHWySUMpoB11FzdvNwldkE87Px8TK1guGriNSkrPk3/Abp0S+/Ka43pf+WAG2OA8DgQ2WIvCIr0ZmosS73Seg+s+MGQH9V78iFaSByEquPMbVE+3vxtl04KkRLJ1zhJ6R9CRGYKb7xiHEwCAFNMw2J8Wi5VjvvuhbkZz2D0Hn/qoEKJDkIFvzkA=
- secure: zrC64PU+T1nPdmTOCXcm+zb/f009yobySOB5YOxtlRakceIoWplJrMxlS03Z4cNCq6F3NHfPhrB8kTgNny7jSa6zP4nud2zBgWBPefgDRyR/QHaE69drcrklWM4QQz/ApUvoT2/X9e02cvDqaeENNIQlw3nJwprqeizZkbjta0+zzF2SQOSFXpjSzHSprQWaAeYBEd9KzACEL2LbejXzYPJUDGxhCBwTafRw48Ur5bp5pEazU3Tv3uRKqW6TAuZx0W5JiWoY7PVx6AlKDiTvtp6ayrCheIwzaOiHStXtn0V7+J5EKfrux30TNVeEvcXrerkdW5LJAPxKbQfj8FMat8GM7Qil35o2/KT6TFjxjiyXgMAJJg+fBlfzmcTpeI9VR/akrCmHon36w9Asgsmjuj5HEG/wbw2jRHH4C3S+J3BwAdWXW9iNkubZyLnyTlGPCm/79xdmqOx5mV0+9xc6Cfr74Gi53mE2XDpC5WD5iAGdS8xLfJNK8J6l5GAPw34gOENt40c7xXYMRx7luHZmV7BDyGW0VcA6dg33sJ2B0nd9tSvwvQpz+d/Nm6R4zRf4JQRS8VS8WYMXTW3/bPt3HbvWdsBICBMs5BcKUxszscgMJW0Ut0/Jsz3o1JEWZy3Gn8y3HJ3zcSke1GFqFNHPWGe2jQ0Rh/ainC+wCXDKkAI=
Expand Down
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,62 @@ const tracer = opentracing.globalTracer();

Note: `globalTracer()` returns a wrapper on the actual tracer object. This is done for the convenience of use as it ensures that the function will always return a non-null object. This can be helpful in cases where it is difficult or impossible to know precisely when `initGlobalTracer` is called (for example, when writing a utility library that does not control the initialization process). For more precise control, individual `Tracer` objects can be used instead of the global tracer.

### Span manager (experimental)

This library supports span activation in the spirit of the [Scope Manager](https://github.com/opentracing/specification/blob/f7ca62c9/rfc/scope_manager.md) draft RFC.

The intention is that it remains active within the executed function and its transitive call graph, including both synchronous and asynchronous calls.

```js
tracer.activeSpan() // null
tracer.activate(span, () => {
tracer.activeSpan() // span
setTimeout(() => {
tracer.activeSpan() // span
}, 0);
(async () => {
tracer.activeSpan() // span
})();
});
tracer.activeSpan() // null
```

JavaScript support for continuation local storage is a patchwork.
This library includes simple wrappers around a few common APIs for continuation tracing.

**ZoneSpanManger**

This uses [Zone.js](https://github.com/angular/zone.js). (See the associated [Zone](https://github.com/domenic/zones) ES TC39 proposal.)
It includes support for most common APIs: Web, Node.js, Electron, RxJS. Async syntax (async/await) is not supported.
I.e. you should target ES 2015 or earlier syntax.

```js
import 'zone.js';
import { ZoneSpanManager } from 'opentracing/zone_span_manager';

new ZoneSpanManager();
```

**AsyncHookSpanManager**

This uses the Node.js [async_hooks](https://nodejs.org/api/async_hooks.html) API, available in Node.js 8.1.x+.

```js
import { AsyncHookSpanManager } from 'opentracing/async_hook_span_manager';

new AsyncHookSpanManager();
```

**AsyncWrapSpanManager**

This uses [async-hook-jl](https://github.com/Jeff-Lewis/async-hook-jl) which patches the Node.js AsyncWrap API, available in Node.js 0.11.x - 7.x.x. Though without futher transpilation async-hook-jl requires Node.js 4.x.x+.

```js
import { AsyncWrapSpanManager } from 'opentracing/async_wrap_span_manager';

new AsyncWrapSpanManager();
```

## API Documentation

There is a hosted copy of the current generated [ESDoc API Documentation here](https://opentracing-javascript.surge.sh).
Expand Down
Loading

0 comments on commit 0974d2f

Please sign in to comment.