fix: fix observationsender error & feat: add DubboTracingObservationHandler (#13818)
This commit is contained in:
parent
9b3073c2f4
commit
b14e5e3a12
|
|
@ -101,6 +101,12 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,4 @@ dubbo:
|
|||
metadata-report:
|
||||
address: zookeeper://127.0.0.1:2181
|
||||
|
||||
logging:
|
||||
pattern:
|
||||
level: '%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]'
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
<PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} %style{-|}{White} %m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}" disableAnsi="false" charset="UTF-8"/>
|
||||
<PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} [%X{traceId}, %X{spanId}] %style{-|}{White} %m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}" disableAnsi="false" charset="UTF-8"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
|
|
|
|||
|
|
@ -101,6 +101,12 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -41,7 +41,3 @@ dubbo:
|
|||
exporter:
|
||||
enabled: true
|
||||
enable-metadata: true
|
||||
logging:
|
||||
pattern:
|
||||
level: '%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]'
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
<PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} %style{-|}{White} %m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}" disableAnsi="false" charset="UTF-8"/>
|
||||
<PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} [%X{traceId}, %X{spanId}] %style{-|}{White} %m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}" disableAnsi="false" charset="UTF-8"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
observationsender=org.apache.dubbo.rpc.cluster.filter.support.ObservationSenderFilter
|
||||
metricsClusterFilter=org.apache.dubbo.rpc.cluster.filter.support.MetricsClusterFilter
|
||||
monitor=org.apache.dubbo.monitor.support.MonitorClusterFilter
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ 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.tracer.PropagatorProvider;
|
||||
import org.apache.dubbo.tracing.tracer.PropagatorProviderFactory;
|
||||
import org.apache.dubbo.tracing.tracer.TracerProvider;
|
||||
|
|
@ -87,7 +89,11 @@ public class DubboObservationRegistry {
|
|||
tracer, propagator),
|
||||
new io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler<>(
|
||||
tracer, propagator),
|
||||
new io.micrometer.tracing.handler.DefaultTracingObservationHandler(tracer)));
|
||||
new io.micrometer.tracing.handler.DefaultTracingObservationHandler(tracer)))
|
||||
.observationHandler(
|
||||
new io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler(
|
||||
new DubboClientTracingObservationHandler<>(tracer),
|
||||
new DubboServerTracingObservationHandler<>(tracer)));
|
||||
|
||||
if (MetricsSupportUtil.isSupportMetrics()) {
|
||||
io.micrometer.core.instrument.MeterRegistry meterRegistry =
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import org.apache.dubbo.rpc.Invoker;
|
|||
|
||||
import java.util.Objects;
|
||||
|
||||
import io.micrometer.observation.transport.Kind;
|
||||
import io.micrometer.observation.transport.SenderContext;
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +34,7 @@ public class DubboClientContext extends SenderContext<Invocation> {
|
|||
private final Invocation invocation;
|
||||
|
||||
public DubboClientContext(Invoker<?> invoker, Invocation invocation) {
|
||||
super((map, key, value) -> Objects.requireNonNull(map).setAttachment(key, value));
|
||||
super((carrier, key, value) -> Objects.requireNonNull(carrier).setAttachment(key, value), Kind.CLIENT);
|
||||
this.invoker = invoker;
|
||||
this.invocation = invocation;
|
||||
setCarrier(invocation);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.dubbo.tracing.context;
|
|||
import org.apache.dubbo.rpc.Invocation;
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
|
||||
import io.micrometer.observation.transport.Kind;
|
||||
import io.micrometer.observation.transport.ReceiverContext;
|
||||
|
||||
/**
|
||||
|
|
@ -31,7 +32,7 @@ public class DubboServerContext extends ReceiverContext<Invocation> {
|
|||
private final Invocation invocation;
|
||||
|
||||
public DubboServerContext(Invoker<?> invoker, Invocation invocation) {
|
||||
super((stringObjectMap, s) -> String.valueOf(stringObjectMap.getAttachment(s)));
|
||||
super((carrier, s) -> String.valueOf(carrier.getAttachment(s)), Kind.SERVER);
|
||||
this.invoker = invoker;
|
||||
this.invocation = invocation;
|
||||
setCarrier(invocation);
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
|
|||
onClass = "io.micrometer.observation.NoopObservationRegistry")
|
||||
public class ObservationReceiverFilter implements Filter, BaseFilter.Listener, ScopeModelAware {
|
||||
|
||||
private ObservationRegistry observationRegistry;
|
||||
private final ObservationRegistry observationRegistry;
|
||||
|
||||
private DubboServerObservationConvention serverObservationConvention;
|
||||
private final DubboServerObservationConvention serverObservationConvention;
|
||||
|
||||
public ObservationReceiverFilter(ApplicationModel applicationModel) {
|
||||
observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class);
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
|
|||
onClass = "io.micrometer.observation.NoopObservationRegistry")
|
||||
public class ObservationSenderFilter implements ClusterFilter, BaseFilter.Listener, ScopeModelAware {
|
||||
|
||||
private ObservationRegistry observationRegistry;
|
||||
private final ObservationRegistry observationRegistry;
|
||||
|
||||
private DubboClientObservationConvention clientObservationConvention;
|
||||
private final DubboClientObservationConvention clientObservationConvention;
|
||||
|
||||
public ObservationSenderFilter(ApplicationModel applicationModel) {
|
||||
observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.tracing.handler;
|
||||
|
||||
import org.apache.dubbo.tracing.context.DubboClientContext;
|
||||
|
||||
import io.micrometer.observation.Observation;
|
||||
import io.micrometer.observation.ObservationHandler;
|
||||
import io.micrometer.observation.transport.SenderContext;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
|
||||
public class DubboClientTracingObservationHandler<T extends DubboClientContext> implements ObservationHandler<T> {
|
||||
private final Tracer tracer;
|
||||
|
||||
public DubboClientTracingObservationHandler(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScopeOpened(T context) {}
|
||||
|
||||
@Override
|
||||
public boolean supportsContext(Observation.Context context) {
|
||||
return context instanceof SenderContext;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.tracing.handler;
|
||||
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.tracing.context.DubboServerContext;
|
||||
|
||||
import io.micrometer.observation.Observation;
|
||||
import io.micrometer.observation.ObservationHandler;
|
||||
import io.micrometer.observation.transport.ReceiverContext;
|
||||
import io.micrometer.tracing.TraceContext;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
|
||||
public class DubboServerTracingObservationHandler<T extends DubboServerContext> implements ObservationHandler<T> {
|
||||
|
||||
private static final String DEFAULT_TRACE_ID_KEY = "traceId";
|
||||
|
||||
private final Tracer tracer;
|
||||
|
||||
public DubboServerTracingObservationHandler(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScopeOpened(T context) {
|
||||
TraceContext traceContext = tracer.currentTraceContext().context();
|
||||
if (traceContext == null) {
|
||||
return;
|
||||
}
|
||||
RpcContext.getServerContext().setAttachment(DEFAULT_TRACE_ID_KEY, traceContext.traceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsContext(Observation.Context context) {
|
||||
return context instanceof ReceiverContext;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,10 @@
|
|||
*/
|
||||
package org.apache.dubbo.spring.boot.observability.autoconfigure;
|
||||
|
||||
import org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration;
|
||||
import org.apache.dubbo.spring.boot.observability.autoconfigure.annotation.ConditionalOnDubboTracingEnable;
|
||||
import org.apache.dubbo.tracing.handler.DubboClientTracingObservationHandler;
|
||||
import org.apache.dubbo.tracing.handler.DubboServerTracingObservationHandler;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
|
|
@ -40,7 +43,9 @@ import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX;
|
|||
"io.micrometer.tracing.Tracer",
|
||||
"io.micrometer.tracing.propagation.Propagator"
|
||||
})
|
||||
@AutoConfigureAfter(name = "org.springframework.boot.actuate.autoconfigure.tracing.MicrometerTracingAutoConfiguration")
|
||||
@AutoConfigureAfter(
|
||||
name = "org.springframework.boot.actuate.autoconfigure.tracing.MicrometerTracingAutoConfiguration",
|
||||
value = DubboAutoConfiguration.class)
|
||||
public class DubboMicrometerTracingAutoConfiguration {
|
||||
|
||||
/**
|
||||
|
|
@ -82,4 +87,22 @@ public class DubboMicrometerTracingAutoConfiguration {
|
|||
io.micrometer.tracing.Tracer tracer, io.micrometer.tracing.propagation.Propagator propagator) {
|
||||
return new io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler<>(tracer, propagator);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean({io.micrometer.tracing.Tracer.class})
|
||||
@Order(SENDER_TRACING_OBSERVATION_HANDLER_ORDER)
|
||||
public DubboClientTracingObservationHandler<?> dubboClientTracingObservationHandler(
|
||||
io.micrometer.tracing.Tracer tracer) {
|
||||
return new DubboClientTracingObservationHandler<>(tracer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean({io.micrometer.tracing.Tracer.class})
|
||||
@Order(RECEIVER_TRACING_OBSERVATION_HANDLER_ORDER)
|
||||
public DubboServerTracingObservationHandler<?> dubboServerTracingObservationHandler(
|
||||
io.micrometer.tracing.Tracer tracer) {
|
||||
return new DubboServerTracingObservationHandler<>(tracer);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.spring.boot.observability.autoconfigure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -47,12 +48,13 @@ class ObservationHandlerGrouping {
|
|||
void apply(List<ObservationHandler<?>> handlers, ObservationRegistry.ObservationConfig config) {
|
||||
MultiValueMap<Class<? extends ObservationHandler>, ObservationHandler<?>> groupings =
|
||||
new LinkedMultiValueMap<>();
|
||||
List<ObservationHandler<?>> handlersWithoutCategory = new ArrayList<>();
|
||||
for (ObservationHandler<?> handler : handlers) {
|
||||
Class<? extends ObservationHandler> category = findCategory(handler);
|
||||
if (category != null) {
|
||||
groupings.add(category, handler);
|
||||
} else {
|
||||
config.observationHandler(handler);
|
||||
handlersWithoutCategory.add(handler);
|
||||
}
|
||||
}
|
||||
for (Class<? extends ObservationHandler> category : this.categories) {
|
||||
|
|
@ -62,6 +64,9 @@ class ObservationHandlerGrouping {
|
|||
new ObservationHandler.FirstMatchingCompositeObservationHandler(handlerGroup));
|
||||
}
|
||||
}
|
||||
for (ObservationHandler<?> observationHandler : handlersWithoutCategory) {
|
||||
config.observationHandler(observationHandler);
|
||||
}
|
||||
}
|
||||
|
||||
private Class<? extends ObservationHandler> findCategory(ObservationHandler<?> handler) {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX;
|
||||
|
||||
|
|
@ -63,7 +64,7 @@ public class BraveAutoConfiguration {
|
|||
/**
|
||||
* Default value for application name if {@code spring.application.name} is not set.
|
||||
*/
|
||||
private static final String DEFAULT_APPLICATION_NAME = "dubbo-application";
|
||||
private static final String DEFAULT_APPLICATION_NAME = "unknown_dubbo_service";
|
||||
|
||||
private final DubboConfigurationProperties dubboConfigProperties;
|
||||
|
||||
|
|
@ -87,14 +88,15 @@ public class BraveAutoConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public brave.Tracing braveTracing(
|
||||
Environment environment,
|
||||
List<brave.handler.SpanHandler> spanHandlers,
|
||||
List<brave.TracingCustomizer> tracingCustomizers,
|
||||
brave.propagation.CurrentTraceContext currentTraceContext,
|
||||
brave.propagation.Propagation.Factory propagationFactory,
|
||||
brave.sampler.Sampler sampler) {
|
||||
String applicationName = dubboConfigProperties.getApplication().getName();
|
||||
if (StringUtils.isEmpty(applicationName)) {
|
||||
applicationName = DEFAULT_APPLICATION_NAME;
|
||||
if (StringUtils.isBlank(applicationName)) {
|
||||
applicationName = environment.getProperty("spring.application.name", DEFAULT_APPLICATION_NAME);
|
||||
}
|
||||
brave.Tracing.Builder builder = brave.Tracing.newBuilder()
|
||||
.currentTraceContext(currentTraceContext)
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ package org.apache.dubbo.spring.boot.observability.autoconfigure.otel;
|
|||
|
||||
import org.apache.dubbo.common.Version;
|
||||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.rpc.model.ModuleModel;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.spring.boot.autoconfigure.DubboConfigurationProperties;
|
||||
import org.apache.dubbo.spring.boot.observability.autoconfigure.DubboMicrometerTracingAutoConfiguration;
|
||||
import org.apache.dubbo.spring.boot.observability.autoconfigure.ObservabilityUtils;
|
||||
|
|
@ -38,6 +37,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX;
|
||||
|
||||
|
|
@ -62,15 +62,12 @@ public class OpenTelemetryAutoConfiguration {
|
|||
/**
|
||||
* Default value for application name if {@code spring.application.name} is not set.
|
||||
*/
|
||||
private static final String DEFAULT_APPLICATION_NAME = "application";
|
||||
private static final String DEFAULT_APPLICATION_NAME = "unknown_dubbo_service";
|
||||
|
||||
private final DubboConfigurationProperties dubboConfigProperties;
|
||||
|
||||
private final ModuleModel moduleModel;
|
||||
|
||||
OpenTelemetryAutoConfiguration(DubboConfigurationProperties dubboConfigProperties, ModuleModel moduleModel) {
|
||||
OpenTelemetryAutoConfiguration(DubboConfigurationProperties dubboConfigProperties) {
|
||||
this.dubboConfigProperties = dubboConfigProperties;
|
||||
this.moduleModel = moduleModel;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
@ -87,14 +84,14 @@ public class OpenTelemetryAutoConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
io.opentelemetry.sdk.trace.SdkTracerProvider otelSdkTracerProvider(
|
||||
Environment environment,
|
||||
ObjectProvider<io.opentelemetry.sdk.trace.SpanProcessor> spanProcessors,
|
||||
io.opentelemetry.sdk.trace.samplers.Sampler sampler) {
|
||||
String applicationName = moduleModel
|
||||
.getApplicationModel()
|
||||
.getApplicationConfigManager()
|
||||
.getApplication()
|
||||
.map(ApplicationConfig::getName)
|
||||
.orElse(DEFAULT_APPLICATION_NAME);
|
||||
String applicationName = dubboConfigProperties.getApplication().getName();
|
||||
if (StringUtils.isBlank(applicationName)) {
|
||||
applicationName = environment.getProperty("spring.application.name", DEFAULT_APPLICATION_NAME);
|
||||
}
|
||||
|
||||
// Due to https://github.com/micrometer-metrics/tracing/issues/343
|
||||
String RESOURCE_ATTRIBUTES_CLASS_NAME = "io.opentelemetry.semconv.ResourceAttributes";
|
||||
boolean isLowVersion = !ClassUtils.isPresent(
|
||||
|
|
|
|||
Loading…
Reference in New Issue