-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow "disabling" cls, and relax requirements for creating root…
- Loading branch information
Showing
15 changed files
with
241 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {Logger} from '@google-cloud/common'; | ||
import * as assert from 'assert'; | ||
import * as semver from 'semver'; | ||
import * as util from 'util'; | ||
|
||
import {TraceCLSConfig, TraceCLSMechanism} from '../src/cls'; | ||
|
||
import * as trace from './trace'; | ||
|
||
describe('Behavior set by config for context propagation mechanism', () => { | ||
const useAH = semver.satisfies(process.version, '>=8') && | ||
!!process.env.GCLOUD_TRACE_NEW_CONTEXT; | ||
const autoMechanism = | ||
useAH ? TraceCLSMechanism.ASYNC_HOOKS : TraceCLSMechanism.ASYNC_LISTENER; | ||
let capturedConfig: TraceCLSConfig|null; | ||
|
||
class CaptureConfigTestCLS extends trace.TestCLS { | ||
constructor(logger: Logger, config: TraceCLSConfig) { | ||
super(logger, config); | ||
// Capture the config object passed into this constructor. | ||
capturedConfig = config; | ||
} | ||
} | ||
|
||
beforeEach(() => { | ||
capturedConfig = null; | ||
}); | ||
|
||
before(() => { | ||
trace.setCLS(CaptureConfigTestCLS); | ||
}); | ||
|
||
after(() => { | ||
trace.setCLS(trace.TestCLS); | ||
}); | ||
|
||
const testCases: Array< | ||
{tracingConfig: trace.Config, contextPropagationConfig: TraceCLSConfig}> = | ||
[ | ||
{ | ||
tracingConfig: {clsMechanism: 'none'}, | ||
contextPropagationConfig: {mechanism: 'none'} | ||
}, | ||
{ | ||
tracingConfig: {clsMechanism: 'auto'}, | ||
contextPropagationConfig: {mechanism: autoMechanism} | ||
}, | ||
{ | ||
tracingConfig: {}, | ||
contextPropagationConfig: {mechanism: autoMechanism} | ||
}, | ||
{ | ||
// tslint:disable:no-any | ||
tracingConfig: {clsMechanism: 'unknown' as any}, | ||
contextPropagationConfig: {mechanism: 'unknown' as any} | ||
// tslint:enable:no-any | ||
} | ||
]; | ||
|
||
for (const testCase of testCases) { | ||
it(`should be as expected for config: ${ | ||
util.inspect(testCase.tracingConfig)}`, | ||
() => { | ||
trace.start(testCase.tracingConfig); | ||
assert.ok(capturedConfig); | ||
assert.strictEqual( | ||
capturedConfig!.mechanism, | ||
testCase.contextPropagationConfig.mechanism); | ||
}); | ||
} | ||
}); |
Oops, something went wrong.