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: Update comments, add file header
kaylareopelle committed Sep 20, 2024
commit 92d9ef6cf1bce0822c3d35e6ee8bdc1c80dfae7b
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
module Instrumentation
# MetricsPatch is a module that provides functionality to create a meter
# and record metrics if both the opentelemetry-metrics-api is present
# and the instrumentation to emit metrics has enabled metrics by setting
# :send_metrics to true
module MetricsPatch
def create_meter
@meter = OpenTelemetry::Metrics::Meter.new
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
module Instrumentation
module Rack
module Middlewares
# MetricsPatch is a module that provides functionality to record metrics
# if both the opentelemetry-metrics-api is present and the rack
# instrumentation is configured to emit metrics by setting
# :send_metrics to true
module MetricsPatch
# Don't check in here to see if metrics is enabled, trust that if it's required, metrics will be enabled
def meter
OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.meter
end
@@ -14,15 +23,16 @@ def http_server_request_duration_histogram
@http_server_request_duration_histogram ||= meter.create_histogram('http.server.request.duration', unit: 's', description: 'Duration of HTTP server requests.')
end

# TODO: Update this to define attributes based on SEMCONV_STABILITY_OPT_IN once available
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 = {}
# pattern below goes
# stable convention
# pattern below goes:
# # stable convention
# current span convention

# attrs['http.request.method']