Skip to content

Commit

Permalink
chore: ffeedback
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlaurin committed May 8, 2024
1 parent 0b666b9 commit dfcbfb2
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module Middlewares
class EventHandler
include ::Rack::Events::Abstract

RACK_OTEL_CONTEXT_KEY = 'otel.rack.context.token'
OTEL_TOKEN_AND_SPAN = 'otel.rack.token_and_span'
GOOD_HTTP_STATUSES = (100..499)

# Creates a server span for this current request using the incoming parent context
Expand All @@ -58,7 +58,7 @@ def on_start(request, _)
span = create_span(parent_context, request)
span_ctx = OpenTelemetry::Trace.context_with_span(span, parent_context: parent_context)
rack_ctx = OpenTelemetry::Instrumentation::Rack.context_with_span(span, parent_context: span_ctx)
request.env[RACK_OTEL_CONTEXT_KEY] = [OpenTelemetry::Context.attach(rack_ctx), rack_ctx]
request.env[OTEL_TOKEN_AND_SPAN] = [OpenTelemetry::Context.attach(rack_ctx), span]
rescue StandardError => e
OpenTelemetry.handle_error(exception: e)
end
Expand Down Expand Up @@ -194,10 +194,10 @@ def request_span_attributes(env)
end

def detach_context(request)
return nil unless request.env[RACK_OTEL_CONTEXT_KEY]
return nil unless request.env[OTEL_TOKEN_AND_SPAN]

token, rack_ctx = request.env[RACK_OTEL_CONTEXT_KEY]
OpenTelemetry::Trace.current_span(rack_ctx).finish
token, span = request.env[OTEL_TOKEN_AND_SPAN]
span.finish
OpenTelemetry::Context.detach(token)
rescue StandardError => e
OpenTelemetry.handle_error(exception: e)
Expand Down

0 comments on commit dfcbfb2

Please sign in to comment.