feat:upgrade trace plugin. (#1480)

pull/1481/head
Haotian Zhang 1 week ago committed by GitHub
parent 8e1874b598
commit 01d24732af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -40,3 +40,4 @@
- [feat:upgrade spring cloud 2023 version.](https://github.com/Tencent/spring-cloud-tencent/pull/1451) - [feat:upgrade spring cloud 2023 version.](https://github.com/Tencent/spring-cloud-tencent/pull/1451)
- [feat:support concurrency rate limit.](https://github.com/Tencent/spring-cloud-tencent/pull/1455) - [feat:support concurrency rate limit.](https://github.com/Tencent/spring-cloud-tencent/pull/1455)
- [feat:support auth.](https://github.com/Tencent/spring-cloud-tencent/pull/1479) - [feat:support auth.](https://github.com/Tencent/spring-cloud-tencent/pull/1479)
- [feat:upgrade trace plugin.](https://github.com/Tencent/spring-cloud-tencent/pull/1480)

@ -25,6 +25,7 @@ import java.util.concurrent.ScheduledExecutorService;
import com.tencent.cloud.common.metadata.StaticMetadataManager; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.OkHttpUtil; import com.tencent.cloud.common.util.OkHttpUtil;
import com.tencent.cloud.common.util.OtUtils;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties; import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler; import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
@ -110,6 +111,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
InstanceRegisterRequest instanceRegisterRequest = new InstanceRegisterRequest(); InstanceRegisterRequest instanceRegisterRequest = new InstanceRegisterRequest();
instanceRegisterRequest.setNamespace(polarisDiscoveryProperties.getNamespace()); instanceRegisterRequest.setNamespace(polarisDiscoveryProperties.getNamespace());
instanceRegisterRequest.setService(serviceId); instanceRegisterRequest.setService(serviceId);
OtUtils.setOtServiceNameIfNeeded(serviceId);
instanceRegisterRequest.setHost(registration.getHost()); instanceRegisterRequest.setHost(registration.getHost());
instanceRegisterRequest.setPort(registration.getPort()); instanceRegisterRequest.setPort(registration.getPort());
instanceRegisterRequest.setWeight(polarisDiscoveryProperties.getWeight()); instanceRegisterRequest.setWeight(polarisDiscoveryProperties.getWeight());

@ -0,0 +1,84 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.common.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Utils for otel.
*
* @author Haotian Zhang
*/
public final class OtUtils {
/**
* Key of otel resource attributes.
*/
public static final String OTEL_RESOURCE_ATTRIBUTES = "otel.resource.attributes";
/**
* Key of lane id.
*/
public static final String OTEL_LANE_ID_KEY = "lane-id";
private static final Logger LOGGER = LoggerFactory.getLogger(OtUtils.class);
private static String otServiceName = null;
private OtUtils() {
}
/**
* If the service name is not set, it will be set when the service is registered.
*
* @param serviceName service name
*/
public static void setOtServiceNameIfNeeded(String serviceName) {
try {
String attributes = null;
if (null != System.getenv(OTEL_RESOURCE_ATTRIBUTES)) {
attributes = System.getenv(OTEL_RESOURCE_ATTRIBUTES);
}
if (null != System.getProperty(OTEL_RESOURCE_ATTRIBUTES)) {
attributes = System.getProperty(OTEL_RESOURCE_ATTRIBUTES);
}
if (attributes == null || !attributes.contains("service.name")) {
otServiceName = serviceName;
System.setProperty(OTEL_RESOURCE_ATTRIBUTES, "service.name=" + serviceName);
LOGGER.info("update ot service name, old:{}, new:{}",
attributes, System.getProperty(OTEL_RESOURCE_ATTRIBUTES));
}
else {
for (String attribute : attributes.split(",")) {
if (attribute.contains("service.name=")) {
otServiceName = attribute.replace("service.name=", "");
LOGGER.info("use env ot service name:{}", otServiceName);
}
}
}
}
catch (Throwable throwable) {
LOGGER.error("set ot service name failed.", throwable);
}
}
public static String getOtServiceName() {
return otServiceName;
}
}

@ -0,0 +1,50 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.plugin.trace;
import com.tencent.cloud.plugin.trace.attribute.SpanAttributesProvider;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
import com.tencent.cloud.rpc.enhancement.plugin.PluginOrderConstant;
import com.tencent.polaris.api.utils.ClassUtils;
import io.opentelemetry.context.Scope;
public class TraceClientFinallyEnhancedPlugin implements EnhancedPlugin {
public TraceClientFinallyEnhancedPlugin() {
}
@Override
public EnhancedPluginType getType() {
return EnhancedPluginType.Client.FINALLY;
}
@Override
public void run(EnhancedPluginContext context) throws Throwable {
Object otScope = context.getExtraData().get(SpanAttributesProvider.OT_SCOPE_KEY);
if (ClassUtils.isClassPresent("io.opentelemetry.context.Scope") && otScope instanceof Scope) {
((Scope) otScope).close();
}
}
@Override
public int getOrder() {
return PluginOrderConstant.ClientPluginOrder.TRACE_CLIENT_PLUGIN_ORDER;
}
}

@ -0,0 +1,78 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.plugin.trace;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.tencent.cloud.plugin.trace.attribute.SpanAttributesProvider;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
import com.tencent.cloud.rpc.enhancement.plugin.PluginOrderConstant;
import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.assembly.api.AssemblyAPI;
import com.tencent.polaris.assembly.api.pojo.TraceAttributes;
public class TraceClientPreEnhancedPlugin implements EnhancedPlugin {
private final PolarisSDKContextManager polarisSDKContextManager;
private final List<SpanAttributesProvider> spanAttributesProviderList;
public TraceClientPreEnhancedPlugin(PolarisSDKContextManager polarisSDKContextManager, List<SpanAttributesProvider> spanAttributesProviderList) {
this.polarisSDKContextManager = polarisSDKContextManager;
this.spanAttributesProviderList = spanAttributesProviderList;
}
@Override
public EnhancedPluginType getType() {
return EnhancedPluginType.Client.PRE;
}
@Override
public void run(EnhancedPluginContext context) throws Throwable {
Map<String, String> attributes = new HashMap<>();
if (CollectionUtils.isNotEmpty(spanAttributesProviderList)) {
for (SpanAttributesProvider spanAttributesProvider : spanAttributesProviderList) {
Map<String, String> additionalAttributes = spanAttributesProvider.getClientBaggageAttributes(context);
if (CollectionUtils.isNotEmpty(additionalAttributes)) {
attributes.putAll(additionalAttributes);
}
}
}
TraceAttributes traceAttributes = new TraceAttributes();
traceAttributes.setAttributes(attributes);
traceAttributes.setAttributeLocation(TraceAttributes.AttributeLocation.BAGGAGE);
AssemblyAPI assemblyAPI = polarisSDKContextManager.getAssemblyAPI();
assemblyAPI.updateTraceAttributes(traceAttributes);
Object otScope = traceAttributes.getOtScope();
if (otScope != null) {
context.getExtraData().put(SpanAttributesProvider.OT_SCOPE_KEY, otScope);
}
}
@Override
public int getOrder() {
return PluginOrderConstant.ClientPluginOrder.TRACE_CLIENT_PLUGIN_ORDER;
}
}

@ -18,10 +18,10 @@
package com.tencent.cloud.plugin.trace; package com.tencent.cloud.plugin.trace;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.plugin.trace.attribute.SpanAttributesProvider;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin; import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext; import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
@ -31,15 +31,15 @@ import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.assembly.api.AssemblyAPI; import com.tencent.polaris.assembly.api.AssemblyAPI;
import com.tencent.polaris.assembly.api.pojo.TraceAttributes; import com.tencent.polaris.assembly.api.pojo.TraceAttributes;
public class TraceServerMetadataEnhancedPlugin implements EnhancedPlugin { public class TraceServerPreEnhancedPlugin implements EnhancedPlugin {
private final PolarisSDKContextManager polarisSDKContextManager; private final PolarisSDKContextManager polarisSDKContextManager;
private final SpanAttributesProvider spanAttributesProvider; private final List<SpanAttributesProvider> spanAttributesProviderList;
public TraceServerMetadataEnhancedPlugin(PolarisSDKContextManager polarisSDKContextManager, SpanAttributesProvider spanAttributesProvider) { public TraceServerPreEnhancedPlugin(PolarisSDKContextManager polarisSDKContextManager, List<SpanAttributesProvider> spanAttributesProviderList) {
this.polarisSDKContextManager = polarisSDKContextManager; this.polarisSDKContextManager = polarisSDKContextManager;
this.spanAttributesProvider = spanAttributesProvider; this.spanAttributesProviderList = spanAttributesProviderList;
} }
@Override @Override
@ -49,35 +49,26 @@ public class TraceServerMetadataEnhancedPlugin implements EnhancedPlugin {
@Override @Override
public void run(EnhancedPluginContext context) throws Throwable { public void run(EnhancedPluginContext context) throws Throwable {
AssemblyAPI assemblyAPI = polarisSDKContextManager.getAssemblyAPI();
Map<String, String> attributes = new HashMap<>(); Map<String, String> attributes = new HashMap<>();
if (null != spanAttributesProvider) { if (CollectionUtils.isNotEmpty(spanAttributesProviderList)) {
Map<String, String> additionalAttributes = spanAttributesProvider.getConsumerSpanAttributes(context); for (SpanAttributesProvider spanAttributesProvider : spanAttributesProviderList) {
if (CollectionUtils.isNotEmpty(additionalAttributes)) { Map<String, String> additionalAttributes = spanAttributesProvider.getServerSpanAttributes(context);
attributes.putAll(additionalAttributes); if (CollectionUtils.isNotEmpty(additionalAttributes)) {
} attributes.putAll(additionalAttributes);
} }
MetadataContext metadataContext = MetadataContextHolder.get();
Map<String, String> transitiveCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE);
if (CollectionUtils.isNotEmpty(transitiveCustomAttributes)) {
for (Map.Entry<String, String> entry : transitiveCustomAttributes.entrySet()) {
attributes.put("custom." + entry.getKey(), entry.getValue());
}
}
Map<String, String> disposableCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_DISPOSABLE);
if (CollectionUtils.isNotEmpty(disposableCustomAttributes)) {
for (Map.Entry<String, String> entry : disposableCustomAttributes.entrySet()) {
attributes.put("custom." + entry.getKey(), entry.getValue());
} }
} }
TraceAttributes traceAttributes = new TraceAttributes(); TraceAttributes traceAttributes = new TraceAttributes();
traceAttributes.setAttributes(attributes); traceAttributes.setAttributes(attributes);
traceAttributes.setAttributeLocation(TraceAttributes.AttributeLocation.SPAN); traceAttributes.setAttributeLocation(TraceAttributes.AttributeLocation.SPAN);
AssemblyAPI assemblyAPI = polarisSDKContextManager.getAssemblyAPI();
assemblyAPI.updateTraceAttributes(traceAttributes); assemblyAPI.updateTraceAttributes(traceAttributes);
} }
@Override @Override
public int getOrder() { public int getOrder() {
return PluginOrderConstant.ServerPluginOrder.PROVIDER_TRACE_METADATA_PLUGIN_ORDER; return PluginOrderConstant.ServerPluginOrder.TRACE_SERVER_PRE_PLUGIN_ORDER;
} }
} }

@ -0,0 +1,99 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.plugin.trace.attribute;
import java.util.HashMap;
import java.util.Map;
import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.metadata.core.MessageMetadataContainer;
import com.tencent.polaris.metadata.core.MetadataType;
import com.tencent.polaris.metadata.core.constant.MetadataConstants;
import com.tencent.polaris.metadata.core.manager.CalleeMetadataContainerGroup;
import static com.tencent.cloud.common.util.OtUtils.OTEL_LANE_ID_KEY;
import static com.tencent.polaris.plugins.router.lane.LaneRouter.TRAFFIC_STAIN_LABEL;
/**
* Implementation of {@link SpanAttributesProvider} for polaris.
*
* @author Haotian Zhang
*/
public class PolarisSpanAttributesProvider implements SpanAttributesProvider {
@Override
public Map<String, String> getServerSpanAttributes(EnhancedPluginContext context) {
Map<String, String> attributes = new HashMap<>();
MetadataContext metadataContext = MetadataContextHolder.get();
Map<String, String> transitiveCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE);
if (CollectionUtils.isNotEmpty(transitiveCustomAttributes)) {
for (Map.Entry<String, String> entry : transitiveCustomAttributes.entrySet()) {
attributes.put("custom." + entry.getKey(), entry.getValue());
}
}
Map<String, String> disposableCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_DISPOSABLE);
if (CollectionUtils.isNotEmpty(disposableCustomAttributes)) {
for (Map.Entry<String, String> entry : disposableCustomAttributes.entrySet()) {
attributes.put("custom." + entry.getKey(), entry.getValue());
}
}
Map<String, String> upstreamDisposableCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_UPSTREAM_DISPOSABLE);
if (CollectionUtils.isNotEmpty(upstreamDisposableCustomAttributes)) {
for (Map.Entry<String, String> entry : upstreamDisposableCustomAttributes.entrySet()) {
attributes.put("custom." + entry.getKey(), entry.getValue());
}
}
attributes.put("http.port", CalleeMetadataContainerGroup.getStaticApplicationMetadataContainer()
.getRawMetadataStringValue(MetadataConstants.LOCAL_PORT));
return attributes;
}
@Override
public Map<String, String> getClientBaggageAttributes(EnhancedPluginContext context) {
Map<String, String> attributes = new HashMap<>();
MetadataContext metadataContext = MetadataContextHolder.get();
Map<String, String> transitiveCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE);
if (CollectionUtils.isNotEmpty(transitiveCustomAttributes)) {
for (Map.Entry<String, String> entry : transitiveCustomAttributes.entrySet()) {
attributes.put("custom." + entry.getKey(), entry.getValue());
}
}
Map<String, String> disposableCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_DISPOSABLE);
if (CollectionUtils.isNotEmpty(disposableCustomAttributes)) {
for (Map.Entry<String, String> entry : disposableCustomAttributes.entrySet()) {
attributes.put("custom." + entry.getKey(), entry.getValue());
}
}
attributes.put("http.port", CalleeMetadataContainerGroup.getStaticApplicationMetadataContainer()
.getRawMetadataStringValue(MetadataConstants.LOCAL_PORT));
attributes.put("net.peer.service", context.getTargetServiceInstance().getServiceId());
String serviceLane = metadataContext.getMetadataContainer(MetadataType.MESSAGE, false)
.getRawMetadataMapValue(MessageMetadataContainer.LABEL_MAP_KEY_HEADER, TRAFFIC_STAIN_LABEL);
if (StringUtils.isNotBlank(serviceLane)) {
String[] splits = StringUtils.split(serviceLane, "/");
if (splits.length >= 2) {
attributes.put(OTEL_LANE_ID_KEY, splits[1]);
}
}
return attributes;
}
}

@ -15,13 +15,25 @@
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*/ */
package com.tencent.cloud.plugin.trace; package com.tencent.cloud.plugin.trace.attribute;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext; import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
public interface SpanAttributesProvider { public interface SpanAttributesProvider {
Map<String, String> getConsumerSpanAttributes(EnhancedPluginContext context); /**
* Key of OT scope object to save in EnhancedPluginContext.
*/
String OT_SCOPE_KEY = "OT_SCOPE_KEY";
default Map<String, String> getServerSpanAttributes(EnhancedPluginContext context) {
return new HashMap<>();
}
default Map<String, String> getClientBaggageAttributes(EnhancedPluginContext context) {
return new HashMap<>();
}
} }

@ -15,12 +15,12 @@
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*/ */
package com.tencent.cloud.plugin.trace.tsf; package com.tencent.cloud.plugin.trace.attribute.tsf;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.tencent.cloud.plugin.trace.SpanAttributesProvider; import com.tencent.cloud.plugin.trace.attribute.SpanAttributesProvider;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext; import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
import com.tencent.polaris.api.utils.CollectionUtils; import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.api.utils.StringUtils; import com.tencent.polaris.api.utils.StringUtils;
@ -31,7 +31,7 @@ import org.springframework.cloud.client.ServiceInstance;
public class TsfSpanAttributesProvider implements SpanAttributesProvider { public class TsfSpanAttributesProvider implements SpanAttributesProvider {
@Override @Override
public Map<String, String> getConsumerSpanAttributes(EnhancedPluginContext context) { public Map<String, String> getClientBaggageAttributes(EnhancedPluginContext context) {
Map<String, String> attributes = new HashMap<>(); Map<String, String> attributes = new HashMap<>();
if (null != context.getRequest().getUrl()) { if (null != context.getRequest().getUrl()) {
attributes.put("remoteInterface", context.getRequest().getUrl().getPath()); attributes.put("remoteInterface", context.getRequest().getUrl().getPath());
@ -53,5 +53,4 @@ public class TsfSpanAttributesProvider implements SpanAttributesProvider {
} }
return attributes; return attributes;
} }
} }

@ -17,12 +17,19 @@
package com.tencent.cloud.plugin.trace.config; package com.tencent.cloud.plugin.trace.config;
import com.tencent.cloud.plugin.trace.SpanAttributesProvider; import java.util.List;
import com.tencent.cloud.plugin.trace.TraceServerMetadataEnhancedPlugin;
import com.tencent.cloud.plugin.trace.TraceClientFinallyEnhancedPlugin;
import com.tencent.cloud.plugin.trace.TraceClientPreEnhancedPlugin;
import com.tencent.cloud.plugin.trace.TraceServerPreEnhancedPlugin;
import com.tencent.cloud.plugin.trace.attribute.PolarisSpanAttributesProvider;
import com.tencent.cloud.plugin.trace.attribute.SpanAttributesProvider;
import com.tencent.cloud.plugin.trace.attribute.tsf.TsfSpanAttributesProvider;
import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -34,9 +41,31 @@ import org.springframework.context.annotation.Configuration;
public class TraceEnhancedPluginAutoConfiguration { public class TraceEnhancedPluginAutoConfiguration {
@Bean @Bean
public TraceServerMetadataEnhancedPlugin traceServerMetadataEnhancedPlugin( public TraceServerPreEnhancedPlugin traceServerPreEnhancedPlugin(
PolarisSDKContextManager polarisSDKContextManager, @Autowired(required = false) SpanAttributesProvider spanAttributesProvider) { PolarisSDKContextManager polarisSDKContextManager, @Autowired(required = false) List<SpanAttributesProvider> spanAttributesProviderList) {
return new TraceServerMetadataEnhancedPlugin(polarisSDKContextManager, spanAttributesProvider); return new TraceServerPreEnhancedPlugin(polarisSDKContextManager, spanAttributesProviderList);
}
@Bean
public TraceClientPreEnhancedPlugin traceClientPreEnhancedPlugin(
PolarisSDKContextManager polarisSDKContextManager, @Autowired(required = false) List<SpanAttributesProvider> spanAttributesProviderList) {
return new TraceClientPreEnhancedPlugin(polarisSDKContextManager, spanAttributesProviderList);
}
@Bean
public TraceClientFinallyEnhancedPlugin traceClientFinallyEnhancedPlugin() {
return new TraceClientFinallyEnhancedPlugin();
}
@Bean
@ConditionalOnMissingBean
public PolarisSpanAttributesProvider polarisSpanAttributesProvider() {
return new PolarisSpanAttributesProvider();
} }
@Bean
@ConditionalOnMissingBean
public TsfSpanAttributesProvider tsfClientSpanAttributesProvider() {
return new TsfSpanAttributesProvider();
}
} }

@ -1,35 +0,0 @@
/*
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.plugin.trace.tsf;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.cloud.polaris.trace.enabled", matchIfMissing = true)
public class TsfTracePropertiesAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public TsfSpanAttributesProvider tsfClientSpanAttributesProvider() {
return new TsfSpanAttributesProvider();
}
}

@ -1,3 +1,2 @@
com.tencent.cloud.plugin.trace.config.TraceConfigModifierAutoConfiguration com.tencent.cloud.plugin.trace.config.TraceConfigModifierAutoConfiguration
com.tencent.cloud.plugin.trace.config.TraceEnhancedPluginAutoConfiguration com.tencent.cloud.plugin.trace.config.TraceEnhancedPluginAutoConfiguration
com.tencent.cloud.plugin.trace.tsf.TsfTracePropertiesAutoConfiguration

@ -61,6 +61,12 @@ public final class TsfCoreEnvironmentPostProcessor implements EnvironmentPostPro
if (StringUtils.isNotBlank(tsfAppId)) { if (StringUtils.isNotBlank(tsfAppId)) {
Map<String, Object> defaultProperties = new HashMap<>(); Map<String, Object> defaultProperties = new HashMap<>();
// enabled
String polarisEnabled = environment.getProperty("spring.cloud.polaris.enabled");
if (StringUtils.isBlank(polarisEnabled)) {
defaultProperties.put("spring.cloud.polaris.enabled", true);
}
// lossless // lossless
String polarisAdminPort = environment.getProperty("polaris_admin_port"); String polarisAdminPort = environment.getProperty("polaris_admin_port");
if (StringUtils.isNotBlank(polarisAdminPort)) { if (StringUtils.isNotBlank(polarisAdminPort)) {

@ -19,7 +19,9 @@ package com.tencent.cloud.rpc.enhancement.plugin;
import java.net.URI; import java.net.URI;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -35,19 +37,13 @@ import org.springframework.cloud.client.ServiceInstance;
public class EnhancedPluginContext { public class EnhancedPluginContext {
private static final Logger LOGGER = LoggerFactory.getLogger(EnhancedPluginContext.class); private static final Logger LOGGER = LoggerFactory.getLogger(EnhancedPluginContext.class);
private final Map<String, Object> extraData = new ConcurrentHashMap<>();
private Object originRequest; private Object originRequest;
private EnhancedRequestContext request; private EnhancedRequestContext request;
private EnhancedResponseContext response; private EnhancedResponseContext response;
private Throwable throwable; private Throwable throwable;
private long delay; private long delay;
private ServiceInstance localServiceInstance; private ServiceInstance localServiceInstance;
/** /**
* targetServiceInstance only exist in a client runner type. * targetServiceInstance only exist in a client runner type.
*/ */
@ -126,6 +122,10 @@ public class EnhancedPluginContext {
} }
} }
public Map<String, Object> getExtraData() {
return extraData;
}
@Override @Override
public String toString() { public String toString() {
return "EnhancedPluginContext{" + return "EnhancedPluginContext{" +

@ -63,15 +63,23 @@ public class PluginOrderConstant {
* {@link com.tencent.cloud.plugin.trace.TraceMetadataEnhancedPlugin}. * {@link com.tencent.cloud.plugin.trace.TraceMetadataEnhancedPlugin}.
*/ */
public static final int CONSUMER_TRACE_METADATA_PLUGIN_ORDER = CONSUMER_TRANSFER_METADATA_PLUGIN_ORDER - 1; public static final int CONSUMER_TRACE_METADATA_PLUGIN_ORDER = CONSUMER_TRANSFER_METADATA_PLUGIN_ORDER - 1;
/**
* order for
* {@link com.tencent.cloud.plugin.trace.TraceClientPreEnhancedPlugin}
* and
* {@link com.tencent.cloud.plugin.trace.TraceClientFinallyEnhancedPlugin}.
*/
public static final int TRACE_CLIENT_PLUGIN_ORDER = Ordered.HIGHEST_PRECEDENCE + 3;
} }
public static class ServerPluginOrder { public static class ServerPluginOrder {
/** /**
* order for * order for
* {@link com.tencent.cloud.plugin.trace.TraceServerMetadataEnhancedPlugin}. * {@link com.tencent.cloud.plugin.trace.TraceServerPreEnhancedPlugin}.
*/ */
public static final int PROVIDER_TRACE_METADATA_PLUGIN_ORDER = Ordered.HIGHEST_PRECEDENCE + 1; public static final int TRACE_SERVER_PRE_PLUGIN_ORDER = Ordered.HIGHEST_PRECEDENCE + 1;
} }
} }

Loading…
Cancel
Save