15
15
using GitHub . DistributedTask . Pipelines . ContextData ;
16
16
using GitHub . DistributedTask . Pipelines . ObjectTemplating ;
17
17
using GitHub . DistributedTask . WebApi ;
18
- using GitHub . Runner . Common . Util ;
19
18
using GitHub . Runner . Common ;
19
+ using GitHub . Runner . Common . Util ;
20
20
using GitHub . Runner . Sdk ;
21
21
using GitHub . Runner . Worker . Container ;
22
22
using GitHub . Services . WebApi ;
@@ -52,8 +52,7 @@ public interface IExecutionContext : IRunnerService
52
52
Dictionary < string , string > IntraActionState { get ; }
53
53
Dictionary < string , VariableValue > JobOutputs { get ; }
54
54
ActionsEnvironmentReference ActionsEnvironment { get ; }
55
- List < ActionsStepTelemetry > ActionsStepsTelemetry { get ; }
56
- List < JobTelemetry > JobTelemetry { get ; }
55
+ ActionsStepTelemetry StepTelemetry { get ; }
57
56
DictionaryContextData ExpressionValues { get ; }
58
57
IList < IFunctionInfo > ExpressionFunctions { get ; }
59
58
JobContext JobContext { get ; }
@@ -109,6 +108,7 @@ public interface IExecutionContext : IRunnerService
109
108
// others
110
109
void ForceTaskComplete ( ) ;
111
110
void RegisterPostJobStep ( IStep step ) ;
111
+ void PublishStepTelemetry ( ) ;
112
112
}
113
113
114
114
public sealed class ExecutionContext : RunnerService , IExecutionContext
@@ -139,6 +139,7 @@ public sealed class ExecutionContext : RunnerService, IExecutionContext
139
139
140
140
// only job level ExecutionContext will track throttling delay.
141
141
private long _totalThrottlingDelayInMilliseconds = 0 ;
142
+ private bool _stepTelemetryPublished = false ;
142
143
143
144
public Guid Id => _record . Id ;
144
145
public Guid EmbeddedId { get ; private set ; }
@@ -152,8 +153,7 @@ public sealed class ExecutionContext : RunnerService, IExecutionContext
152
153
public Dictionary < string , VariableValue > JobOutputs { get ; private set ; }
153
154
154
155
public ActionsEnvironmentReference ActionsEnvironment { get ; private set ; }
155
- public List < ActionsStepTelemetry > ActionsStepsTelemetry { get ; private set ; }
156
- public List < JobTelemetry > JobTelemetry { get ; private set ; }
156
+ public ActionsStepTelemetry StepTelemetry { get ; } = new ActionsStepTelemetry ( ) ;
157
157
public DictionaryContextData ExpressionValues { get ; } = new DictionaryContextData ( ) ;
158
158
public IList < IFunctionInfo > ExpressionFunctions { get ; } = new List < IFunctionInfo > ( ) ;
159
159
@@ -273,9 +273,9 @@ public void RegisterPostJobStep(IStep step)
273
273
{
274
274
Trace . Info ( $ "'post' of '{ actionRunner . DisplayName } ' already push to child post step stack.") ;
275
275
}
276
- else
276
+ else
277
277
{
278
- Root . EmbeddedStepsWithPostRegistered [ actionRunner . Action . Id ] = actionRunner . Condition ;
278
+ Root . EmbeddedStepsWithPostRegistered [ actionRunner . Action . Id ] = actionRunner . Condition ;
279
279
}
280
280
return ;
281
281
}
@@ -294,7 +294,20 @@ public void RegisterPostJobStep(IStep step)
294
294
Root . PostJobSteps . Push ( step ) ;
295
295
}
296
296
297
- public IExecutionContext CreateChild ( Guid recordId , string displayName , string refName , string scopeName , string contextName , ActionRunStage stage , Dictionary < string , string > intraActionState = null , int ? recordOrder = null , IPagingLogger logger = null , bool isEmbedded = false , CancellationTokenSource cancellationTokenSource = null , Guid embeddedId = default ( Guid ) , string siblingScopeName = null )
297
+ public IExecutionContext CreateChild (
298
+ Guid recordId ,
299
+ string displayName ,
300
+ string refName ,
301
+ string scopeName ,
302
+ string contextName ,
303
+ ActionRunStage stage ,
304
+ Dictionary < string , string > intraActionState = null ,
305
+ int ? recordOrder = null ,
306
+ IPagingLogger logger = null ,
307
+ bool isEmbedded = false ,
308
+ CancellationTokenSource cancellationTokenSource = null ,
309
+ Guid embeddedId = default ( Guid ) ,
310
+ string siblingScopeName = null )
298
311
{
299
312
Trace . Entering ( ) ;
300
313
@@ -306,7 +319,6 @@ public void RegisterPostJobStep(IStep step)
306
319
child . Stage = stage ;
307
320
child . EmbeddedId = embeddedId ;
308
321
child . SiblingScopeName = siblingScopeName ;
309
- child . JobTelemetry = JobTelemetry ;
310
322
if ( intraActionState == null )
311
323
{
312
324
child . IntraActionState = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
@@ -354,7 +366,13 @@ public void RegisterPostJobStep(IStep step)
354
366
/// An embedded execution context shares the same record ID, record name, logger,
355
367
/// and a linked cancellation token.
356
368
/// </summary>
357
- public IExecutionContext CreateEmbeddedChild ( string scopeName , string contextName , Guid embeddedId , ActionRunStage stage , Dictionary < string , string > intraActionState = null , string siblingScopeName = null )
369
+ public IExecutionContext CreateEmbeddedChild (
370
+ string scopeName ,
371
+ string contextName ,
372
+ Guid embeddedId ,
373
+ ActionRunStage stage ,
374
+ Dictionary < string , string > intraActionState = null ,
375
+ string siblingScopeName = null )
358
376
{
359
377
return Root . CreateChild ( _record . Id , _record . Name , _record . Id . ToString ( "N" ) , scopeName , contextName , stage , logger : _logger , isEmbedded : true , cancellationTokenSource : CancellationTokenSource . CreateLinkedTokenSource ( _cancellationTokenSource . Token ) , intraActionState : intraActionState , embeddedId : embeddedId , siblingScopeName : siblingScopeName ) ;
360
378
}
@@ -404,6 +422,8 @@ public TaskResult Complete(TaskResult? result = null, string currentOperation =
404
422
}
405
423
}
406
424
425
+ PublishStepTelemetry ( ) ;
426
+
407
427
if ( Root != this )
408
428
{
409
429
// only dispose TokenSource for step level ExecutionContext
@@ -654,16 +674,18 @@ public void InitializeJob(Pipelines.AgentJobRequestMessage message, Cancellation
654
674
// Job defaults shared across all actions
655
675
Global . JobDefaults = new Dictionary < string , IDictionary < string , string > > ( StringComparer . OrdinalIgnoreCase ) ;
656
676
677
+ // Job Telemetry
678
+ Global . JobTelemetry = new List < JobTelemetry > ( ) ;
679
+
680
+ // ActionsStepTelemetry for entire job
681
+ Global . StepsTelemetry = new List < ActionsStepTelemetry > ( ) ;
682
+
657
683
// Job Outputs
658
684
JobOutputs = new Dictionary < string , VariableValue > ( StringComparer . OrdinalIgnoreCase ) ;
659
685
660
686
// Actions environment
661
687
ActionsEnvironment = message . ActionsEnvironment ;
662
688
663
- // ActionsStepTelemetry
664
- ActionsStepsTelemetry = new List < ActionsStepTelemetry > ( ) ;
665
-
666
- JobTelemetry = new List < JobTelemetry > ( ) ;
667
689
668
690
// Service container info
669
691
Global . ServiceContainers = new List < ContainerInfo > ( ) ;
@@ -895,6 +917,24 @@ public IEnumerable<IssueMatcherConfig> GetMatchers()
895
917
return Root . _matchers ?? Array . Empty < IssueMatcherConfig > ( ) ;
896
918
}
897
919
920
+ public void PublishStepTelemetry ( )
921
+ {
922
+ if ( ! _stepTelemetryPublished )
923
+ {
924
+ // Add to the global steps telemetry only if we have something to log.
925
+ if ( ! string . IsNullOrEmpty ( StepTelemetry ? . Type ) )
926
+ {
927
+ Trace . Info ( $ "Publish step telemetry for current step { StringUtil . ConvertToJson ( StepTelemetry ) } .") ;
928
+ Global . StepsTelemetry . Add ( StepTelemetry ) ;
929
+ _stepTelemetryPublished = true ;
930
+ }
931
+ }
932
+ else
933
+ {
934
+ Trace . Info ( $ "Step telemetry has already been published.") ;
935
+ }
936
+ }
937
+
898
938
private void InitializeTimelineRecord ( Guid timelineId , Guid timelineRecordId , Guid ? parentTimelineRecordId , string recordType , string displayName , string refName , int ? order )
899
939
{
900
940
_mainTimelineId = timelineId ;
0 commit comments