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: 🦠 Metrics prototype for Rack instrumentation #1129

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
refactor: Assign attributes using select
kaylareopelle committed Oct 3, 2024
commit 258b5874a640dfd9f9b88861f79b788ca4ecd418
Original file line number Diff line number Diff line change
@@ -266,6 +266,8 @@ def create_span(parent_context, request)
end

# Metrics stuff
HTTP_SERVER_REQUEST_DURATION_ATTRS_FROM_SPAN = %w[http.method http.scheme http.route http.status_code http.host].freeze

def metrics_enabled?
OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.metrics_enabled?
end
@@ -287,14 +289,9 @@ def record_http_server_request_duration_metric(span)
# find span duration
# end - start / a billion to convert nanoseconds to seconds
duration = (span.end_timestamp - span.start_timestamp) / Float(10**9)
# Create attributes
#
attrs = {}
attrs['http.method'] = span.attributes['http.method']
attrs['http.scheme'] = span.attributes['http.scheme']
attrs['http.route'] = span.attributes['http.route']
attrs['http.status_code'] = span.attributes['http.status_code']
attrs['http.host'] = span.attributes['http.host']
# glean attributes
attrs = span.attributes.select {|k, _v| HTTP_SERVER_REQUEST_DURATION_ATTRS_FROM_SPAN.include?(k) }
# set error
attrs['error.type'] = span.status.description if span.status.code == OpenTelemetry::Trace::Status::ERROR

http_server_request_duration_histogram.record(duration, attributes: attrs)
Loading