Skip to content

Commit

Permalink
added skipped steps logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dpacheconr committed Nov 10, 2023
1 parent 275dee8 commit 5a3adcb
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
p_sub_context = trace.set_span_in_context(child_0)

# Steps trace span
for step in job['steps']:
for index,step in enumerate(job['steps']):
# Set steps tracer and logger
resource_attributes ={SERVICE_NAME: GHA_SERVICE_NAME,"github.source": "github-exporter","github.resource.type": "span","workflow_run_id": GHA_RUN_ID}
resource_log = Resource(attributes=resource_attributes)
Expand All @@ -108,8 +108,17 @@
resource_attributes.update(create_resource_attributes(parse_attributes(step,""),GHA_SERVICE_NAME))
resource_log = Resource(attributes=resource_attributes)
job_logger = get_logger(endpoint,headers,resource_log, "job_logger")

child_1 = step_tracer.start_span(name=str(step['name']),start_time=do_time(step['started_at']),context=p_sub_context,kind=trace.SpanKind.CONSUMER)

if step['conclusion'] == 'skipped':
if index >= 1:
# Start time should be the previous step end time
step_started_at=job['steps'][index - 1]['completed_at']
else:
step_started_at=job['started_at']
else:
step_started_at=step['started_at']

child_1 = step_tracer.start_span(name=str(step['name']),start_time=do_time(step_started_at),context=p_sub_context,kind=trace.SpanKind.CONSUMER)
child_1.set_attributes(create_resource_attributes(parse_attributes(step,""),GHA_SERVICE_NAME))
with trace.use_span(child_1, end_on_exit=False):
# Parse logs
Expand Down Expand Up @@ -137,7 +146,17 @@
except IOError as e:
print("Log file does not exist: "+str(job["name"])+"/"+str(step['number'])+"_"+str(step['name'].replace("/",""))+".txt")

child_1.end(end_time=do_time(step['completed_at']))
if step['conclusion'] == 'skipped':
child_1.update_name(name=str(step['name']+"-SKIPPED"))
if index >= 1:
#End time should be the previous step end time
step_completed_at=job['steps'][index - 1]['completed_at']
else:
step_completed_at=job['started_at']
else:
step_completed_at=step['completed_at']

child_1.end(end_time=do_time(step_completed_at))
child_0.end(end_time=do_time(job['completed_at']))
workflow_run_finish_time=do_time(job['completed_at'])
p_parent.end(end_time=workflow_run_finish_time)
Expand Down

0 comments on commit 5a3adcb

Please sign in to comment.