@@ -140,31 +140,35 @@ export class TraceWriter extends common.Service {
140140
141141 this . getHostname ( ( hostname ) => {
142142 this . getInstanceId ( ( instanceId ) => {
143- const labels : LabelObject = { } ;
144- labels [ TraceLabels . AGENT_DATA ] =
145- 'node ' + pjson . name + ' v' + pjson . version ;
146- labels [ TraceLabels . GCE_HOSTNAME ] = hostname ;
143+ // tslint:disable-next-line:no-any
144+ const addDefaultLabel = ( key : string , value : any ) => {
145+ this . defaultLabels [ key ] = `${ value } ` ;
146+ } ;
147+
148+ this . defaultLabels = { } ;
149+ addDefaultLabel (
150+ TraceLabels . AGENT_DATA , `node ${ pjson . name } v${ pjson . version } ` ) ;
151+ addDefaultLabel ( TraceLabels . GCE_HOSTNAME , hostname ) ;
147152 if ( instanceId ) {
148- labels [ TraceLabels . GCE_INSTANCE_ID ] = instanceId ;
153+ addDefaultLabel ( TraceLabels . GCE_INSTANCE_ID , instanceId ) ;
149154 }
150155 const moduleName = this . config . serviceContext . service || hostname ;
151- labels [ TraceLabels . GAE_MODULE_NAME ] = moduleName ;
156+ addDefaultLabel ( TraceLabels . GAE_MODULE_NAME , moduleName ) ;
152157
153158 const moduleVersion = this . config . serviceContext . version ;
154159 if ( moduleVersion ) {
155- labels [ TraceLabels . GAE_MODULE_VERSION ] = moduleVersion ;
160+ addDefaultLabel ( TraceLabels . GAE_MODULE_VERSION , moduleVersion ) ;
156161 const minorVersion = this . config . serviceContext . minorVersion ;
157162 if ( minorVersion ) {
158163 let versionLabel = '' ;
159164 if ( moduleName !== 'default' ) {
160165 versionLabel = moduleName + ':' ;
161166 }
162167 versionLabel += moduleVersion + '.' + minorVersion ;
163- labels [ TraceLabels . GAE_VERSION ] = versionLabel ;
168+ addDefaultLabel ( TraceLabels . GAE_VERSION , versionLabel ) ;
164169 }
165170 }
166- Object . freeze ( labels ) ;
167- this . defaultLabels = labels ;
171+ Object . freeze ( this . defaultLabels ) ;
168172 if ( -- pendingOperations === 0 ) {
169173 cb ( ) ;
170174 }
@@ -192,7 +196,7 @@ export class TraceWriter extends common.Service {
192196 } ) ;
193197 }
194198
195- getInstanceId ( cb : ( instanceId ?: string ) => void ) {
199+ getInstanceId ( cb : ( instanceId ?: number ) => void ) {
196200 gcpMetadata . instance ( { property : 'id' , headers} )
197201 . then ( ( res ) => {
198202 cb ( res . data ) ; // instance ID
0 commit comments