Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Trace route_eval in Sinatra #666

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,29 @@ module Extensions
# Sinatra extension that installs TracerMiddleware and provides
# tracing for template rendering
module TracerExtension

# Sinatra hook after extension is registered
def self.registered(app)
# Create tracing `render` method

::Sinatra::Base.module_eval do
# Invoked when a matching route is found.
# This method yields directly to user code.
def route_eval
Sinatra::Instrumentation.instance.tracer.in_span(
'sinatra.route_eval',
attributes: {
'sinatra.route' => request.path,
'sinatra.request_method' => request.request_method,
'sinatra.resource' => "#{request.request_method} #{request.path}",
}
) do
throw :halt, yield
# Can't use super?
# super
end
end

# Create tracing `render` method
def render(_engine, data, *)
template_name = data.is_a?(Symbol) ? data : :literal

Expand All @@ -28,6 +47,7 @@ def render(_engine, data, *)
end
end
end

app.use(*OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.middleware_args)
app.use(Middlewares::TracerMiddleware)
end
Expand Down