Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ef0869d

Browse files
authoredFeb 13, 2024
Merge branch 'micrometer-metrics:main' into micrometer-metricsgh-1441
2 parents 5cb55eb + c69180d commit ef0869d

File tree

103 files changed

+2943
-5155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2943
-5155
lines changed
 

‎docs/modules/ROOT/pages/observation.adoc

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33

44
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
55

6-
> Instrument code once, and get multiple benefits out of it.
6+
****
7+
_"Instrument code once, and get multiple benefits out of it."_
8+
****

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

+71-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,73 @@
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 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+
165
[[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.
371

472
A popular way to record Observations is storing the start state in a `Timer.Sample` instance and stopping it when the event has ended.
573
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
1684
include::{include-java}/observation/ObservationHandlerTests.java[tags=observation,indent=0]
1785
-----
1886

19-
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).
2088
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).
2189

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-
2790
[[micrometer-observation-handler-example]]
28-
== ObservationHandler Example
91+
=== ObservationHandler Example
2992

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

There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.