Class: OpenTelemetry::Instrumentation::Rage::Handlers::SSE

Inherits:
Rage::Telemetry::Handler
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/rage/handlers/sse.rb

Overview

The class wraps the processing of SSE streams in spans.

Class Method Summary collapse

Class Method Details

.create_stream_span(env:, type:) ⇒ Object

Parameters:

  • env (Hash)

    the Rack env

  • type (Symbol)

    the type of the SSE response



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/opentelemetry/instrumentation/rage/handlers/sse.rb', line 30

def self.create_stream_span(env:, type:)
  return yield if type != :stream && :type != :manual

  request_context = env[REQUEST_CONTEXT]

  OpenTelemetry::Context.with_current(request_context) do
    Rage::Instrumentation.instance.tracer.in_span("SSE stream", kind: :server) do |span|
      result = yield

      if result.error?
        span.record_exception(result.exception)
        span.status = OpenTelemetry::Trace::Status.error
      end
    end
  end
end

.save_context(env:) ⇒ Object

Parameters:

  • env (Hash)

    the Rack env



20
21
22
23
24
25
26
# File 'lib/opentelemetry/instrumentation/rage/handlers/sse.rb', line 20

def self.save_context(env:)
  span = OpenTelemetry::Instrumentation::Rack.current_span
  return yield unless span.recording?

  env[REQUEST_CONTEXT] = OpenTelemetry::Context.current
  yield
end