20
20
import org .apache .dubbo .common .logger .LoggerFactory ;
21
21
import org .apache .dubbo .common .utils .JsonUtils ;
22
22
import org .apache .dubbo .config .TracingConfig ;
23
- import org .apache .dubbo .metrics .MetricsGlobalRegistry ;
24
23
import org .apache .dubbo .metrics .utils .MetricsSupportUtil ;
25
24
import org .apache .dubbo .rpc .model .ApplicationModel ;
26
25
import org .apache .dubbo .tracing .handler .DubboClientTracingObservationHandler ;
27
26
import org .apache .dubbo .tracing .handler .DubboServerTracingObservationHandler ;
27
+ import org .apache .dubbo .tracing .metrics .ObservationMeter ;
28
28
import org .apache .dubbo .tracing .tracer .PropagatorProvider ;
29
29
import org .apache .dubbo .tracing .tracer .PropagatorProviderFactory ;
30
30
import org .apache .dubbo .tracing .tracer .TracerProvider ;
31
31
import org .apache .dubbo .tracing .tracer .TracerProviderFactory ;
32
32
33
+ import io .micrometer .observation .ObservationHandler ;
34
+ import io .micrometer .observation .ObservationRegistry ;
35
+ import io .micrometer .tracing .Tracer ;
36
+ import io .micrometer .tracing .handler .DefaultTracingObservationHandler ;
37
+ import io .micrometer .tracing .handler .PropagatingReceiverTracingObservationHandler ;
38
+ import io .micrometer .tracing .handler .PropagatingSenderTracingObservationHandler ;
39
+ import io .micrometer .tracing .propagation .Propagator ;
40
+
33
41
import static org .apache .dubbo .common .constants .LoggerCodeConstants .COMMON_NOT_FOUND_TRACER_DEPENDENCY ;
34
42
35
43
public class DubboObservationRegistry {
@@ -48,8 +56,8 @@ public DubboObservationRegistry(ApplicationModel applicationModel, TracingConfig
48
56
49
57
public void initObservationRegistry () {
50
58
// If get ObservationRegistry.class from external(eg Spring.), use external.
51
- io . micrometer . observation . ObservationRegistry externalObservationRegistry =
52
- applicationModel .getBeanFactory ().getBean (io . micrometer . observation . ObservationRegistry .class );
59
+ ObservationRegistry externalObservationRegistry =
60
+ applicationModel .getBeanFactory ().getBean (ObservationRegistry .class );
53
61
if (externalObservationRegistry != null ) {
54
62
if (logger .isDebugEnabled ()) {
55
63
logger .debug ("ObservationRegistry.class from external is existed." );
@@ -71,36 +79,26 @@ public void initObservationRegistry() {
71
79
return ;
72
80
}
73
81
// The real tracer will come from tracer implementation (OTel / Brave)
74
- io . micrometer . tracing . Tracer tracer = tracerProvider .getTracer ();
82
+ Tracer tracer = tracerProvider .getTracer ();
75
83
76
84
// The real propagator will come from tracer implementation (OTel / Brave)
77
85
PropagatorProvider propagatorProvider = PropagatorProviderFactory .getPropagatorProvider ();
78
- io .micrometer .tracing .propagation .Propagator propagator = propagatorProvider != null
79
- ? propagatorProvider .getPropagator ()
80
- : io .micrometer .tracing .propagation .Propagator .NOOP ;
86
+ Propagator propagator = propagatorProvider != null ? propagatorProvider .getPropagator () : Propagator .NOOP ;
81
87
82
- io . micrometer . observation . ObservationRegistry registry = io . micrometer . observation . ObservationRegistry .create ();
88
+ ObservationRegistry registry = ObservationRegistry .create ();
83
89
registry .observationConfig ()
84
90
// set up a first matching handler that creates spans - it comes from Micrometer Tracing.
85
91
// set up spans for sending and receiving data over the wire and a default one.
86
- .observationHandler (
87
- new io .micrometer .observation .ObservationHandler .FirstMatchingCompositeObservationHandler (
88
- new io .micrometer .tracing .handler .PropagatingSenderTracingObservationHandler <>(
89
- tracer , propagator ),
90
- new io .micrometer .tracing .handler .PropagatingReceiverTracingObservationHandler <>(
91
- tracer , propagator ),
92
- new io .micrometer .tracing .handler .DefaultTracingObservationHandler (tracer )))
93
- .observationHandler (
94
- new io .micrometer .observation .ObservationHandler .FirstMatchingCompositeObservationHandler (
95
- new DubboClientTracingObservationHandler <>(tracer ),
96
- new DubboServerTracingObservationHandler <>(tracer )));
92
+ .observationHandler (new ObservationHandler .FirstMatchingCompositeObservationHandler (
93
+ new PropagatingSenderTracingObservationHandler <>(tracer , propagator ),
94
+ new PropagatingReceiverTracingObservationHandler <>(tracer , propagator ),
95
+ new DefaultTracingObservationHandler (tracer )))
96
+ .observationHandler (new ObservationHandler .FirstMatchingCompositeObservationHandler (
97
+ new DubboClientTracingObservationHandler <>(tracer ),
98
+ new DubboServerTracingObservationHandler <>(tracer )));
97
99
98
100
if (MetricsSupportUtil .isSupportMetrics ()) {
99
- io .micrometer .core .instrument .MeterRegistry meterRegistry =
100
- MetricsGlobalRegistry .getCompositeRegistry (applicationModel );
101
- registry .observationConfig ()
102
- .observationHandler (new io .micrometer .core .instrument .observation .DefaultMeterObservationHandler (
103
- meterRegistry ));
101
+ ObservationMeter .addMeterRegistry (registry , applicationModel );
104
102
}
105
103
106
104
applicationModel .getBeanFactory ().registerBean (registry );
0 commit comments