@@ -124,7 +124,8 @@ describe('Top level API', () => {
124124 expect ( log . body ) . to . equal ( 'This is a test error' ) ;
125125 expect ( log . attributes ) . to . deep . equal ( {
126126 'error.type' : 'TestError' ,
127- 'error.stack' : '...stack trace...'
127+ 'error.stack' : '...stack trace...' ,
128+ 'app.version' : 'unset'
128129 } ) ;
129130 } ) ;
130131
@@ -140,7 +141,8 @@ describe('Top level API', () => {
140141 expect ( log . body ) . to . equal ( 'error with no stack' ) ;
141142 expect ( log . attributes ) . to . deep . equal ( {
142143 'error.type' : 'Error' ,
143- 'error.stack' : 'No stack trace available'
144+ 'error.stack' : 'No stack trace available' ,
145+ 'app.version' : 'unset'
144146 } ) ;
145147 } ) ;
146148
@@ -151,7 +153,9 @@ describe('Top level API', () => {
151153 const log = emittedLogs [ 0 ] ;
152154 expect ( log . severityNumber ) . to . equal ( SeverityNumber . ERROR ) ;
153155 expect ( log . body ) . to . equal ( 'a string error' ) ;
154- expect ( log . attributes ) . to . deep . equal ( { } ) ;
156+ expect ( log . attributes ) . to . deep . equal ( {
157+ 'app.version' : 'unset'
158+ } ) ;
155159 } ) ;
156160
157161 it ( 'should capture an unknown error type correctly' , ( ) => {
@@ -161,7 +165,9 @@ describe('Top level API', () => {
161165 const log = emittedLogs [ 0 ] ;
162166 expect ( log . severityNumber ) . to . equal ( SeverityNumber . ERROR ) ;
163167 expect ( log . body ) . to . equal ( 'Unknown error type: number' ) ;
164- expect ( log . attributes ) . to . deep . equal ( { } ) ;
168+ expect ( log . attributes ) . to . deep . equal ( {
169+ 'app.version' : 'unset'
170+ } ) ;
165171 } ) ;
166172
167173 it ( 'should propagate trace context' , async ( ) => {
@@ -187,6 +193,7 @@ describe('Top level API', () => {
187193 expect ( emittedLogs [ 0 ] . attributes ) . to . deep . equal ( {
188194 'error.type' : 'TestError' ,
189195 'error.stack' : '...stack trace...' ,
196+ 'app.version' : 'unset' ,
190197 'logging.googleapis.com/trace' : `projects/${ PROJECT_ID } /traces/my-trace` ,
191198 'logging.googleapis.com/spanId' : `my-span`
192199 } ) ;
@@ -211,6 +218,7 @@ describe('Top level API', () => {
211218 expect ( log . attributes ) . to . deep . equal ( {
212219 'error.type' : 'TestError' ,
213220 'error.stack' : '...stack trace...' ,
221+ 'app.version' : 'unset' ,
214222 strAttr : 'string attribute' ,
215223 mapAttr : {
216224 boolAttr : true ,
@@ -219,6 +227,24 @@ describe('Top level API', () => {
219227 arrAttr : [ 1 , 2 , 3 ]
220228 } ) ;
221229 } ) ;
230+
231+ it ( 'should use explicit app version when provided' , ( ) => {
232+ const telemetry = new TelemetryService (
233+ fakeTelemetry . app ,
234+ fakeTelemetry . loggerProvider
235+ ) ;
236+ telemetry . options = {
237+ appVersion : '1.0.0'
238+ } ;
239+
240+ captureError ( telemetry , 'a string error' ) ;
241+
242+ expect ( emittedLogs . length ) . to . equal ( 1 ) ;
243+ const log = emittedLogs [ 0 ] ;
244+ expect ( log . attributes ) . to . deep . equal ( {
245+ 'app.version' : '1.0.0'
246+ } ) ;
247+ } ) ;
222248 } ) ;
223249
224250 describe ( 'flush()' , ( ) => {
0 commit comments