Skip to content

Commit da3ed53

Browse files
remove strong dep micrometer in tracing (#14986)
* remove strong dep micrometer in tracing * format code
1 parent 09d6645 commit da3ed53

File tree

2 files changed

+55
-24
lines changed

2 files changed

+55
-24
lines changed

dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationRegistry.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,24 @@
2020
import org.apache.dubbo.common.logger.LoggerFactory;
2121
import org.apache.dubbo.common.utils.JsonUtils;
2222
import org.apache.dubbo.config.TracingConfig;
23-
import org.apache.dubbo.metrics.MetricsGlobalRegistry;
2423
import org.apache.dubbo.metrics.utils.MetricsSupportUtil;
2524
import org.apache.dubbo.rpc.model.ApplicationModel;
2625
import org.apache.dubbo.tracing.handler.DubboClientTracingObservationHandler;
2726
import org.apache.dubbo.tracing.handler.DubboServerTracingObservationHandler;
27+
import org.apache.dubbo.tracing.metrics.ObservationMeter;
2828
import org.apache.dubbo.tracing.tracer.PropagatorProvider;
2929
import org.apache.dubbo.tracing.tracer.PropagatorProviderFactory;
3030
import org.apache.dubbo.tracing.tracer.TracerProvider;
3131
import 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+
3341
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_NOT_FOUND_TRACER_DEPENDENCY;
3442

3543
public 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);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.tracing.metrics;
18+
19+
import org.apache.dubbo.metrics.MetricsGlobalRegistry;
20+
import org.apache.dubbo.rpc.model.ApplicationModel;
21+
22+
import io.micrometer.core.instrument.MeterRegistry;
23+
import io.micrometer.observation.ObservationRegistry;
24+
25+
public class ObservationMeter {
26+
27+
public static void addMeterRegistry(ObservationRegistry registry, ApplicationModel applicationModel) {
28+
MeterRegistry meterRegistry = MetricsGlobalRegistry.getCompositeRegistry(applicationModel);
29+
registry.observationConfig()
30+
.observationHandler(
31+
new io.micrometer.core.instrument.observation.DefaultMeterObservationHandler(meterRegistry));
32+
}
33+
}

0 commit comments

Comments
 (0)