diff --git a/CHANGELOG.md b/CHANGELOG.md index d6bfa23cf..f0c153f59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,3 +23,4 @@ - [fix:fix app starting failed when user using custom OpenAPI bean.](https://github.com/Tencent/spring-cloud-tencent/pull/1398) - [fix: memory cost too many when using wildcard feign calls](https://github.com/Tencent/spring-cloud-tencent/pull/1400) - [feat:support consul config data.](https://github.com/Tencent/spring-cloud-tencent/pull/1401) +- [feat: support otel trace](https://github.com/Tencent/spring-cloud-tencent/pull/1402) \ No newline at end of file diff --git a/spring-cloud-tencent-examples/tsf-example/consumer-demo/pom.xml b/spring-cloud-tencent-examples/tsf-example/consumer-demo/pom.xml index 6c839dd70..9c9494728 100644 --- a/spring-cloud-tencent-examples/tsf-example/consumer-demo/pom.xml +++ b/spring-cloud-tencent-examples/tsf-example/consumer-demo/pom.xml @@ -36,6 +36,16 @@ org.springframework.cloud spring-cloud-starter-openfeign + + + com.tencent.cloud + spring-cloud-starter-tencent-metadata-transfer + + + + com.tencent.cloud + spring-cloud-starter-tencent-trace-plugin + diff --git a/spring-cloud-tencent-examples/tsf-example/provider-demo/pom.xml b/spring-cloud-tencent-examples/tsf-example/provider-demo/pom.xml index 348438516..108f456ec 100644 --- a/spring-cloud-tencent-examples/tsf-example/provider-demo/pom.xml +++ b/spring-cloud-tencent-examples/tsf-example/provider-demo/pom.xml @@ -39,6 +39,14 @@ org.springframework.cloud spring-cloud-starter-bootstrap + + com.tencent.cloud + spring-cloud-starter-tencent-metadata-transfer + + + com.tencent.cloud + spring-cloud-starter-tencent-trace-plugin + diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-trace-plugin/src/main/java/com/tencent/cloud/plugin/trace/TraceClientMetadataEnhancedPlugin.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-trace-plugin/src/main/java/com/tencent/cloud/plugin/trace/TraceClientMetadataEnhancedPlugin.java deleted file mode 100644 index dc61810a4..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-trace-plugin/src/main/java/com/tencent/cloud/plugin/trace/TraceClientMetadataEnhancedPlugin.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. - * - * Copyright (C) 2019 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.Map; - -import com.tencent.cloud.common.metadata.MetadataContext; -import com.tencent.cloud.common.metadata.MetadataContextHolder; -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 TraceClientMetadataEnhancedPlugin implements EnhancedPlugin { - - private final PolarisSDKContextManager polarisSDKContextManager; - - private final SpanAttributesProvider spanAttributesProvider; - - public TraceClientMetadataEnhancedPlugin(PolarisSDKContextManager polarisSDKContextManager, SpanAttributesProvider spanAttributesProvider) { - this.polarisSDKContextManager = polarisSDKContextManager; - this.spanAttributesProvider = spanAttributesProvider; - } - - @Override - public EnhancedPluginType getType() { - return EnhancedPluginType.Client.PRE; - } - - @Override - public void run(EnhancedPluginContext context) throws Throwable { - AssemblyAPI assemblyAPI = polarisSDKContextManager.getAssemblyAPI(); - Map attributes = new HashMap<>(); - if (null != spanAttributesProvider) { - Map additionalAttributes = spanAttributesProvider.getConsumerSpanAttributes(context); - if (CollectionUtils.isNotEmpty(additionalAttributes)) { - attributes.putAll(additionalAttributes); - } - } - MetadataContext metadataContext = MetadataContextHolder.get(); - Map transitiveCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE); - if (CollectionUtils.isNotEmpty(transitiveCustomAttributes)) { - for (Map.Entry entry : transitiveCustomAttributes.entrySet()) { - attributes.put("custom." + entry.getKey(), entry.getValue()); - } - } - Map disposableCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_DISPOSABLE); - if (CollectionUtils.isNotEmpty(disposableCustomAttributes)) { - for (Map.Entry entry : disposableCustomAttributes.entrySet()) { - attributes.put("custom." + entry.getKey(), entry.getValue()); - } - } - TraceAttributes traceAttributes = new TraceAttributes(); - traceAttributes.setAttributes(attributes); - traceAttributes.setAttributeLocation(TraceAttributes.AttributeLocation.SPAN); - assemblyAPI.updateTraceAttributes(traceAttributes); - } - - @Override - public int getOrder() { - return PluginOrderConstant.ClientPluginOrder.CONSUMER_TRACE_METADATA_PLUGIN_ORDER; - } - -} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-trace-plugin/src/main/java/com/tencent/cloud/plugin/trace/config/TraceEnhancedPluginAutoConfiguration.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-trace-plugin/src/main/java/com/tencent/cloud/plugin/trace/config/TraceEnhancedPluginAutoConfiguration.java index 932cd1421..9eb8970a4 100644 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-trace-plugin/src/main/java/com/tencent/cloud/plugin/trace/config/TraceEnhancedPluginAutoConfiguration.java +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-trace-plugin/src/main/java/com/tencent/cloud/plugin/trace/config/TraceEnhancedPluginAutoConfiguration.java @@ -19,7 +19,6 @@ package com.tencent.cloud.plugin.trace.config; import com.tencent.cloud.plugin.trace.SpanAttributesProvider; -import com.tencent.cloud.plugin.trace.TraceClientMetadataEnhancedPlugin; import com.tencent.cloud.plugin.trace.TraceServerMetadataEnhancedPlugin; import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.cloud.polaris.context.PolarisSDKContextManager; @@ -35,12 +34,6 @@ import org.springframework.context.annotation.Configuration; @ConditionalOnProperty(value = "spring.cloud.polaris.trace.enabled", matchIfMissing = true) public class TraceEnhancedPluginAutoConfiguration { - @Bean - public TraceClientMetadataEnhancedPlugin traceClientMetadataEnhancedPlugin( - PolarisSDKContextManager polarisSDKContextManager, @Autowired(required = false) SpanAttributesProvider spanAttributesProvider) { - return new TraceClientMetadataEnhancedPlugin(polarisSDKContextManager, spanAttributesProvider); - } - @Bean public TraceServerMetadataEnhancedPlugin traceServerMetadataEnhancedPlugin( PolarisSDKContextManager polarisSDKContextManager, @Autowired(required = false) SpanAttributesProvider spanAttributesProvider) {