com.tencent.polaris
diff --git a/polaris-discovery/polaris-discovery-api/src/main/java/com/tencent/polaris/api/core/ConsumerAPI.java b/polaris-discovery/polaris-discovery-api/src/main/java/com/tencent/polaris/api/core/ConsumerAPI.java
index 00f3915d5..59ee38a02 100644
--- a/polaris-discovery/polaris-discovery-api/src/main/java/com/tencent/polaris/api/core/ConsumerAPI.java
+++ b/polaris-discovery/polaris-discovery-api/src/main/java/com/tencent/polaris/api/core/ConsumerAPI.java
@@ -77,7 +77,11 @@ public interface ConsumerAPI extends AutoCloseable, Closeable {
* @param req 请求
* @return 单个服务实例
* @throws PolarisException 错误码及错误信息
+ *
+ * @deprecated
+ * * Use {@link com.tencent.polaris.assembly.api.AssemblyAPI#getOneInstance(com.tencent.polaris.assembly.api.pojo.GetOneInstanceRequest)} instead.
*/
+ @Deprecated
InstancesResponse getOneInstance(GetOneInstanceRequest req) throws PolarisException;
/**
@@ -86,7 +90,11 @@ public interface ConsumerAPI extends AutoCloseable, Closeable {
* @param req 请求
* @return 过滤后的服务列表
* @throws PolarisException 错误码及错误信息
+ *
+ * @deprecated
+ * *
Use {@link com.tencent.polaris.assembly.api.AssemblyAPI#getReachableInstances(com.tencent.polaris.assembly.api.pojo.GetReachableInstancesRequest)} instead.
*/
+ @Deprecated
InstancesResponse getInstances(GetInstancesRequest req) throws PolarisException;
/**
@@ -121,7 +129,11 @@ public interface ConsumerAPI extends AutoCloseable, Closeable {
*
* @param req 调用结果(包括成功失败,返回码,以及时延)
* @throws PolarisException 错误码及错误信息
+ *
+ * @deprecated
+ * *
Use {@link com.tencent.polaris.assembly.api.AssemblyAPI#updateServiceCallResult(ServiceCallResult)} instead.
*/
+ @Deprecated
void updateServiceCallResult(ServiceCallResult req) throws PolarisException;
/**
diff --git a/polaris-discovery/polaris-discovery-client/src/main/java/com/tencent/polaris/discovery/client/flow/CommonInstancesRequest.java b/polaris-discovery/polaris-discovery-client/src/main/java/com/tencent/polaris/discovery/client/flow/CommonInstancesRequest.java
index d79f9e62a..51d45be59 100644
--- a/polaris-discovery/polaris-discovery-client/src/main/java/com/tencent/polaris/discovery/client/flow/CommonInstancesRequest.java
+++ b/polaris-discovery/polaris-discovery-client/src/main/java/com/tencent/polaris/discovery/client/flow/CommonInstancesRequest.java
@@ -32,6 +32,7 @@
import com.tencent.polaris.api.rpc.GetHealthyInstancesRequest;
import com.tencent.polaris.api.rpc.GetInstancesRequest;
import com.tencent.polaris.api.rpc.GetOneInstanceRequest;
+import com.tencent.polaris.api.rpc.RequestBaseEntity;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.client.flow.BaseFlow;
import com.tencent.polaris.client.flow.FlowControlParam;
@@ -191,6 +192,25 @@ public CommonInstancesRequest(GetInstancesRequest request, Configuration configu
BaseFlow.buildFlowControlParam(request, configuration, this);
}
+ public CommonInstancesRequest(ServiceEventKey dstInstanceEventKey, ServiceEventKey dstRuleEventKey, ServiceEventKey srcRuleEventKey,
+ RouteInfo routeInfo, Criteria criteria, RequestBaseEntity request, Configuration configuration) {
+ this.srcRuleEventKey = srcRuleEventKey;
+ if (null != srcRuleEventKey) {
+ svcEventKeys.add(srcRuleEventKey);
+ }
+ this.dstInstanceEventKey = dstInstanceEventKey;
+ if (null != dstInstanceEventKey) {
+ svcEventKeys.add(dstInstanceEventKey);
+ }
+ this.dstRuleEventKey = dstRuleEventKey;
+ if (null != dstRuleEventKey) {
+ svcEventKeys.add(dstRuleEventKey);
+ }
+ this.routeInfo = routeInfo;
+ this.criteria = criteria;
+ BaseFlow.buildFlowControlParam(request, configuration, this);
+ }
+
public ServiceEventKey getSrcRuleEventKey() {
return srcRuleEventKey;
}
diff --git a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/common/PluginTypes.java b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/common/PluginTypes.java
index 1113b21cd..654587421 100644
--- a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/common/PluginTypes.java
+++ b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/common/PluginTypes.java
@@ -34,6 +34,7 @@
import com.tencent.polaris.api.plugin.route.ServiceRouter;
import com.tencent.polaris.api.plugin.server.ServerConnector;
import com.tencent.polaris.api.plugin.stat.StatReporter;
+import com.tencent.polaris.api.plugin.stat.TraceReporter;
import com.tencent.polaris.api.plugin.weight.WeightAdjuster;
/**
@@ -91,10 +92,15 @@ public enum PluginTypes {
WEIGHT_ADJUSTER(new PluginType(WeightAdjuster.class, 2)),
/**
- * 统计上报扩展点
+ * 统计监控上报扩展点
*/
STAT_REPORTER(new PluginType(StatReporter.class, 2)),
+ /**
+ * 调用链上报扩展点
+ */
+ TRACE_REPORTER(new PluginType(TraceReporter.class, 2)),
+
/**
* 限流器扩展点
*/
diff --git a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/compose/Extensions.java b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/compose/Extensions.java
index c3b54614e..cd65cdf57 100644
--- a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/compose/Extensions.java
+++ b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/compose/Extensions.java
@@ -44,6 +44,7 @@
import com.tencent.polaris.api.plugin.route.ServiceRouter;
import com.tencent.polaris.api.plugin.server.ServerConnector;
import com.tencent.polaris.api.plugin.stat.StatReporter;
+import com.tencent.polaris.api.plugin.stat.TraceReporter;
import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.api.utils.MapUtils;
import com.tencent.polaris.api.utils.StringUtils;
@@ -84,6 +85,9 @@ public class Extensions extends Destroyable {
private CircuitBreaker resourceBreaker;
private final List statReporters = new ArrayList<>();
+
+ private TraceReporter traceReporter;
+
private Supplier plugins;
//系统服务的路由链
@@ -191,6 +195,9 @@ public void init(Configuration config, Supplier plugins, ValueContext valueConte
// 加载监控上报
loadStatReporters(plugins);
+ // 加载调用链上报
+ loadTraceReporter(plugins);
+
// 加载优雅上下线插件
loadLosslessPolicies(config, plugins);
@@ -274,6 +281,15 @@ private void loadStatReporters(Supplier plugins) throws PolarisException {
}
}
+ private void loadTraceReporter(Supplier plugins) throws PolarisException {
+ if (configuration.getGlobal().getTraceReporter().isEnable()) {
+ Collection reporters = plugins.getPlugins(PluginTypes.TRACE_REPORTER.getBaseType());
+ if (CollectionUtils.isNotEmpty(reporters)) {
+ traceReporter = (TraceReporter) reporters.iterator().next();
+ }
+ }
+ }
+
private void loadLosslessPolicies(Configuration config, Supplier plugins) throws PolarisException {
if (!config.getProvider().getLossless().isEnable()) {
return;
@@ -546,6 +562,10 @@ public List getLosslessPolicies() {
return losslessPolicies;
}
+ public TraceReporter getTraceReporter() {
+ return traceReporter;
+ }
+
@Override
protected void doDestroy() {
if (MapUtils.isNotEmpty(httpServers)) {
diff --git a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/StatReporter.java b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/StatReporter.java
index d458c259c..73f37e6fb 100644
--- a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/StatReporter.java
+++ b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/StatReporter.java
@@ -20,7 +20,7 @@
import com.tencent.polaris.api.plugin.Plugin;
/**
- * 【扩展点接口】上报统计结果
+ * 【扩展点接口】上报统计监控
*
* @author andrewshan
* @date 2019/8/21
diff --git a/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/pojo/Capability.java b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/TraceReporter.java
similarity index 57%
rename from polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/pojo/Capability.java
rename to polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/TraceReporter.java
index 748049571..60a04ea36 100644
--- a/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/pojo/Capability.java
+++ b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/TraceReporter.java
@@ -1,22 +1,43 @@
-/*
- * Tencent is pleased to support the open source community by making Polaris 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.polaris.assembly.api.pojo;
-
-public enum Capability {
- ALL, TRACING, DISCOVERY, ROUTER, LOAD_BALANCER, CIRCUIT_BREAKER, RATE_LIMITER, AUTH
-}
+/*
+ * Tencent is pleased to support the open source community by making Polaris 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.polaris.api.plugin.stat;
+
+import java.util.Map;
+
+import com.tencent.polaris.api.plugin.Plugin;
+
+/**
+ * 【扩展点接口】上报调用链
+ *
+ * @author andrewshan
+ * @date 2024/6/2
+ */
+public interface TraceReporter extends Plugin {
+
+ /**
+ * set the attributes in trace span
+ * @param attributes span attributes
+ */
+ void setSpanAttributes(Map attributes);
+
+ /**
+ * set the attributes in baggage span
+ * @param attributes baggage attributes
+ */
+ void setBaggageAttributes(Map attributes);
+}
diff --git a/polaris-plugins/polaris-plugins-observability/pom.xml b/polaris-plugins/polaris-plugins-observability/pom.xml
index 9fd551a07..a60751920 100644
--- a/polaris-plugins/polaris-plugins-observability/pom.xml
+++ b/polaris-plugins/polaris-plugins-observability/pom.xml
@@ -18,6 +18,7 @@
stat-prometheus
stat-common
+ trace-otel
diff --git a/polaris-plugins/polaris-plugins-observability/trace-otel/pom.xml b/polaris-plugins/polaris-plugins-observability/trace-otel/pom.xml
new file mode 100644
index 000000000..943bc79d3
--- /dev/null
+++ b/polaris-plugins/polaris-plugins-observability/trace-otel/pom.xml
@@ -0,0 +1,29 @@
+
+
+
+ polaris-plugins-observability
+ com.tencent.polaris
+ ${revision}
+ ../pom.xml
+
+ 4.0.0
+
+ trace-otel
+ Polaris Plugins Observability Trace OTel
+ Polaris Plugins Observability Trace OTel JAR
+
+
+
+ polaris-plugin-api
+ com.tencent.polaris
+ ${project.version}
+
+
+ io.opentelemetry
+ opentelemetry-api
+ ${otel.version}
+
+
+
\ No newline at end of file
diff --git a/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporter.java b/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporter.java
new file mode 100644
index 000000000..db464d308
--- /dev/null
+++ b/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporter.java
@@ -0,0 +1,72 @@
+/*
+ * Tencent is pleased to support the open source community by making Polaris 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.polaris.plugins.stat.otel;
+
+import java.util.Map;
+
+import com.tencent.polaris.api.config.global.TraceReporterConfig;
+import com.tencent.polaris.api.exception.PolarisException;
+import com.tencent.polaris.api.plugin.PluginType;
+import com.tencent.polaris.api.plugin.common.InitContext;
+import com.tencent.polaris.api.plugin.common.PluginTypes;
+import com.tencent.polaris.api.plugin.compose.Extensions;
+import com.tencent.polaris.api.plugin.stat.TraceReporter;
+import io.opentelemetry.api.baggage.Baggage;
+import io.opentelemetry.api.baggage.BaggageBuilder;
+import io.opentelemetry.api.trace.Span;
+
+public class OtelTraceReporter implements TraceReporter {
+
+ @Override
+ public String getName() {
+ return TraceReporterConfig.DEFAULT_REPORTER_OTEL;
+ }
+
+ @Override
+ public PluginType getType() {
+ return PluginTypes.TRACE_REPORTER.getBaseType();
+ }
+
+ @Override
+ public void init(InitContext ctx) throws PolarisException {
+
+ }
+
+ @Override
+ public void postContextInit(Extensions ctx) throws PolarisException {
+
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+
+ @Override
+ public void setSpanAttributes(Map attributes) {
+ Span span = Span.current();
+ attributes.forEach(span::setAttribute);
+ }
+
+ @Override
+ public void setBaggageAttributes(Map attributes) {
+ BaggageBuilder builder = Baggage.current().toBuilder();
+ attributes.forEach(builder::put);
+ builder.build().makeCurrent();
+ }
+}
diff --git a/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/resources/META-INF/services/com.tencent.polaris.api.plugin.stat.TraceReporter b/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/resources/META-INF/services/com.tencent.polaris.api.plugin.stat.TraceReporter
new file mode 100644
index 000000000..56a3a64bf
--- /dev/null
+++ b/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/resources/META-INF/services/com.tencent.polaris.api.plugin.stat.TraceReporter
@@ -0,0 +1 @@
+com.tencent.polaris.plugins.stat.otel.OtelTraceReporter
\ No newline at end of file
diff --git a/polaris-plugins/polaris-plugins-observability/trace-otel/src/test/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporterTest.java b/polaris-plugins/polaris-plugins-observability/trace-otel/src/test/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporterTest.java
new file mode 100644
index 000000000..87366af32
--- /dev/null
+++ b/polaris-plugins/polaris-plugins-observability/trace-otel/src/test/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporterTest.java
@@ -0,0 +1,43 @@
+/*
+ * Tencent is pleased to support the open source community by making Polaris 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.polaris.plugins.stat.otel;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class OtelTraceReporterTest {
+
+ @Test
+ public void testSetSpanAttributes() {
+ OtelTraceReporter reporter = new OtelTraceReporter();
+ Map values = new HashMap<>();
+ values.put("key1", "value1");
+ reporter.setSpanAttributes(values);
+ }
+
+ @Test
+ public void testSetBaggageAttributes() {
+ OtelTraceReporter reporter = new OtelTraceReporter();
+ Map values = new HashMap<>();
+ values.put("key1", "value1");
+ reporter.setBaggageAttributes(values);
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 41b8967cb..cd68618e6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -97,6 +97,7 @@
3.16.1
-Xmx2048m
0.11.0
+ 1.38.0
3.0.0
3.2.0
3.2.0