Skip to content

Commit

Permalink
feat: add config.disableUntracedModulesWarn (#1070)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin authored Jul 18, 2019
1 parent 7cf423c commit f688e33
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export interface Config {
*/
logLevel?: number;

/**
* If set to true, prevents a warning from being emitted if modules are
* required before the Trace Agent.
*/
disableUntracedModulesWarning?: boolean;

/**
* Whether to enable to Trace Agent or not.
* Once enabled, the Trace Agent may not be disabled.
Expand Down Expand Up @@ -312,6 +318,7 @@ export interface Config {
*/
export const defaultConfig = {
logLevel: 1,
disableUntracedModulesWarning: false,
enabled: true,
enhancedDatabaseReporting: false,
rootSpanNameOverride: (name: string) => name,
Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function initConfig(userConfig: Forceable<Config>): TopLevelConfig {

return {
[FORCE_NEW]: forceNew,
disableUntracedModulesWarning: mergedConfig.disableUntracedModulesWarning,
enabled: mergedConfig.enabled,
logLevel: lastOf(
mergedConfig.logLevel,
Expand Down Expand Up @@ -230,7 +231,12 @@ export function start(config?: Config): PluginTypes.Tracer {
throw new Error('Cannot call start on an already created agent.');
}
tracing.enable();
tracing.logModulesLoadedBeforeTrace(filesLoadedBeforeTrace);
if (
normalizedConfig.enabled &&
!normalizedConfig.disableUntracedModulesWarning
) {
tracing.logModulesLoadedBeforeTrace(filesLoadedBeforeTrace);
}
return traceAgent;
} finally {
// Stop storing these entries in memory
Expand Down
1 change: 1 addition & 0 deletions src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type TopLevelConfig =
| Forceable<{
enabled: boolean;
logLevel: number;
disableUntracedModulesWarning: boolean;
clsConfig: Forceable<TraceCLSConfig>;
writerConfig: Forceable<TraceWriterConfig>;
pluginLoaderConfig: Forceable<PluginLoaderConfig>;
Expand Down
23 changes: 18 additions & 5 deletions test/test-modules-loaded-before-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import * as log from '../src/logger';
import {TestLogger} from './logger';
import * as testTraceModule from './trace';

const UNTRACED_LOGS_WARNING = /StackdriverTracer#start.*modules.*loaded.*before.*trace agent.*: \[.*shimmer.*\]/;

describe('modules loaded before agent', () => {
let logger: CaptureTestLogger;
let logger: CaptureTestLogger | null = null;

class CaptureTestLogger extends TestLogger {
constructor() {
Expand All @@ -40,14 +42,25 @@ describe('modules loaded before agent', () => {
shimmer.unwrap(log, 'Logger');
});

afterEach(() => {
logger = null;
});

it('should log if modules were loaded before agent', () => {
testTraceModule.start();
assert.ok(logger);
assert.strictEqual(
logger.getNumLogsWith(
'warn',
/StackdriverTracer#start.*modules.*loaded.*before.*trace agent.*: \[.*shimmer.*\]/
),
logger!.getNumLogsWith('warn', UNTRACED_LOGS_WARNING),
1
);
});

it('should not log if disableUntracedModulesWarning is set to true', () => {
testTraceModule.start({disableUntracedModulesWarning: true});
assert.ok(logger);
assert.strictEqual(
logger!.getNumLogsWith('warn', UNTRACED_LOGS_WARNING),
0
);
});
});

0 comments on commit f688e33

Please sign in to comment.