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: advisory parameters for metrics instruments #1801

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zvkemp
Copy link

@zvkemp zvkemp commented Jan 29, 2025

According to the metrics API, instrument creation should support advisory parameters.

The two current parameters are attributes and explicit_bucket_boundaries.

attributes (status: development), apply to every instrument.

explicit_bucket_boundaries only apply to histograms.

The advisory parameters are accepted at instrument creation, validated that they apply to that instrument type, and then are cached on the instrument. New instances of their configured aggregations receive these parameters at #initialize.

@kaylareopelle
Copy link
Contributor

Example of this in use in the Redis PR

Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @zvkemp! This looks great. 🎉 I have a few testing/documentation recommendations, but the logic is sound and aligns with the spec.

When we make changes to the API/SDK, I also think about whether any changes need to be made to the OTLP exporter. In this case, it seems like the OTLP exporter should accept these attributes without any changes. A test might be helpful down the line to confirm explicit bucket boundaries are passed along, but that can be handled in a separate unit of work.

@@ -30,4 +30,30 @@
_(last_snapshot[0].data_points[0].attributes).must_equal('foo' => 'bar')
_(last_snapshot[0].aggregation_temporality).must_equal(:delta)
end

describe 'with advisory parameters' do
let(:random_key) { "a#{SecureRandom.hex}" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, similar question to the API -- what do you think about adding advisory parameters/attributes for the other instruments?

)
end

let(:random_attribute) { "a#{SecureRandom.hex}" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above -- tests are failing with a missing SecureRandom require: https://github.com/open-telemetry/opentelemetry-ruby/actions/runs/13058885253/job/36668636949?pr=1801#step:6:185

@@ -43,8 +43,8 @@ def initialize
# @param description [optional String] an optional free-form text provided by user.
#
# @return [nil] after creation of counter, it will be stored in instrument_registry
def create_counter(name, unit: nil, description: nil)
create_instrument(:counter, name, unit, description, nil) { COUNTER }
def create_counter(name, unit: nil, description: nil, **advisory_parameters)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some documentation to each of the instruments about the relevant **advisory_parameters named keyword args?

@@ -24,11 +24,21 @@
_(counter.class).must_equal(OpenTelemetry::Metrics::Instrument::Counter)
end

it 'test create_counter with advisory parameters' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering tests as documentation, I think it would be helpful to add assertions for the other instruments with their permitted advisory parameters.

@@ -35,7 +35,21 @@ def record(amount, attributes: {})
private

def default_aggregation
OpenTelemetry::SDK::Metrics::Aggregation::ExplicitBucketHistogram.new
# This hash is assembled to avoid implicitly passing `boundaries: nil`,
# which should be valid explicit call according to ExplicitBucketHistogram#initialize
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# which should be valid explicit call according to ExplicitBucketHistogram#initialize
# which should be a valid explicit call according to ExplicitBucketHistogram#initialize

Comment on lines +57 to +59
advisory_parameters.each_key do |parameter_name|
OpenTelemetry.logger.warn "Advisory parameter `#{parameter_name}` is not valid for instrument kind `#{instrument_kind}`; ignoring"
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a test that covers this scenario?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants