feat: add trace report support (#1411)
Co-authored-by: andrew shan <45474304+andrewshan@users.noreply.github.com>pull/1412/head
parent
850a105522
commit
797b33f47f
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.springframework.tsf.core.context;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.tencent.cloud.common.metadata.MetadataContext;
|
||||||
|
import com.tencent.cloud.common.metadata.MetadataContextHolder;
|
||||||
|
import com.tencent.polaris.metadata.core.MetadataType;
|
||||||
|
import com.tencent.polaris.metadata.core.TransitiveType;
|
||||||
|
|
||||||
|
import org.springframework.tsf.core.entity.Tag;
|
||||||
|
|
||||||
|
public final class TsfContext {
|
||||||
|
|
||||||
|
static final int MAX_KEY_LENGTH = 32;
|
||||||
|
static final int MAX_VALUE_LENGTH = 128;
|
||||||
|
|
||||||
|
private TsfContext() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void putTags(Map<String, String> tagMap, Tag.ControlFlag... flags) {
|
||||||
|
if (tagMap == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MetadataContext tsfCoreContext = MetadataContextHolder.get();
|
||||||
|
TransitiveType transitive = TransitiveType.NONE;
|
||||||
|
if (null != flags) {
|
||||||
|
for (Tag.ControlFlag flag : flags) {
|
||||||
|
if (flag == Tag.ControlFlag.TRANSITIVE) {
|
||||||
|
transitive = TransitiveType.PASS_THROUGH;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, String> entry : tagMap.entrySet()) {
|
||||||
|
validateTag(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
tsfCoreContext.putMetadataAsMap(MetadataType.CUSTOM, transitive, false, tagMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void putTag(String key, String value, Tag.ControlFlag... flags) {
|
||||||
|
putTags(Collections.singletonMap(key, value), flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void validateTag(String key, String value) {
|
||||||
|
int keyLength = key.getBytes(StandardCharsets.UTF_8).length;
|
||||||
|
int valueLength = value.getBytes(StandardCharsets.UTF_8).length;
|
||||||
|
|
||||||
|
if (keyLength > MAX_KEY_LENGTH) {
|
||||||
|
throw new RuntimeException(String.format("Key \"%s\" length (after UTF-8 encoding) exceeding limit (%d)", key,
|
||||||
|
MAX_KEY_LENGTH));
|
||||||
|
}
|
||||||
|
if (valueLength > MAX_VALUE_LENGTH) {
|
||||||
|
throw new RuntimeException(String.format("Value \"%s\" length (after UTF-8 encoding) exceeding limit (%d)", value,
|
||||||
|
MAX_VALUE_LENGTH));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.springframework.tsf.core.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public class Tag implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update version whenever change the content in tag.
|
||||||
|
*/
|
||||||
|
public static final int VERSION = 1;
|
||||||
|
|
||||||
|
public enum ControlFlag {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tag transitive by all services.
|
||||||
|
*/
|
||||||
|
@SerializedName("0")
|
||||||
|
TRANSITIVE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tag not used in auth.
|
||||||
|
*/
|
||||||
|
@SerializedName("1")
|
||||||
|
NOT_IN_AUTH,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tag not used in route.
|
||||||
|
*/
|
||||||
|
@SerializedName("2")
|
||||||
|
NOT_IN_ROUTE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tag not used in trace.
|
||||||
|
*/
|
||||||
|
@SerializedName("3")
|
||||||
|
NOT_IN_SLEUTH,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tag not used in lane.
|
||||||
|
*/
|
||||||
|
@SerializedName("4")
|
||||||
|
NOT_IN_LANE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tag not used in unit.
|
||||||
|
*/
|
||||||
|
@SerializedName("5")
|
||||||
|
IN_UNIT
|
||||||
|
}
|
||||||
|
|
||||||
|
@SerializedName("k")
|
||||||
|
@Expose
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
@SerializedName("v")
|
||||||
|
@Expose
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
@SerializedName("f")
|
||||||
|
@Expose
|
||||||
|
private Set<ControlFlag> flags = new HashSet<>();
|
||||||
|
|
||||||
|
public Tag(String key, String value, ControlFlag... flags) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
this.flags = new HashSet<>(Arrays.asList(flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tag() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ControlFlag> getFlags() {
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFlags(Set<ControlFlag> flags) {
|
||||||
|
this.flags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object object) {
|
||||||
|
if (object instanceof Tag) {
|
||||||
|
Tag tag = (Tag) object;
|
||||||
|
return (key == null ? tag.key == null : key.equals(tag.key))
|
||||||
|
&& (flags == null ? tag.flags == null : flags.equals(tag.flags));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return (key == null ? 0 : key.hashCode()) + (flags == null ? 0 : flags.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Tag{" +
|
||||||
|
"key='" + key + '\'' +
|
||||||
|
", value='" + value + '\'' +
|
||||||
|
", flags=" + flags +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>spring-cloud-tencent-plugin-starters</artifactId>
|
||||||
|
<groupId>com.tencent.cloud</groupId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>spring-cloud-starter-tencent-trace-plugin</artifactId>
|
||||||
|
<name>Spring Cloud Tencent Trace Plugin</name>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.tencent.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-tencent-rpc-enhancement</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.tencent.polaris</groupId>
|
||||||
|
<artifactId>trace-otel</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
|
||||||
|
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
|
||||||
|
|
||||||
|
public interface SpanAttributesProvider {
|
||||||
|
|
||||||
|
Map<String, String> getConsumerSpanAttributes(EnhancedPluginContext context);
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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<String, String> attributes = new HashMap<>();
|
||||||
|
if (null != spanAttributesProvider) {
|
||||||
|
Map<String, String> additionalAttributes = spanAttributesProvider.getConsumerSpanAttributes(context);
|
||||||
|
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.setAttributes(attributes);
|
||||||
|
traceAttributes.setAttributeLocation(TraceAttributes.AttributeLocation.SPAN);
|
||||||
|
assemblyAPI.updateTraceAttributes(traceAttributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrder() {
|
||||||
|
return PluginOrderConstant.ClientPluginOrder.CONSUMER_TRACE_METADATA_PLUGIN_ORDER;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* 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 TraceServerMetadataEnhancedPlugin implements EnhancedPlugin {
|
||||||
|
|
||||||
|
private final PolarisSDKContextManager polarisSDKContextManager;
|
||||||
|
|
||||||
|
private final SpanAttributesProvider spanAttributesProvider;
|
||||||
|
|
||||||
|
public TraceServerMetadataEnhancedPlugin(PolarisSDKContextManager polarisSDKContextManager, SpanAttributesProvider spanAttributesProvider) {
|
||||||
|
this.polarisSDKContextManager = polarisSDKContextManager;
|
||||||
|
this.spanAttributesProvider = spanAttributesProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnhancedPluginType getType() {
|
||||||
|
return EnhancedPluginType.Server.PRE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(EnhancedPluginContext context) throws Throwable {
|
||||||
|
AssemblyAPI assemblyAPI = polarisSDKContextManager.getAssemblyAPI();
|
||||||
|
Map<String, String> attributes = new HashMap<>();
|
||||||
|
if (null != spanAttributesProvider) {
|
||||||
|
Map<String, String> additionalAttributes = spanAttributesProvider.getConsumerSpanAttributes(context);
|
||||||
|
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.setAttributes(attributes);
|
||||||
|
traceAttributes.setAttributeLocation(TraceAttributes.AttributeLocation.SPAN);
|
||||||
|
assemblyAPI.updateTraceAttributes(traceAttributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrder() {
|
||||||
|
return PluginOrderConstant.ServerPluginOrder.PROVIDER_TRACE_METADATA_PLUGIN_ORDER;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.config;
|
||||||
|
|
||||||
|
import com.tencent.cloud.common.constant.OrderConstant;
|
||||||
|
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
|
||||||
|
import com.tencent.polaris.factory.config.ConfigurationImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spring Cloud Tencent config Override polaris trace config.
|
||||||
|
*
|
||||||
|
* @author andrew 2024-06-18
|
||||||
|
*/
|
||||||
|
public class TraceConfigModifier implements PolarisConfigModifier {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modify(ConfigurationImpl configuration) {
|
||||||
|
configuration.getGlobal().getTraceReporter().setEnable(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrder() {
|
||||||
|
return OrderConstant.Modifier.TRACE_ORDER;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.config;
|
||||||
|
|
||||||
|
import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnPolarisEnabled
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.polaris.trace.enabled", matchIfMissing = true)
|
||||||
|
public class TraceConfigModifierAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TraceConfigModifier traceConfigModifier() {
|
||||||
|
return new TraceConfigModifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnProperty("spring.cloud.polaris.enabled")
|
||||||
|
@Import(TraceConfigModifierAutoConfiguration.class)
|
||||||
|
public class TraceConfigModifierBootstrapAutoConfiguration {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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.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;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnPolarisEnabled
|
||||||
|
@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) {
|
||||||
|
return new TraceServerMetadataEnhancedPlugin(polarisSDKContextManager, spanAttributesProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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.tsf;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.tencent.cloud.common.tsf.TsfConstant;
|
||||||
|
import com.tencent.cloud.plugin.trace.SpanAttributesProvider;
|
||||||
|
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
|
||||||
|
import com.tencent.polaris.api.utils.CollectionUtils;
|
||||||
|
import com.tencent.polaris.api.utils.StringUtils;
|
||||||
|
|
||||||
|
import org.springframework.cloud.client.ServiceInstance;
|
||||||
|
|
||||||
|
public class TsfSpanAttributesProvider implements SpanAttributesProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getConsumerSpanAttributes(EnhancedPluginContext context) {
|
||||||
|
Map<String, String> attributes = new HashMap<>();
|
||||||
|
if (null != context.getRequest().getUrl()) {
|
||||||
|
attributes.put("remoteInterface", context.getRequest().getUrl().getPath());
|
||||||
|
}
|
||||||
|
ServiceInstance targetServiceInstance = context.getTargetServiceInstance();
|
||||||
|
if (null != targetServiceInstance && CollectionUtils.isNotEmpty(targetServiceInstance.getMetadata())) {
|
||||||
|
String nsId = targetServiceInstance.getMetadata().get(TsfConstant.TSF_NAMESPACE_ID);
|
||||||
|
attributes.put("remote.namespace-id", StringUtils.defaultString(nsId));
|
||||||
|
String groupId = targetServiceInstance.getMetadata().get(TsfConstant.TSF_GROUP_ID);
|
||||||
|
attributes.put("remote.group-id", StringUtils.defaultString(groupId));
|
||||||
|
String applicationId = targetServiceInstance.getMetadata().get(TsfConstant.TSF_APPLICATION_ID);
|
||||||
|
attributes.put("remote.application-id", StringUtils.defaultString(applicationId));
|
||||||
|
}
|
||||||
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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.tsf;
|
||||||
|
|
||||||
|
import com.tencent.cloud.polaris.context.tsf.ConditionalOnTsfEnabled;
|
||||||
|
|
||||||
|
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)
|
||||||
|
@ConditionalOnTsfEnabled
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.polaris.trace.enabled", matchIfMissing = true)
|
||||||
|
public class TsfTracePropertiesAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public TsfSpanAttributesProvider tsfClientSpanAttributesProvider() {
|
||||||
|
return new TsfSpanAttributesProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||||
|
com.tencent.cloud.plugin.trace.config.TraceConfigModifierBootstrapAutoConfiguration
|
@ -0,0 +1,3 @@
|
|||||||
|
com.tencent.cloud.plugin.trace.config.TraceConfigModifierAutoConfiguration
|
||||||
|
com.tencent.cloud.plugin.trace.config.TraceEnhancedPluginAutoConfiguration
|
||||||
|
com.tencent.cloud.plugin.trace.tsf.TsfTracePropertiesAutoConfiguration
|
Loading…
Reference in new issue