@@ -55,13 +55,16 @@ public interface Observation extends ObservationView {
55
55
Observation NOOP = NoopObservation .INSTANCE ;
56
56
57
57
/**
58
- * Creates and starts an {@link Observation}. When no registry is passed or
59
- * observation is not applicable will return a no-op observation.
58
+ * Create and start an {@link Observation} with the given name.
59
+ * All Observations of the same type must share the same name.
60
+ * <p>When no registry is passed or the observation is
61
+ * {@link ObservationRegistry.ObservationConfig#observationPredicate(ObservationPredicate) not applicable},
62
+ * a no-op observation will be returned.
60
63
* @param name name of the observation
61
64
* @param registry observation registry
62
- * @return started observation
65
+ * @return a started observation
63
66
*/
64
- static Observation start (String name , ObservationRegistry registry ) {
67
+ static Observation start (String name , @ Nullable ObservationRegistry registry ) {
65
68
return start (name , Context ::new , registry );
66
69
}
67
70
@@ -81,7 +84,7 @@ static Observation start(String name, ObservationRegistry registry) {
81
84
* @return started observation
82
85
*/
83
86
static <T extends Context > Observation start (String name , Supplier <T > contextSupplier ,
84
- ObservationRegistry registry ) {
87
+ @ Nullable ObservationRegistry registry ) {
85
88
return createNotStarted (name , contextSupplier , registry ).start ();
86
89
}
87
90
@@ -94,7 +97,7 @@ static <T extends Context> Observation start(String name, Supplier<T> contextSup
94
97
* @param registry observation registry
95
98
* @return created but not started observation
96
99
*/
97
- static Observation createNotStarted (String name , ObservationRegistry registry ) {
100
+ static Observation createNotStarted (String name , @ Nullable ObservationRegistry registry ) {
98
101
return createNotStarted (name , Context ::new , registry );
99
102
}
100
103
@@ -116,7 +119,7 @@ static Observation createNotStarted(String name, ObservationRegistry registry) {
116
119
* @return created but not started observation
117
120
*/
118
121
static <T extends Context > Observation createNotStarted (String name , Supplier <T > contextSupplier ,
119
- ObservationRegistry registry ) {
122
+ @ Nullable ObservationRegistry registry ) {
120
123
if (registry == null || registry .isNoop ()) {
121
124
return NOOP ;
122
125
}
@@ -129,42 +132,23 @@ static <T extends Context> Observation createNotStarted(String name, Supplier<T>
129
132
130
133
// @formatter:off
131
134
/**
132
- * Creates but <b>does not start</b> an {@link Observation}. Remember to call
133
- * {@link Observation#start()} when you want the measurements to start. When the
134
- * {@link ObservationRegistry} is null or the no-op registry, this fast returns a
135
- * no-op {@link Observation} and skips the creation of the
136
- * {@link Observation.Context}. This check avoids unnecessary
137
- * {@link Observation.Context} creation, which is why it takes a {@link Supplier} for
138
- * the context rather than the context directly. If the observation is not enabled
139
- * (see
135
+ * Create but <b>does not start</b> an {@link Observation}.
136
+ * <p>Remember to call {@link Observation#start()} when you want the measurements to start.
137
+ * When the {@link ObservationRegistry} is null or the no-op registry, this returns a
138
+ * no-op {@link Observation} and skips the creation of the {@link Observation.Context}.
139
+ * If the observation is not enabled (see
140
140
* {@link ObservationRegistry.ObservationConfig#observationPredicate(ObservationPredicate)
141
141
* ObservationConfig#observationPredicate}), a no-op observation will also be
142
- * returned. Allows to set a custom {@link ObservationConvention} and requires to
143
- * provide a default one if neither a custom nor a pre-configured one (via
144
- * {@link ObservationRegistry.ObservationConfig#getObservationConvention(Context, ObservationConvention)})
145
- * was found. The {@link ObservationConvention} implementation can override
146
- * {@link Observation} names (i.e. name and contextual name) and key values.
147
- * <pre>
148
- * Here you can find the matrix of choosing the convention:
149
- * 1. custom default no pre-configured -> custom
150
- * 2. custom default pre-configured -> custom (not a valid case, just use custom)
151
- * 3. no custom default no pre-configured -> default
152
- * 4. no custom default pre-configured -> pre-configured
153
- * 5. custom no default no pre-configured -> custom (providing default is recommended)
154
- * 6. custom no default pre-configured -> custom (providing default is recommended)
155
- * 7. no custom no default no pre-configured -> local names/tags will be used
156
- * 8. no custom no default pre-configured -> pre-configured
157
- * </pre>
158
- * <p>
159
- * Also, if you set a convention using,
160
- * {@link Observation#observationConvention(ObservationConvention)} (not recommended),
161
- * the convention you set here will be used and everything else (custom, default,
162
- * pre-configured) will be ignored.
163
- * </p>
164
- * <p>
165
- * If you want to add to the all the contexts or mutate them,
166
- * use the ObservationFilter (e.g.: add region=cloud-1 or remove PII).
167
- * </p>
142
+ * returned.
143
+ * <p>A single {@link ObservationConvention convention} will be used for this observation
144
+ * for getting its name and {@link KeyValues key values}:
145
+ * <ol>
146
+ * <li>the {@code customConvention} given as an argument, if not {@code null}
147
+ * <li>a {@link GlobalObservationConvention} configured on the
148
+ * {@link ObservationRegistry.ObservationConfig#observationConvention(GlobalObservationConvention)}
149
+ * that matches this observation
150
+ * <li>as a fallback, the {@code defaultConvention} will be used if none of the above are available
151
+ * </ol>
168
152
* @param <T> type of context
169
153
* @param customConvention custom convention. If {@code null}, the default one will be
170
154
* picked.
@@ -176,8 +160,8 @@ static <T extends Context> Observation createNotStarted(String name, Supplier<T>
176
160
*/
177
161
// @formatter:on
178
162
static <T extends Context > Observation createNotStarted (@ Nullable ObservationConvention <T > customConvention ,
179
- ObservationConvention <T > defaultConvention , Supplier <T > contextSupplier , ObservationRegistry registry ) {
180
- if (registry .isNoop ()) {
163
+ ObservationConvention <T > defaultConvention , Supplier <T > contextSupplier , @ Nullable ObservationRegistry registry ) {
164
+ if (registry == null || registry .isNoop ()) {
181
165
return Observation .NOOP ;
182
166
}
183
167
ObservationConvention <T > convention ;
0 commit comments