Sha256: 30bdb9a74fd41d42bbda1ef6b008a8d1f7059076128cab3d9ae0d4c4e96b6354
Contents?: true
Size: 1.01 KB
Versions: 17
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true require "securerandom" ## # This code is inspired by request_store gem by Steve Klabnik: # # https://github.com/steveklabnik/request_store/ # # See LICENSE.txt in the current directory for the license. module PlainApm module Extensions module Context class Rack def initialize(app) @app = app end def call(env) Context.trace_id = trace_id(env) status, headers, body = @app.call(env) body = if defined?(::Rack::BodyProxy) ::Rack::BodyProxy.new(body) do Context.clear! end else body end processed = true [status, headers, body] ensure Context.clear! if !processed end private def trace_id(env) request_id(env) || SecureRandom.uuid end def request_id(env) env["action_dispatch.request_id"] || env["HTTP_X_REQUEST_ID"] end end end end end
Version data entries
17 entries across 17 versions & 1 rubygems