Skip to content

Commit

Permalink
extract span tracking to a helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisholmes committed Oct 23, 2021
1 parent 0b3be3f commit 8c1cecf
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,17 @@ def current_timestamp

def start(notification)
span = tracer.start_span('RSpec suite', start_timestamp: current_timestamp)
token = OpenTelemetry::Context.attach(
OpenTelemetry::Trace.context_with_span(span)
)
@spans_and_tokens.unshift([span, token])
track_span(span)
end

def stop(notification)
pop_and_finalize_span
end

def example_group_started(notification)
group = notification.group
description = group.description
description = notification.group.description
span = tracer.start_span(description, start_timestamp: current_timestamp)
token = OpenTelemetry::Context.attach(
OpenTelemetry::Trace.context_with_span(span)
)
@spans_and_tokens.unshift([span, token])
track_span(span)
end

def example_group_finished(notification)
Expand All @@ -68,10 +61,7 @@ def example_started(notification)
'described_class' => example.metadata[:described_class].to_s
}
span = tracer.start_span(example.description, attributes: attributes, start_timestamp: current_timestamp)
token = OpenTelemetry::Context.attach(
OpenTelemetry::Trace.context_with_span(span)
)
@spans_and_tokens.unshift([span, token])
track_span(span)
end

def example_finished(notification)
Expand All @@ -88,6 +78,13 @@ def example_finished(notification)
end
end

def track_span(span)
token = OpenTelemetry::Context.attach(
OpenTelemetry::Trace.context_with_span(span)
)
@spans_and_tokens.unshift([span, token])
end

def pop_and_finalize_span
span, token = *@spans_and_tokens.shift
return unless span.recording?
Expand Down

0 comments on commit 8c1cecf

Please sign in to comment.