2020import org .apache .dubbo .common .logger .LoggerFactory ;
2121import org .apache .dubbo .common .utils .JsonUtils ;
2222import org .apache .dubbo .config .TracingConfig ;
23- import org .apache .dubbo .metrics .MetricsGlobalRegistry ;
2423import org .apache .dubbo .metrics .utils .MetricsSupportUtil ;
2524import org .apache .dubbo .rpc .model .ApplicationModel ;
2625import org .apache .dubbo .tracing .handler .DubboClientTracingObservationHandler ;
2726import org .apache .dubbo .tracing .handler .DubboServerTracingObservationHandler ;
27+ import org .apache .dubbo .tracing .metrics .ObservationMeter ;
2828import org .apache .dubbo .tracing .tracer .PropagatorProvider ;
2929import org .apache .dubbo .tracing .tracer .PropagatorProviderFactory ;
3030import org .apache .dubbo .tracing .tracer .TracerProvider ;
3131import org .apache .dubbo .tracing .tracer .TracerProviderFactory ;
3232
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+
3341import static org .apache .dubbo .common .constants .LoggerCodeConstants .COMMON_NOT_FOUND_TRACER_DEPENDENCY ;
3442
3543public class DubboObservationRegistry {
@@ -48,8 +56,8 @@ public DubboObservationRegistry(ApplicationModel applicationModel, TracingConfig
4856
4957 public void initObservationRegistry () {
5058 // 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 );
5361 if (externalObservationRegistry != null ) {
5462 if (logger .isDebugEnabled ()) {
5563 logger .debug ("ObservationRegistry.class from external is existed." );
@@ -71,36 +79,26 @@ public void initObservationRegistry() {
7179 return ;
7280 }
7381 // The real tracer will come from tracer implementation (OTel / Brave)
74- io . micrometer . tracing . Tracer tracer = tracerProvider .getTracer ();
82+ Tracer tracer = tracerProvider .getTracer ();
7583
7684 // The real propagator will come from tracer implementation (OTel / Brave)
7785 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 ;
8187
82- io . micrometer . observation . ObservationRegistry registry = io . micrometer . observation . ObservationRegistry .create ();
88+ ObservationRegistry registry = ObservationRegistry .create ();
8389 registry .observationConfig ()
8490 // set up a first matching handler that creates spans - it comes from Micrometer Tracing.
8591 // 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 )));
9799
98100 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 );
104102 }
105103
106104 applicationModel .getBeanFactory ().registerBean (registry );
0 commit comments