-
Notifications
You must be signed in to change notification settings - Fork 47
Drafting possible API to generalise instrumentation code for ZIO apps. #155
Conversation
After quick review with @adamgfraser we think that we would like to get this PR to a mergable state rather sooner than later. To achieve that we would like to implement a unified for a minmal set of supported metrics which could be reported to either statsd or prometheus. Metrics that are special to DataDog statsd will be left to another PR. We are leaning towards an approach that would make it easy to instrument an existing app without introducing the ZMetrics service into the requirements for all instrumented effects. Further, we came up with the idea to have the instrumentation methods also as extensions to the ZIO itself, so that we could do the following instrumentation: trait InstrumentedSample {
def doSomething = ZMetrics.count("myCounter")(ZIO.succeed(print(".")))
def doSomething2 = ZIO.succeed(print(".")).counted("myCounter2")
def countSomething = ZIO.foreach_(1.to(100))(_ => doSomething2.zip(doSomething))
def program: ZIO[ZEnv with ZMetrics, Nothing, ExitCode] = for {
_ <- countSomething.absorbWith(_ => new Exception("Boom")).orDie
} yield ExitCode.success
} Here, each execution of doSomething or domeSomething2 would be counted. The extension method might feel more natural for ZIO developers. |
instrumented effects
The API has now changed so that instrumented effects push Metric Events to a globally available Queue, the |
Review API to allow reporting Gauges to arbitrary backends
Finalizing example to use Gauges with StatsD / Datadog
In the last review with @adamgfraser we have agreed to finish the support for Counters and Gauges reporting to StatsD and Prometheus and leave the other metrics to a later PR. The reasoning is the amount of code changes in this PR. Merging the PR will allow others to contribute with more documentation and other metrics. The PR comes with Basic testing and documentation. I will be working on some more docs, but before the merge I am planning nor more fundamental code changes. |
which is not published, but can be referenced in mdocs
I have now added the first round of documentation for the metrics supported so far. I would suggest to get this PR into a mergable state rather sooner than later, so that we can synchronise with other PR's and tackle more supported metrics. |
Adding support to provide custom labels for Prometheus metrics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get this merged!
This addresses #109.
As far as I can see this will require some refactoring of the existing instrumentation which is tightly couple to statsd.
I am starting to draft out a common instrumentation API that can be used in any ZIO app. The idea is to be able to report metrics to either Prometheus or statsd simply by sticking another Layer into the application.
Creating the PR early to share and discuss early.
An example of a very simple instrumented App is in the test trait and the test app - statsd and test app - empty and also test-app prometheus
See https://github.com/blended-zio/zio-zmx/tree/109-prometheus/docs/metrics for documentation related to the PR.