Module: Datadog::AppSec::Contrib::Sinatra::DefaultMiddlewarePatch

Defined in:
lib/datadog/appsec/contrib/sinatra/patcher.rb

Overview

Hook into builder before the middleware list gets frozen

Instance Method Summary collapse

Instance Method Details

#setup_middleware(*args, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/datadog/appsec/contrib/sinatra/patcher.rb', line 30

def setup_middleware(*args, &block)
  builder = args.first

  super.tap do
    tracing_sinatra_framework = Datadog::Tracing::Contrib::Sinatra::Framework
    tracing_middleware = Datadog::Tracing::Contrib::Rack::TraceMiddleware

    if tracing_sinatra_framework.include_middleware?(tracing_middleware, builder)
      tracing_sinatra_framework.add_middleware_after(
        tracing_middleware,
        Datadog::AppSec::Contrib::Rack::RequestMiddleware,
        builder
      )
    else
      tracing_sinatra_framework.add_middleware(Datadog::AppSec::Contrib::Rack::RequestMiddleware, builder)
    end

    tracing_sinatra_framework.inspect_middlewares(builder)
  end
end