Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Increment metric duration #27

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

Conversation

bondepike
Copy link

This change allows for incrementing the metric duration.
Good use case for aggregating compute duration for specific methods in a recursive environment. Which is what I use it for.

func recusiveThing(ctx context.Context, id string) {
    //... many other compute

    timing := servertiming.FromContext(ctx)

    dt := timing.NewMetric("some_compute").Start()
    doSomeComputeForThisThing(ctx, id)
    dt.End()

    subThings := findSubThingsForThisThing(ctx, id)
    for i := range subThings {
        recursiveThing(ctx, subThings[i].id)
    }
}

// how much time did we spend with doSomeComputeForThisThing in total?

Please consider if you want to alter the functionality before merging, as it may be a breaking change for some who rely upon the current implementation logic.

…tead of overwriting it. This allows for accumulation of metric time across multiple starts and stops. Also updated NewMetric function in the Header to return an existing metric if it shares the same name as the one being created.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant