lib/sidekiq/tracer/server_middleware.rb in sidekiq-instrumentation-1.2.0 vs lib/sidekiq/tracer/server_middleware.rb in sidekiq-instrumentation-1.2.1
- old
+ new
@@ -10,32 +10,30 @@
def initialize(tracer:, active_span:)
@tracer = tracer
@active_span = active_span
end
+ # rubocop:disable Metrics/MethodLength
def call(_worker, job, _queue)
- span = build_span(job)
-
- yield
- rescue StandardError => e
- tag_errors(span, e) if span
- raise
- ensure
- span&.finish
- end
-
- private
-
- def build_span(job)
parent_span_context = extract(job)
follows_from = OpenTracing::Reference.follows_from(parent_span_context)
- tracer.start_span(operation_name(job),
- references: [follows_from],
- ignore_active_scope: true,
- tags: tags(job, "consumer"))
+ tracer.start_active_span(operation_name(job),
+ references: [follows_from],
+ ignore_active_scope: true,
+ tags: tags(job, "consumer")) do |scope|
+ begin
+ yield
+ rescue StandardError => e
+ tag_errors(scope.span, e) if scope.span
+ raise
+ end
+ end
end
+ # rubocop:enable Metrics/MethodLength
+
+ private
def tag_errors(span, error)
span.set_tag("error", true)
span.log(event: "error", 'error.object': error)
end