@@ -40,15 +40,20 @@ describe("DefaultTelemetryClient", () => {
4040 metricSinks : [ fileSystemSink ] ,
4141 } ) ;
4242
43- const recorder = client . getAttributesRecorder ( "cli.command_run" , {
43+ const metricEvent = client . startMetricEvent ( "cli.command_run" , {
4444 exit_reason : "success" ,
4545 command_path : "/agentcore" ,
4646 } ) ;
4747
48- await client . emit ( "cli.command_run" , 123 , recorder ) ;
48+ await metricEvent . end ( 123 ) ;
4949
50- recorder . record ( { exit_reason : "failure" } ) ;
51- await client . emit ( "cli.command_run" , 456 , recorder ) ;
50+ // Start a second event with failure
51+ const metricEvent2 = client . startMetricEvent ( "cli.command_run" , {
52+ exit_reason : "failure" ,
53+ command_path : "/agentcore" ,
54+ } ) ;
55+
56+ await metricEvent2 . end ( 456 ) ;
5257 await client . shutdown ( ) ;
5358
5459 expect ( fileSystemSink . getName ( ) ) . toBe ( "FileSystemSink" ) ;
@@ -129,24 +134,20 @@ describe("DefaultTelemetryClient", () => {
129134 auditFilePath,
130135 } ) ;
131136
132- await enabledClient . emit (
133- "cli.command_run" ,
134- 123 ,
135- enabledClient . getAttributesRecorder ( "cli.command_run" , {
136- exit_reason : "success" ,
137- command_path : "/agentcore" ,
138- is_tui : true ,
139- } ) ,
140- ) ;
141- await disabledClient . emit (
142- "cli.command_run" ,
143- 123 ,
144- enabledClient . getAttributesRecorder ( "cli.command_run" , {
145- exit_reason : "failure" ,
146- command_path : "/agentcore" ,
147- is_tui : false ,
148- } ) ,
149- ) ;
137+ const enabledEvent = enabledClient . startMetricEvent ( "cli.command_run" , {
138+ exit_reason : "success" ,
139+ command_path : "/agentcore" ,
140+ is_tui : true ,
141+ } ) ;
142+ await enabledEvent . end ( 123 ) ;
143+
144+ const disabledEvent = disabledClient . startMetricEvent ( "cli.command_run" , {
145+ exit_reason : "failure" ,
146+ command_path : "/agentcore" ,
147+ is_tui : false ,
148+ } ) ;
149+ await disabledEvent . end ( 123 ) ;
150+
150151 await Promise . all ( [ enabledClient . shutdown ( ) , disabledClient . shutdown ( ) ] ) ;
151152
152153 const auditLines = ( await readFile ( auditFilePath , "utf8" ) ) . trimEnd ( ) . split ( "\n" ) ;
@@ -170,17 +171,17 @@ describe("DefaultTelemetryClient", () => {
170171 } ) ;
171172 } ) ;
172173
173- test ( "throws when recorder has incomplete attributes" , async ( ) => {
174+ test ( "throws when metric event has incomplete attributes" , async ( ) => {
174175 const client = new DefaultTelemetryClient ( {
175176 logger,
176177 sessionId : "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" ,
177178 globalConfigAccessor : new TestGlobalConfigAccessor ( ) ,
178179 metricSinks : [ ] ,
179180 } ) ;
180181
181- const recorder = client . getAttributesRecorder ( "cli.command_run" ) ;
182+ const metricEvent = client . startMetricEvent ( "cli.command_run" ) ;
182183
183- expect ( ( ) => client . emit ( "cli.command_run" , 100 , recorder ) ) . toThrow ( ) ;
184+ await expect ( metricEvent . end ( 100 ) ) . rejects . toThrow ( ) ;
184185 await client . shutdown ( ) ;
185186 } ) ;
186187
@@ -197,11 +198,11 @@ describe("DefaultTelemetryClient", () => {
197198 globalConfigAccessor : new TestGlobalConfigAccessor ( ) ,
198199 metricSinks : [ sink ] ,
199200 } ) ;
200- const recorder = client . getAttributesRecorder ( "cli.command_run" , {
201+ const metricEvent = client . startMetricEvent ( "cli.command_run" , {
201202 exit_reason : "success" ,
202203 command_path : "/agentcore" ,
203204 } ) ;
204- await client . emit ( "cli.command_run" , 1 , recorder ) ;
205+ await metricEvent . end ( 1 ) ;
205206 await client . shutdown ( ) ;
206207
207208 await assertLogsMatch ( tempDir , [
@@ -241,13 +242,13 @@ describe("DefaultTelemetryClient", () => {
241242 metricSinks : [ badSink , goodSink ] ,
242243 } ) ;
243244
244- const recorder = client . getAttributesRecorder ( "cli.command_run" , {
245+ const metricEvent = client . startMetricEvent ( "cli.command_run" , {
245246 exit_reason : "success" ,
246247 command_path : "/agentcore" ,
247248 } ) ;
248249
249- // emit should not throw even though the sink's record () throws
250- await client . emit ( "cli.command_run" , 100 , recorder ) ;
250+ // end should not throw even though the sink's send () throws
251+ await metricEvent . end ( 100 ) ;
251252 // shutdown should not throw even though the sink's shutdown() rejects
252253 await client . shutdown ( ) ;
253254
0 commit comments