@@ -34,7 +34,7 @@ import {PluginLoaderConfig} from './trace-plugin-loader';
3434import { pluginLoader } from './trace-plugin-loader' ;
3535import { TraceAgent } from './trace-api' ;
3636import { traceWriter , TraceWriterConfig } from './trace-writer' ;
37- import * as traceUtil from './util' ;
37+ import { Forceable , FORCE_NEW , packageNameFromPath } from './util' ;
3838
3939export { Config , PluginTypes } ;
4040
@@ -43,7 +43,7 @@ const traceAgent = new TraceAgent('Custom Span API');
4343const modulesLoadedBeforeTrace : string [ ] = [ ] ;
4444const traceModuleName = path . join ( '@google-cloud' , 'trace-agent' ) ;
4545for ( let i = 0 ; i < filesLoadedBeforeTrace . length ; i ++ ) {
46- const moduleName = traceUtil . packageNameFromPath ( filesLoadedBeforeTrace [ i ] ) ;
46+ const moduleName = packageNameFromPath ( filesLoadedBeforeTrace [ i ] ) ;
4747 if ( moduleName && moduleName !== traceModuleName &&
4848 modulesLoadedBeforeTrace . indexOf ( moduleName ) === - 1 ) {
4949 modulesLoadedBeforeTrace . push ( moduleName ) ;
@@ -53,12 +53,10 @@ for (let i = 0; i < filesLoadedBeforeTrace.length; i++) {
5353interface TopLevelConfig {
5454 enabled : boolean ;
5555 logLevel : number ;
56- forceNewAgent_ : boolean ;
5756}
5857
5958// PluginLoaderConfig extends TraceAgentConfig
60- type NormalizedConfig = TraceWriterConfig & PluginLoaderConfig & TopLevelConfig &
61- { forceNewAgent_ : boolean } ;
59+ type NormalizedConfig = TraceWriterConfig & PluginLoaderConfig & TopLevelConfig ;
6260
6361/**
6462 * Normalizes the user-provided configuration object by adding default values
@@ -67,7 +65,8 @@ type NormalizedConfig = TraceWriterConfig&PluginLoaderConfig&TopLevelConfig&
6765 * be modified.
6866 * @return A normalized configuration object.
6967 */
70- function initConfig ( projectConfig : Config ) : NormalizedConfig {
68+ function initConfig ( projectConfig : Forceable < Config > ) :
69+ Forceable < NormalizedConfig > {
7170 const envConfig = {
7271 logLevel : Number ( process . env . GCLOUD_TRACE_LOGLEVEL ) || undefined ,
7372 projectId : process . env . GCLOUD_PROJECT ,
@@ -89,8 +88,8 @@ function initConfig(projectConfig: Config): NormalizedConfig {
8988 // 3. Environment Variable Set Configuration File (from GCLOUD_TRACE_CONFIG)
9089 // 4. Default Config (as specified in './config')
9190 const config = extend (
92- true , { forceNewAgent_ : false } , defaultConfig , envSetConfig , projectConfig ,
93- envConfig ) ;
91+ true , { [ FORCE_NEW ] : projectConfig [ FORCE_NEW ] } , defaultConfig ,
92+ envSetConfig , projectConfig , envConfig ) ;
9493
9594 // Enforce the upper limit for the label value size.
9695 if ( config . maximumLabelValueSize >
@@ -137,9 +136,9 @@ function stop() {
137136 * trace.start();
138137 */
139138export function start ( projectConfig ?: Config ) : PluginTypes . TraceAgent {
140- const config : NormalizedConfig = initConfig ( projectConfig || { } ) ;
139+ const config = initConfig ( projectConfig || { } ) ;
141140
142- if ( traceAgent . isActive ( ) && ! config . forceNewAgent_ ) { // already started.
141+ if ( traceAgent . isActive ( ) && ! config [ FORCE_NEW ] ) { // already started.
143142 throw new Error ( 'Cannot call start on an already started agent.' ) ;
144143 } else if ( traceAgent . isActive ( ) ) {
145144 // For unit tests only.
0 commit comments