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

Commit 98c21ac

Browse files
committed
Implement a form of the Scope Manager RFC
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
1 parent 0f14554 commit 98c21ac

17 files changed

+1422
-906
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ node_js:
55

66
env:
77
matrix:
8-
- TEST_NODE_VERSION=0.10
8+
- TEST_NODE_VERSION=0.10 TEST_ZONE_JS=true
99
- TEST_NODE_VERSION=0.12
10+
- TEST_NODE_VERSION=0.12 TEST_ZONE_JS=true
1011
- TEST_NODE_VERSION=4
12+
- TEST_NODE_VERSION=4 TEST_ZONE_JS=true
1113
- TEST_NODE_VERSION=6
12-
- TEST_NODE_VERSION=node
14+
- TEST_NODE_VERSION=6 TEST_ZONE_JS=true
15+
- TEST_NODE_VERSION=8
16+
- TEST_NODE_VERSION=8 TEST_ZONE_JS=true
17+
- TEST_NODE_VERSION=10
18+
- TEST_NODE_VERSION=10 TEST_ZONE_JS=true
1319
global:
1420
- secure: CV7Q6AHwuTCg2yi5iHC9mNexD7dgPoroZ1qdV8h+AAMUHFjO9GvCDy295l0zpqqJSb+b24GxPjx2gzK2klWMm0B55HORTBAbqJB8O7Y3dDtjycHZK23n5ph/JqhCGm4/XhxTmgDngF+0C98uWLvFKILYpTadWuOudLCc/NP4p4xykHeL2XgNA4TMg+FMYCy0k0/Xy5GNsjeHeQCJm3G1caX8jbQCRsoOiFol7Md/m5llXvY6KQzbmpis2LbPTM2mla8Ixn7bAdBX65xzcBjoWJ0dIrOghTh0z0AnEThYZHBWSvOwAkiVM3el3a4sfyUlvUfLn1ZPCK8u20uD3FQLL/q3aijmqiDORa0a6nJ67D6glRDjW1IgOyJ1iXL9GUzKBnrfdR2S78kSYGEyYDqd5Mro7InnkQ+5wgOUka0VHsJAv79tFe4ylOy3FNWzgXLmao7X/SsmV6LTXg99OpNB3zWPyFm48e5XCfWk2XR2jbeFAXc7u9W6WHWySUMpoB11FzdvNwldkE87Px8TK1guGriNSkrPk3/Abp0S+/Ka43pf+WAG2OA8DgQ2WIvCIr0ZmosS73Seg+s+MGQH9V78iFaSByEquPMbVE+3vxtl04KkRLJ1zhJ6R9CRGYKb7xiHEwCAFNMw2J8Wi5VjvvuhbkZz2D0Hn/qoEKJDkIFvzkA=
1521
- secure: zrC64PU+T1nPdmTOCXcm+zb/f009yobySOB5YOxtlRakceIoWplJrMxlS03Z4cNCq6F3NHfPhrB8kTgNny7jSa6zP4nud2zBgWBPefgDRyR/QHaE69drcrklWM4QQz/ApUvoT2/X9e02cvDqaeENNIQlw3nJwprqeizZkbjta0+zzF2SQOSFXpjSzHSprQWaAeYBEd9KzACEL2LbejXzYPJUDGxhCBwTafRw48Ur5bp5pEazU3Tv3uRKqW6TAuZx0W5JiWoY7PVx6AlKDiTvtp6ayrCheIwzaOiHStXtn0V7+J5EKfrux30TNVeEvcXrerkdW5LJAPxKbQfj8FMat8GM7Qil35o2/KT6TFjxjiyXgMAJJg+fBlfzmcTpeI9VR/akrCmHon36w9Asgsmjuj5HEG/wbw2jRHH4C3S+J3BwAdWXW9iNkubZyLnyTlGPCm/79xdmqOx5mV0+9xc6Cfr74Gi53mE2XDpC5WD5iAGdS8xLfJNK8J6l5GAPw34gOENt40c7xXYMRx7luHZmV7BDyGW0VcA6dg33sJ2B0nd9tSvwvQpz+d/Nm6R4zRf4JQRS8VS8WYMXTW3/bPt3HbvWdsBICBMs5BcKUxszscgMJW0Ut0/Jsz3o1JEWZy3Gn8y3HJ3zcSke1GFqFNHPWGe2jQ0Rh/ainC+wCXDKkAI=

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,62 @@ const tracer = opentracing.globalTracer();
105105

106106
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.
107107

108+
### Span manager (experimental)
109+
110+
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.
111+
112+
The intention is that it remains active within the executed function and its transitive call graph, including both synchronous and asynchronous calls.
113+
114+
```js
115+
tracer.activeSpan() // null
116+
tracer.activate(span, () => {
117+
tracer.activeSpan() // span
118+
setTimeout(() => {
119+
tracer.activeSpan() // span
120+
}, 0);
121+
(async () => {
122+
tracer.activeSpan() // span
123+
})();
124+
});
125+
tracer.activeSpan() // null
126+
```
127+
128+
JavaScript support for continuation local storage is a patchwork.
129+
This library includes simple wrappers around a few common APIs for continuation tracing.
130+
131+
**ZoneSpanManger**
132+
133+
This uses [Zone.js](https://github.com/angular/zone.js). (See the associated [Zone](https://github.com/domenic/zones) ES TC39 proposal.)
134+
It includes support for most common APIs: Web, Node.js, Electron, RxJS. Async syntax (async/await) is not supported.
135+
I.e. you should target ES 2015 or earlier syntax.
136+
137+
```js
138+
import 'zone.js';
139+
import { ZoneSpanManager } from 'opentracing/zone_span_manager';
140+
141+
new ZoneSpanManager();
142+
```
143+
144+
**AsyncHookSpanManager**
145+
146+
This uses the Node.js [async_hooks](https://nodejs.org/api/async_hooks.html) API, available in Node.js 8.1.x+.
147+
148+
```js
149+
import { AsyncHookSpanManager } from 'opentracing/async_hook_span_manager';
150+
151+
new AsyncHookSpanManager();
152+
```
153+
154+
**AsyncWrapSpanManager**
155+
156+
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+.
157+
158+
```js
159+
import { AsyncWrapSpanManager } from 'opentracing/async_wrap_span_manager';
160+
161+
new AsyncWrapSpanManager();
162+
```
163+
108164
## API Documentation
109165

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

0 commit comments

Comments
 (0)