Skip to content

Commit bfb341d

Browse files
authored
Add API for configuring custom ObservationRegistry (reactor#2747)
Fixes reactor#2719
1 parent 4effedc commit bfb341d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

reactor-netty-core/src/main/java/reactor/netty/Metrics.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2022 VMware, Inc. or its affiliates, All Rights Reserved.
2+
* Copyright (c) 2019-2023 VMware, Inc. or its affiliates, All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@
3939
public class Metrics {
4040
public static final MeterRegistry REGISTRY = io.micrometer.core.instrument.Metrics.globalRegistry;
4141
public static final String OBSERVATION_KEY = "micrometer.observation";
42-
public static final ObservationRegistry OBSERVATION_REGISTRY = ObservationRegistry.create();
42+
public static ObservationRegistry OBSERVATION_REGISTRY = ObservationRegistry.create();
4343
static {
4444
OBSERVATION_REGISTRY.observationConfig().observationHandler(
4545
new ObservationHandler.FirstMatchingCompositeObservationHandler(
@@ -313,6 +313,18 @@ public static String formatSocketAddress(@Nullable SocketAddress socketAddress)
313313
return null;
314314
}
315315

316+
/**
317+
* Set the {@link ObservationRegistry} to use in Reactor Netty for tracing related purposes.
318+
*
319+
* @return the previously configured registry.
320+
* @since 1.1.6
321+
*/
322+
public static ObservationRegistry observationRegistry(ObservationRegistry observationRegistry) {
323+
ObservationRegistry previous = OBSERVATION_REGISTRY;
324+
OBSERVATION_REGISTRY = observationRegistry;
325+
return previous;
326+
}
327+
316328
public static Context updateContext(Context context, Object observation) {
317329
return context.hasKey(OBSERVATION_KEY) ? context : context.put(OBSERVATION_KEY, observation);
318330
}

0 commit comments

Comments
 (0)