Class: EpsagonRackMiddleware
- Inherits:
-
Object
- Object
- EpsagonRackMiddleware
- Defined in:
- lib/instrumentation/epsagon_rails_middleware.rb
Constant Summary collapse
- EMPTY_HASH =
{}.freeze
Class Method Summary collapse
- .allowed_rack_request_headers ⇒ Object
- .allowed_response_headers ⇒ Object
- .build_attribute_name(prefix, suffix) ⇒ Object
- .config ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ EpsagonRackMiddleware
constructor
A new instance of EpsagonRackMiddleware.
Constructor Details
#initialize(app) ⇒ EpsagonRackMiddleware
Returns a new instance of EpsagonRackMiddleware.
72 73 74 |
# File 'lib/instrumentation/epsagon_rails_middleware.rb', line 72 def initialize(app) @app = app end |
Class Method Details
.allowed_rack_request_headers ⇒ Object
41 42 43 44 45 |
# File 'lib/instrumentation/epsagon_rails_middleware.rb', line 41 def allowed_rack_request_headers @allowed_rack_request_headers ||= Array(config[:allowed_request_headers]).each_with_object({}) do |header, memo| memo["HTTP_#{header.to_s.upcase.gsub(/[-\s]/, '_')}"] = build_attribute_name('http.request.headers.', header) end end |
.allowed_response_headers ⇒ Object
47 48 49 50 51 52 |
# File 'lib/instrumentation/epsagon_rails_middleware.rb', line 47 def allowed_response_headers @allowed_response_headers ||= Array(config[:allowed_response_headers]).each_with_object({}) do |header, memo| memo[header] = build_attribute_name('http.response.headers.', header) memo[header.to_s.upcase] = build_attribute_name('http.response.headers.', header) end end |
.build_attribute_name(prefix, suffix) ⇒ Object
54 55 56 |
# File 'lib/instrumentation/epsagon_rails_middleware.rb', line 54 def build_attribute_name(prefix, suffix) prefix + suffix.to_s.downcase.gsub(/[-\s]/, '_') end |
.config ⇒ Object
58 59 60 |
# File 'lib/instrumentation/epsagon_rails_middleware.rb', line 58 def config EpsagonRailsInstrumentation.instance.config end |
Instance Method Details
#call(env) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/instrumentation/epsagon_rails_middleware.rb', line 76 def call(env) original_env = env.dup extracted_context = OpenTelemetry.propagation.http.extract(env) frontend_context = create_frontend_span(env, extracted_context) # restore extracted context in this process: OpenTelemetry::Context.with_current(frontend_context || extracted_context) do request_span_name = create_request_span_name(env['REQUEST_URI'] || original_env['PATH_INFO']) tracer.in_span(env['HTTP_HOST'] || 'unknown', attributes: request_span_attributes(env: env), kind: :server) do |http_span| RackExtension.with_span(http_span) do tracer.in_span( env['HTTP_HOST'], kind: :server, attributes: {type: 'rails'} ) do |framework_span| @app.call(env).tap do |status, headers, response| set_attributes_after_request(http_span, framework_span, status, headers, response) end end end end end ensure finish_span(frontend_context) end |