Skip to content

Commit 4743b3c

Browse files
Added more high-overview docs with graphs; fixes gh-4726
1 parent 0b321c8 commit 4743b3c

File tree

6 files changed

+555
-70
lines changed

6 files changed

+555
-70
lines changed

docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
* xref:observation.adoc[Micrometer Observation]
6262
** xref:observation/installing.adoc[Installing]
6363
** xref:observation/introduction.adoc[Introduction]
64-
** xref:observation/handler.adoc[Observation Handlers]
64+
** xref:observation/components.adoc[Components]
6565
** xref:observation/instrumenting.adoc[Instrumenting]
6666
** xref:observation/testing.adoc[Testing]
6767
** xref:observation/projects.adoc[Instrumented Projects]

docs/modules/ROOT/pages/observation/handler.adoc renamed to docs/modules/ROOT/pages/observation/components.adoc

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,69 @@
1+
[[micrometer-observation-components]]
2+
= Observation Components
3+
4+
In this section we will describe main components related to Micrometer Observation.
5+
6+
* <<micrometer-observation-context, Observation Context>>
7+
* <<micrometer-observation-handler, Observation Handler>>
8+
* <<micrometer-observation-events, Signaling Errors and Arbitrary Events>>
9+
* <<micrometer-observation-convention-example, Observation Convention>>
10+
* <<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.
15+
16+
// https://arthursonzogni.com/Diagon/#GraphDAG
17+
// ObservationRegistry->Observation
18+
// Context->Observation
19+
// Observation->Handler
20+
[source,subs=+attributes]
21+
-----
22+
┌───────────────────┐┌───────┐
23+
│ObservationRegistry││Context│
24+
└┬──────────────────┘└┬──────┘
25+
┌▽────────────────────▽┐
26+
│Observation │
27+
└┬─────────────────────┘
28+
┌▽──────┐
29+
│Handler│
30+
└───────┘
31+
-----
32+
33+
*Micrometer Observation detailed flow*
34+
35+
// https://arthursonzogni.com/Diagon/#GraphDAG
36+
// ObservationRegistry->Observation
37+
// Context->Observation
38+
// ObservationConvention->Observation
39+
// ObservationPredicate->Observation
40+
// Observation->Handler
41+
// Handler->ObservationFilter
42+
[source,subs=+attributes]
43+
-----
44+
┌───────────────────┐┌───────┐┌─────────────────────┐┌────────────────────┐
45+
│ObservationRegistry││Context││ObservationConvention││ObservationPredicate│
46+
└┬──────────────────┘└┬──────┘└┬────────────────────┘└┬───────────────────┘
47+
┌▽────────────────────▽────────▽──────────────────────▽┐
48+
│Observation │
49+
└┬─────────────────────────────────────────────────────┘
50+
┌▽──────┐
51+
│Handler│
52+
└┬──────┘
53+
┌▽────────────────┐
54+
│ObservationFilter│
55+
└─────────────────┘
56+
-----
57+
58+
`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 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+
165
[[micrometer-observation-handler]]
2-
= Observation Handler
66+
== Observation Handler
367

468
A popular way to record Observations is storing the start state in a `Timer.Sample` instance and stopping it when the event has ended.
569
Recording such measurements could look like this:
@@ -19,13 +83,8 @@ include::{include-java}/observation/ObservationHandlerTests.java[tags=observatio
1983
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).
2084
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).
2185

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-
2786
[[micrometer-observation-handler-example]]
28-
== ObservationHandler Example
87+
=== ObservationHandler Example
2988

3089
Based on this, we can implement a simple handler that lets the users know about its invocations by printing them out to `stdout`:
3190

0 commit comments

Comments
 (0)