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 event handler prototype #1213

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
style: Spacing updates
  • Loading branch information
kaylareopelle authored Oct 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit ba9d06d8085cfbe36a61622698461a5db64b54d7
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
#
# SPDX-License-Identifier: Apache-2.0


module OpenTelemetry
module Instrumentation
# The Base class holds all metadata and configuration for an
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
option :use_rack_events, default: true, validate: :boolean
# TODO: This option currently exclusively uses the event handler, should we support old and new Rack?
option :send_metrics, default: false, validate: :boolean

# Temporary Helper for Sinatra and ActionPack middleware to use during installation
#
# @example Default usage
@@ -48,7 +49,6 @@ def middleware_args
end
end


private

def require_dependencies
Original file line number Diff line number Diff line change
@@ -158,7 +158,6 @@ def untraced_request?(env)
false
end


# https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-http.md#name
#
# recommendation: span.name(s) should be low-cardinality (e.g.,
@@ -281,7 +280,11 @@ def meter
def http_server_request_duration_histogram
return unless metrics_enabled?

@http_server_request_duration_histogram ||= meter.create_histogram('http.server.request.duration', unit: 's', description: 'Duration of HTTP server requests.')
@http_server_request_duration_histogram ||= meter.create_histogram(
'http.server.request.duration',
unit: 's',
description: 'Duration of HTTP server requests.'
)
end

def record_http_server_request_duration_metric(span)
@@ -290,7 +293,7 @@ def record_http_server_request_duration_metric(span)
# end - start / a billion to convert nanoseconds to seconds
duration = (span.end_timestamp - span.start_timestamp) / Float(10**9)
# glean attributes
attrs = span.attributes.select {|k, _v| HTTP_SERVER_REQUEST_DURATION_ATTRS_FROM_SPAN.include?(k) }
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