-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add options to set the cls mechanism to async-hooks or async-listener #741
Conversation
Codecov Report
@@ Coverage Diff @@
## master #741 +/- ##
=========================================
Coverage ? 91.15%
=========================================
Files ? 31
Lines ? 1595
Branches ? 312
=========================================
Hits ? 1454
Misses ? 60
Partials ? 81
Continue to review full report at Codecov.
|
src/index.ts
Outdated
const agentEnabled = !config || config.enabled !== false; | ||
const alAutoPreferred = | ||
!ahAvailable && (!config || config.clsMechanism === 'auto'); | ||
const alUserPreferred = config && (config.clsMechanism === 'async-listener'); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
82bc9f7
to
1990e4a
Compare
src/index.ts
Outdated
@@ -1,5 +1,5 @@ | |||
/** | |||
* Copyright 2015 Google Inc. All Rights Reserved. | |||
* Copyright 2018 Google LLC |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/index.ts
Outdated
'Disabling trace agent.'); | ||
stop(); | ||
return traceAgent; | ||
throw e; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/index.ts
Outdated
// This code path maintains the current contract that calling get() before | ||
// start() yields a disabled custom span API. It assumes that the use case | ||
// for doing so (instead of returning null) is when get() is called in | ||
// a file where it is unknown whether start() has been called. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
1fbcd68
to
409693a
Compare
src/tracing.ts
Outdated
* Constructs a new Tracing instance. | ||
* @param config The configuration for this instance. | ||
*/ | ||
constructor(config: NormalizedConfig, traceAgent: TraceAgent) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/tracing.ts
Outdated
*/ | ||
enable(): void { | ||
if (this.traceAgent.isActive()) { | ||
// For unit tests only. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/tracing.ts
Outdated
|
||
this.traceAgent.enable(this.config, this.logger); | ||
|
||
pluginLoader.create(this.config, this.logger).activate(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/tracing.ts
Outdated
this.traceAgent.enable(this.config, this.logger); | ||
|
||
pluginLoader.create(this.config, this.logger).activate(); | ||
} catch (e) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting there. One more round.
src/tracing.ts
Outdated
constructor( | ||
config: NormalizedConfig, private readonly traceAgent: TraceAgent) { | ||
this.config = config; | ||
this.traceAgent = traceAgent; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/tracing.ts
Outdated
const clsConfig: Forceable<TraceCLSConfig> = { | ||
mechanism: this.config.clsMechanism as TraceCLSMechanism, | ||
[FORCE_NEW]: this.config[FORCE_NEW] | ||
}; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/tracing.ts
Outdated
this.disable(); | ||
} | ||
}); | ||
} catch (e) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This PR makesasync_hooks
-based Tracing the default option for tracing using Node 8+. To go back to usingasync-listener
(viacontinuation-local-storage
), newconfig.clsMechanism
options are accepted:async-listener
(andasync-hooks
).This PR provides two new possible values for
config.clsMechanism
:async-listener
andasync-hooks
.Because context tracking is now specified as a config option rather than strictly as an environmental variable, a fair bit of refactoring is needed to support conditionally loading
continuation-local-storage
as late as possible. The constraints to satisfy are as following:continuation-local-storage
needs to be loaded as early as possible, and definitely before any modules that do I/O.continuation-local-storage
must be loaded afterstart()
is called, so we know whether to load it (via the config option passed tostart
).To accomplish this, most of the logic in
index.ts
has been moved to a new file,tracing.ts
, where it is now encapsulated in a classTracing
. Barring thefeat:
change, there should be no behavioral changes; however there are some caveats that hopefully are captured in the added comments.There is also a small change to prevent
PluginLoader#deactivate
from throwing when being called on an already deactivated plugin loader. This is only required to prevent large-scale changes to tests, as the case when it might be called when the plugin loader is de-activated is from test code that sets the[FORCE_NEW]
flag in configuration objects.