You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/observation.adoc
+3-1
Original file line number
Diff line number
Diff line change
@@ -3,4 +3,6 @@
3
3
4
4
Micrometer Observation is part of the https://github.com/micrometer-metrics/micrometer[Micrometer] project and contains the Observation API. The main idea behind it is that you
5
5
6
-
> Instrument code once, and get multiple benefits out of it.
6
+
****
7
+
_"Instrument code once, and get multiple benefits out of it."_
* <<micrometer-observation-predicates-filters, Observation Predicates and Filters>>
11
+
12
+
*Micrometer Observation basic flow*
13
+
14
+
`Observation` through `ObservationRegistry` gets created with a mutable `Observation.Context`. On each Micrometer Observation lifecycle action (e.g. `start()`) a corresponding `ObservationHandler` method is called (e.g. `onStart`) with the mutable `Observation.Context` as argument.
`Observation` through `ObservationRegistry` gets created with a mutable `Observation.Context`. To allow name and key-value customization, an `ObservationConvention` can be used instead of direct name setting. List of `ObservationPredicate` is run to verify if an `Observation` should be created instead of a no-op version. On each xref:observation/introduction.adoc[Micrometer Observation lifecycle] action (e.g. `start()`) a corresponding `ObservationHandler` method is called (e.g. `onStart`) with the mutable `Observation.Context` as argument. On `Observation` stop, before calling the `ObservationHandler` `onStop` methods, list of `ObservationFilter` is called to optionally further modify the `Observation.Context`.
59
+
60
+
[[micrometer-observation-context]]
61
+
== Observation.Context
62
+
63
+
To pass information between the instrumented code and the handler (or between handler methods, such as `onStart` and `onStop`), you can use an `Observation.Context`. An `Observation.Context` is a `Map`-like container that can store values for you while your handler can access the data inside the context.
64
+
1
65
[[micrometer-observation-handler]]
2
-
= Observation Handler
66
+
== Observation Handler
67
+
68
+
Observation Handler allows adding capabilities to existing instrumentations (i.e. you instrument code once and depending on the Observation Handler setup, different actions, such as create spans, metrics, logs will happen). In other words, if you have instrumented code and want to add metrics around it, it's enough for you to register an Observation Handler in the Observation Registry to add that behaviour.
69
+
70
+
Let's look at the following example of adding a timer behaviour to an existing instrumentation.
3
71
4
72
A popular way to record Observations is storing the start state in a `Timer.Sample` instance and stopping it when the event has ended.
5
73
Recording such measurements could look like this:
@@ -16,16 +84,11 @@ If you want to have more observation options (such as metrics and tracing -- alr
Starting with Micrometer 1.10, you can register "handlers" (`ObservationHandler` instances) that are notified about the lifecycle event of an observation (for example, you can run custom code when an observation is started or stopped).
87
+
Starting with Micrometer 1.10, you can register "handlers" (`ObservationHandler` instances) that are notified about the xref:observation/introduction.adoc[lifecycle event] of an observation (for example, you can run custom code when an observation is started or stopped).
20
88
Using this feature lets you add tracing capabilities to your existing metrics instrumentation (see: `DefaultTracingObservationHandler`). The implementation of these handlers does not need to be tracing related. It is completely up to you how you are going to implement them (for example, you can add logging capabilities).
21
89
22
-
[[micrometer-observation-context]]
23
-
== Observation.Context
24
-
25
-
To pass information between the instrumented code and the handler (or between handler methods, such as `onStart` and `onStop`), you can use an `Observation.Context`. An `Observation.Context` is a `Map`-like container that can store values for you while your handler can access the data inside the context.
26
-
27
90
[[micrometer-observation-handler-example]]
28
-
== ObservationHandler Example
91
+
=== ObservationHandler Example
29
92
30
93
Based on this, we can implement a simple handler that lets the users know about its invocations by printing them out to `stdout`:
31
94
There was a problem loading the remainder of the diff.
0 commit comments