Closed Bug 1624626 Opened 6 years ago Closed 6 years ago

Add convenience `measure` function to Python TimingDistribution and Timespan metric types

Categories

(Data Platform and Tools :: Glean: SDK, enhancement, P1)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: travis_, Assigned: mdroettboom)

Details

(Whiteboard: [telemetry:glean-rs:m13][glean-py])

Attachments

(1 file)

This is to add the same measure convenience method to the Python bindings that's added by this PR

Priority: -- → P3
Whiteboard: [telemetry:glean-rs:m?]

I feel like the most Pythonic way to expose this would be to implement it as a context manager so it could be used in a with block, e.g.:

with metrics.timing_distribution.measure():
    do_the_thing_you_want_to_measure()

This has the advantage that it makes it just as easy to measure parts of functions.

It could also be a decorator, but that would require measuring an entire function:

@metrics.timing_distribution.measure
def a_function_i_want_to_measure():
    # ... do the work

Passing a function to measure would also work, but it vaguely feels less Pythonic to me (and would also require measuring an entire function):

metrics.timing_distribution.measure(a_function_i_want_to_measure)

Passing a function to measure would also work, but it vaguely feels less Pythonic to me (and would also require measuring an entire function):

metrics.timing_distribution.measure(a_function_i_want_to_measure)

I played around with this method (as I didn't know about the other ways to do this due to lack of knowledge about Python), and I couldn't come up with a way to return the value of the function or to pass values into the function that worked for me and was congruent with the Kotlin and Swift implementations. Is that possible? If so I'd be interested in seeing how it's done :)

(In reply to Michael Droettboom [:mdroettboom] from comment #1)

I feel like the most Pythonic way to expose this would be to implement it as a context manager so it could be used in a with block, e.g.:

with metrics.timing_distribution.measure():
    do_the_thing_you_want_to_measure()

This has the advantage that it makes it just as easy to measure parts of functions.

This feels the best option to me as well. We want to make ti easy to measure parts of functions as part of our API, and this approach makes it comparable to what's offered in the Kotlin bindings as well.

Whiteboard: [telemetry:glean-rs:m?] → [telemetry:glean-rs:m13][glean-py]
Whiteboard: [telemetry:glean-rs:m13][glean-py] → [telemetry:glean-rs:backlog][glean-py]
Whiteboard: [telemetry:glean-rs:backlog][glean-py] → [telemetry:glean-rs:m13][glean-py]
Assignee: nobody → mdroettboom
Priority: P3 → P1
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: