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

introduce an opinionatedly better statsd helper that gives you access… #393

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

Conversation

raginpirate
Copy link
Contributor

@raginpirate raginpirate commented Feb 3, 2025

Whats the diff

This opinionatedly removes the yielded block from statsd_count_sucess and makes developers use tags instead.
The tags proc now supports a result parameter to let developers tag data from any datapoint they would have available to them if they were writing their instrumentation inline (such as a tag like result: T.any(:success, :failure, :error), which is impossible using statsd helpers today).

Note: the name right now is a joke, we can fix the name later 😂

Example of this in use

class Q
    extend(StatsD::Instrument)

    attr_accessor :owner_type
    def initialize(owner_type: "shop_pay_buyer")
    	@owner_type = owner_type
    end

	def y(random_argument:, other_random_argument:)
		"hello"
	end

	statsd_count_but_better(:y, "tester", tags: ->(obj, args, result) { puts obj.owner_type; puts args; puts result; })
end

Q.new.y(random_argument: 3, other_random_argument: "so much clarity!")

> shop_pay_buyer
> {random_argument: 3, other_random_argument: "so much clarity!"}
> hello

✅ What

🤔 Why

👩🔬 How to validate

Checklist

  • I documented the changes in the CHANGELOG file.

@raginpirate raginpirate self-assigned this Feb 3, 2025
@@ -38,10 +38,18 @@ def generate_metric_name(name, callee, *args)
# Generates the tags for an instrumented method.
# @private
# @return [Array[String]]
def generate_tags(tags, callee, *args)
def generate_tags(tags, callee, result=nil, *args)
Copy link
Contributor Author

@raginpirate raginpirate Feb 3, 2025

Choose a reason for hiding this comment

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

I need to fix this, probably requires a bool use_result = false for real nilable result objects.
It should also accept errors that it can hand over to the tag proc too.

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.

1 participant