{"action":"opened","issue":{"url":"https://api.github.com/repos/AppMetrics/AppMetrics/issues/304","repository_url":"https://api.github.com/repos/AppMetrics/AppMetrics","labels_url":"https://api.github.com/repos/AppMetrics/AppMetrics/issues/304/labels{/name}","comments_url":"https://api.github.com/repos/AppMetrics/AppMetrics/issues/304/comments","events_url":"https://api.github.com/repos/AppMetrics/AppMetrics/issues/304/events","html_url":"https://github.com/AppMetrics/AppMetrics/issues/304","id":359201701,"node_id":"MDU6SXNzdWUzNTkyMDE3MDE=","number":304,"title":"Add ability to provide time measurement to IMeasureTimerMetrics.Time()","user":{"login":"joshclark","id":1121140,"node_id":"MDQ6VXNlcjExMjExNDA=","avatar_url":"https://avatars3.githubusercontent.com/u/1121140?v=4","gravatar_id":"","url":"https://api.github.com/users/joshclark","html_url":"https://github.com/joshclark","followers_url":"https://api.github.com/users/joshclark/followers","following_url":"https://api.github.com/users/joshclark/following{/other_user}","gists_url":"https://api.github.com/users/joshclark/gists{/gist_id}","starred_url":"https://api.github.com/users/joshclark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshclark/subscriptions","organizations_url":"https://api.github.com/users/joshclark/orgs","repos_url":"https://api.github.com/users/joshclark/repos","events_url":"https://api.github.com/users/joshclark/events{/privacy}","received_events_url":"https://api.github.com/users/joshclark/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-11T20:01:34Z","updated_at":"2018-09-11T20:01:34Z","closed_at":null,"author_association":"NONE","body":"The `IMeasureTimerMetrics` interface allows the user to provide either an Action method that will be executed and then the time to execute will be recorded or the user can get back an IDisposable that will record the metric when `Dispose()` is called.\r\n\r\nI'd like to have a third way to record the time:  Let the caller just specify the duration directly.  The API would look something like this:\r\n``` csharp\r\n  void Time(TimerOptions options, MetricTags tags, long time);\r\n```\r\nThe implementation would basically just call `ITimer.Record` similar to how the Action and TimerContext versions do.\r\n\r\n\r\nWhy do I want something like this?\r\nI have a user asking for the ability to \r\n1. Disable the metric generation with the TimerContext is disposed.  Basically they want to have the context in a using block but then be able to say `context.Enabled = false` if they determine that the metric should not be recorded.\r\n2. Add tags after the timer has started.  Specifically, they want to add an \"isSuccessful\" tag to be able to tell which times represent successful calls and which ones represent failures.  \"I don't care how fast my page renders when I can't talk to the database.\"\r\n\r\nMy solution for both of these was to provide my own TimerContext-like IDisposable.  My api that wraps appmetrics would return this new context type and have the ability to add new tags on the fly and to disable the recording of the metric.  Basically I would do nothing in the \"Start Timer\" call other than record `IClock.Nanoseconds`.  In my context's Dispose call, I could check if I was still enabled, and if so create a new timer with `_metricRoot.Measure.Timer.Time(name, tags, totalTime);`\r\n\r\n\r\nThoughts on this approach?  Would you be interested in a PR for this?  Is there a better solution?"}}
{"actor":{"display_login":"joshclark"}}