module Sashiko::Ractor::Recorder::Sink
Main-Ractor replayer. Takes a batch of SpanEvents from a worker and re-emits them as real OTel spans with their recorded timing and the correct parent chain.
Public Class Methods
Source
# File lib/sashiko/ractor.rb, line 162 def replay(events, parent_carrier:, tracer: nil) return if events.empty? tracer ||= Sashiko.tracer parent_ctx = OpenTelemetry.propagation.extract(parent_carrier) replayed = {} #: Hash[Integer, untyped] events.sort_by(&:id).each do |event| ctx = if event.parent_id.nil? parent_ctx elsif (parent = replayed[event.parent_id]) OpenTelemetry::Trace.context_with_span(parent) else parent_ctx end OpenTelemetry::Context.with_current(ctx) do span = tracer.start_span( event.name, kind: event.kind, attributes: event.attributes, start_timestamp: Time.at(0, event.start_ns, :nanosecond), ) if event.status_error span.status = OpenTelemetry::Trace::Status.error(event.status_error) end span.finish(end_timestamp: Time.at(0, event.end_ns, :nanosecond)) replayed[event.id] = span end end end