Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove strong dep micrometer in tracing #14986

Open
wants to merge 2 commits into
base: 3.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,25 @@
*/
package org.apache.dubbo.tracing;

import io.micrometer.observation.ObservationHandler;

import io.micrometer.observation.ObservationRegistry;
import io.micrometer.tracing.Tracer;
import io.micrometer.tracing.handler.DefaultTracingObservationHandler;
import io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler;
import io.micrometer.tracing.handler.PropagatingSenderTracingObservationHandler;

import io.micrometer.tracing.propagation.Propagator;

import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.config.TracingConfig;
import org.apache.dubbo.metrics.MetricsGlobalRegistry;
import org.apache.dubbo.metrics.utils.MetricsSupportUtil;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.tracing.handler.DubboClientTracingObservationHandler;
import org.apache.dubbo.tracing.handler.DubboServerTracingObservationHandler;
import org.apache.dubbo.tracing.metrics.ObservationMeter;
import org.apache.dubbo.tracing.tracer.PropagatorProvider;
import org.apache.dubbo.tracing.tracer.PropagatorProviderFactory;
import org.apache.dubbo.tracing.tracer.TracerProvider;
Expand All @@ -34,8 +44,7 @@

public class DubboObservationRegistry {

private static final ErrorTypeAwareLogger logger =
LoggerFactory.getErrorTypeAwareLogger(DubboObservationRegistry.class);
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(DubboObservationRegistry.class);

private final ApplicationModel applicationModel;

Expand All @@ -48,8 +57,8 @@ public DubboObservationRegistry(ApplicationModel applicationModel, TracingConfig

public void initObservationRegistry() {
// If get ObservationRegistry.class from external(eg Spring.), use external.
io.micrometer.observation.ObservationRegistry externalObservationRegistry =
applicationModel.getBeanFactory().getBean(io.micrometer.observation.ObservationRegistry.class);
ObservationRegistry externalObservationRegistry = applicationModel.getBeanFactory()
.getBean(ObservationRegistry.class);
if (externalObservationRegistry != null) {
if (logger.isDebugEnabled()) {
logger.debug("ObservationRegistry.class from external is existed.");
Expand All @@ -63,48 +72,31 @@ public void initObservationRegistry() {

TracerProvider tracerProvider = TracerProviderFactory.getProvider(applicationModel, tracingConfig);
if (tracerProvider == null) {
logger.warn(
COMMON_NOT_FOUND_TRACER_DEPENDENCY,
"",
"",
"Can not found OpenTelemetry/Brave tracer dependencies, skip init ObservationRegistry.");
logger.warn(COMMON_NOT_FOUND_TRACER_DEPENDENCY, "", "", "Can not found OpenTelemetry/Brave tracer dependencies, skip init ObservationRegistry.");
return;
}
// The real tracer will come from tracer implementation (OTel / Brave)
io.micrometer.tracing.Tracer tracer = tracerProvider.getTracer();
Tracer tracer = tracerProvider.getTracer();

// The real propagator will come from tracer implementation (OTel / Brave)
PropagatorProvider propagatorProvider = PropagatorProviderFactory.getPropagatorProvider();
io.micrometer.tracing.propagation.Propagator propagator = propagatorProvider != null
? propagatorProvider.getPropagator()
: io.micrometer.tracing.propagation.Propagator.NOOP;
Propagator propagator = propagatorProvider != null ? propagatorProvider.getPropagator() : Propagator.NOOP;

io.micrometer.observation.ObservationRegistry registry = io.micrometer.observation.ObservationRegistry.create();
ObservationRegistry registry = ObservationRegistry.create();
registry.observationConfig()
// set up a first matching handler that creates spans - it comes from Micrometer Tracing.
// set up spans for sending and receiving data over the wire and a default one.
.observationHandler(
new io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler(
new io.micrometer.tracing.handler.PropagatingSenderTracingObservationHandler<>(
tracer, propagator),
new io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler<>(
tracer, propagator),
new io.micrometer.tracing.handler.DefaultTracingObservationHandler(tracer)))
.observationHandler(
new io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler(
new DubboClientTracingObservationHandler<>(tracer),
new DubboServerTracingObservationHandler<>(tracer)));
.observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler(new PropagatingSenderTracingObservationHandler<>(tracer, propagator), new PropagatingReceiverTracingObservationHandler<>(tracer, propagator), new DefaultTracingObservationHandler(tracer)))
.observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler(new DubboClientTracingObservationHandler<>(tracer), new DubboServerTracingObservationHandler<>(tracer)));

if (MetricsSupportUtil.isSupportMetrics()) {
io.micrometer.core.instrument.MeterRegistry meterRegistry =
MetricsGlobalRegistry.getCompositeRegistry(applicationModel);
registry.observationConfig()
.observationHandler(new io.micrometer.core.instrument.observation.DefaultMeterObservationHandler(
meterRegistry));
ObservationMeter.addMeterRegistry(registry, applicationModel);
}

applicationModel.getBeanFactory().registerBean(registry);
applicationModel.getBeanFactory().registerBean(tracer);
applicationModel.getBeanFactory().registerBean(propagator);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.apache.dubbo.tracing.metrics;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.observation.ObservationRegistry;

import org.apache.dubbo.metrics.MetricsGlobalRegistry;
import org.apache.dubbo.rpc.model.ApplicationModel;

public class ObservationMeter {

public static void addMeterRegistry(ObservationRegistry registry, ApplicationModel applicationModel) {
MeterRegistry meterRegistry = MetricsGlobalRegistry.getCompositeRegistry(applicationModel);
registry.observationConfig()
.observationHandler(new io.micrometer.core.instrument.observation.DefaultMeterObservationHandler(
meterRegistry));
}

}
Loading