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

ScopeManager #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,64 @@ 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.

If neither `childOf` nor `references` is specified, create spans are children of the activated span.

The intent of `SpanManager` is that it remains active within the executed function and its transitive call graph. Ideally, this applies to 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be on tracer.scopeManager() instead?

```

JavaScript support for continuation local storage is a patchwork.
This library includes simple wrappers around a few common APIs for continuation contexts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be selected automatically for the user according to the environment. This will avoid the user needing extensive knowledge of all the possible ways to do context propagation in JavaScript.

I've mentioned how I think this should be selected at the bottom of #112 (comment)


**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**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since AsyncWrap cannot have multiple hooks, and has many bugs, possible crashes and memory leaks in older Node versions, I would probably skip it entirely and add something based on a fixed fork of async-listener as described in #112 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, in my experience it's also slower than async-listener.


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