Skip to content

[RFC] Exception handling and api normalization #113

@maximebedard

Description

@maximebedard

Fixes: #110

Follow-up on #111, #112

To improve consistency of this library and try to minimize unexpected side-effects from developers, I have a few proposal I'd like to make.

changes to .statsd_count_if

The README currently states the following:

This will only increment the given key if the method executes successfully. So now, if GoogleBase#insert raises an exception or returns false (ie. result == false), we won't increment the key. If you want to define what success means for a given method you can pass a block that takes the result of the method.

I propose that instead of comparing against a false value that we use the ruby if directly to evaluate the truthiness/falsyness of the value. If the method raises, no metric will be pushed.

changes to .statsd_count_success

I propose that we evaluate the condition to deliver the metric exactly the same way defined in .statsd_count_if. However, instead of creating 2 buckets for success and failure, I propose we add a 3rd bucket error for situations where the method raises.

changes to measure .statsd_measure

I propose that this method would push metrics for all situations (normal execution, raise). In other words, it would behave exactly the same way as .statsd_count.

add .statsd_measure_success, .statsd_measure_if

I propose we match the same API we do for .statsd_count_*. This would allow us to give more flexibility as to which metrics we want to observe in the end.

changes to #measure

I suggest we create 2 distinct methods:

  • measure (push a single metrics in all cases -- even when the method raises)
  • measure_success (push a metric in 3 distinct buckets success, failure, error)

Note: measure_success would have to accept a proc in order to allow the consumer to define what success means. By default it will simply check truthy/falsy values.

changes to tags/automatic suffixes

For StatsD implementations that supports tags, instead of pushing a metric with a suffix MetricName.success|failure|error, we could push them as a tag with the key status:#{status}.

Any thoughts/concerns? ❤️

@tjoyal @simon-shopify @wvanbergen @alexsnaps @dnlserrano

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions