tags = new HashMap<>();
@@ -121,9 +137,9 @@ public SofaTracerSpan(SofaTracer sofaTracer, long startTime, String operationNam
/**
* Note:
- *
+ *
* 1.As a server-side: After reverting back to {@link SofaTracerSpanContext}, you can directly construct Server Span (traceId, spanId unchanged)
- *
+ *
* 2.As a client: need to be built by {@link SofaTracer.SofaTracerSpanBuilder#start()}
*
* @param sofaTracer sofaTracer
@@ -167,6 +183,28 @@ public void finish(long endTime) {
SpanExtensionFactory.logStoppedSpan(this);
}
+ /**
+ * Add event.
+ *
+ * @param eventData the event data
+ */
+ public void addEvent(SpanEventData eventData) {
+ if (eventData == null) {
+ SelfLog.error("event is null");
+ return;
+ }
+
+ if (this.endTime > 0 && System.currentTimeMillis() > this.endTime) {
+ // span is closed, can not report event
+ SelfLog.error("span is closed, can not add event");
+ return;
+ }
+
+ SofaTracerSpan clonedSpan = this.cloneInstance();
+ clonedSpan.setEventData(eventData);
+ this.sofaTracer.reportEvent(clonedSpan);
+ }
+
@Override
public void close() {
this.finish();
@@ -222,6 +260,12 @@ public Span log(long currentTime, String eventValue) {
return this.log(currentTime, fields);
}
+ /**
+ * Log span.
+ *
+ * @param logData the log data
+ * @return the span
+ */
public Span log(LogData logData) {
if (logData == null) {
return this;
@@ -258,8 +302,8 @@ public Span log(long currentTime, String eventName, /* @Nullable */Object payloa
}
/**
- *
* The default settings are business baggage
+ *
* @param key
* @param value
* @return
@@ -272,6 +316,7 @@ public Span setBaggageItem(String key, String value) {
/**
* The default read are business baggage
+ *
* @param key
* @return
*/
@@ -289,12 +334,13 @@ public Span setOperationName(String operationName) {
//======================= Extended API interface starts
/**
+ * Report error.
*
- * @param errorType errorType error description:timeout_error/biz_error...
- * @param context context
- * @param e e
- * @param errorSourceApp errorSourceApp trade|rpc
- * @param errorSources errorSources
+ * @param errorType errorType error description:timeout_error/biz_error...
+ * @param context context
+ * @param e e
+ * @param errorSourceApp errorSourceApp trade|rpc
+ * @param errorSources errorSources
*/
public void reportError(String errorType, Map context, Throwable e,
String errorSourceApp, String... errorSources) {
@@ -355,11 +401,11 @@ public void profile(String profileApp, String protocolType, String profileMessag
* Return itself as the parent of the next context
*
* Use countMatches to count . for higher performance, see performance test data for com.alipay.common.tracer.benchmark.CountBenchmark
-
* Preventing SofaTracerSpan from nesting too deeply causes a memory leak.
* This time recreates a context so that the above context can be released.
*
- * @return
+ *
+ * @return this as parent when exceed layer
*/
public SofaTracerSpan getThisAsParentWhenExceedLayer() {
final SofaTracerSpan parent;
@@ -385,6 +431,11 @@ public SofaTracerSpan getThisAsParentWhenExceedLayer() {
//======================= Extended API interface end
+ /**
+ * Gets span references.
+ *
+ * @return the span references
+ */
public List getSpanReferences() {
if (spanReferences == null) {
return Collections.emptyList();
@@ -392,62 +443,155 @@ public List getSpanReferences() {
return Collections.unmodifiableList(spanReferences);
}
+ /**
+ * Gets sofa tracer.
+ *
+ * @return the sofa tracer
+ */
public SofaTracer getSofaTracer() {
return sofaTracer;
}
+ /**
+ * Gets start time.
+ *
+ * @return the start time
+ */
public long getStartTime() {
return startTime;
}
+ /**
+ * Sets start time.
+ *
+ * @param startTime the start time
+ */
public void setStartTime(long startTime) {
this.startTime = startTime;
}
+ /**
+ * Gets end time.
+ *
+ * @return the end time
+ */
public long getEndTime() {
return endTime;
}
+ /**
+ * Sets end time.
+ *
+ * @param endTime the end time
+ */
public void setEndTime(long endTime) {
this.endTime = endTime;
}
+ /**
+ * Gets duration microseconds.
+ *
+ * @return the duration microseconds
+ */
public long getDurationMicroseconds() {
return this.endTime - this.startTime;
}
+ /**
+ * Gets tags with str.
+ *
+ * @return the tags with str
+ */
public Map getTagsWithStr() {
return tagsWithStr;
}
+ /**
+ * Gets tags with bool.
+ *
+ * @return the tags with bool
+ */
public Map getTagsWithBool() {
return tagsWithBool;
}
+ /**
+ * Gets tags with number.
+ *
+ * @return the tags with number
+ */
public Map getTagsWithNumber() {
return tagsWithNumber;
}
+ /**
+ * Gets operation name.
+ *
+ * @return the operation name
+ */
public String getOperationName() {
return operationName;
}
+ /**
+ * Gets sofa tracer span context.
+ *
+ * @return the sofa tracer span context
+ */
public SofaTracerSpanContext getSofaTracerSpanContext() {
return sofaTracerSpanContext;
}
+ /**
+ * Gets logs.
+ *
+ * @return the logs
+ */
public ConcurrentLinkedQueue getLogs() {
return logs;
}
+ /**
+ * Gets log type.
+ *
+ * @return the log type
+ */
public String getLogType() {
return logType;
}
+ /**
+ * Sets log type.
+ *
+ * @param logType the log type
+ */
public void setLogType(String logType) {
this.logType = logType;
}
+ /**
+ * Gets event data.
+ *
+ * @return the event data
+ */
+ public SpanEventData getEventData() {
+ return eventData;
+ }
+
+ /**
+ * Sets event data.
+ *
+ * @param eventData the event data
+ */
+ public void setEventData(SpanEventData eventData) {
+ this.eventData = eventData;
+ }
+
+ /**
+ * Gets parent sofa tracer span.
+ *
+ * @return the parent sofa tracer span
+ */
public SofaTracerSpan getParentSofaTracerSpan() {
if (this.parentSofaTracerSpan != null) {
return this.parentSofaTracerSpan.getThisAsParentWhenExceedLayer();
@@ -455,14 +599,29 @@ public SofaTracerSpan getParentSofaTracerSpan() {
return null;
}
+ /**
+ * Sets parent sofa tracer span.
+ *
+ * @param parentSofaTracerSpan the parent sofa tracer span
+ */
public void setParentSofaTracerSpan(SofaTracerSpan parentSofaTracerSpan) {
this.parentSofaTracerSpan = parentSofaTracerSpan;
}
+ /**
+ * Is server boolean.
+ *
+ * @return the boolean
+ */
public boolean isServer() {
return Tags.SPAN_KIND_SERVER.equals(tagsWithStr.get(Tags.SPAN_KIND.getKey()));
}
+ /**
+ * Is client boolean.
+ *
+ * @return the boolean
+ */
public boolean isClient() {
return Tags.SPAN_KIND_CLIENT.equals(tagsWithStr.get(Tags.SPAN_KIND.getKey()));
}
diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SpanEventData.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SpanEventData.java
new file mode 100644
index 000000000..76cb962c0
--- /dev/null
+++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SpanEventData.java
@@ -0,0 +1,127 @@
+/*
+ * 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 com.alipay.common.tracer.core.span;
+
+import com.alipay.common.tracer.core.utils.StringUtils;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * The type Span event data.
+ *
+ * @author yuqian
+ * @version : SpanEventData.java, v 0.1 2025-04-07 20:17 yuqian Exp $$
+ */
+public class SpanEventData implements Serializable {
+
+ private long timestamp;
+
+ private final Map eventTagWithStr = new ConcurrentHashMap<>();
+
+ private final Map eventTagWithNumber = new ConcurrentHashMap<>();
+
+ private final Map eventTagWithBool = new ConcurrentHashMap<>();
+
+ /**
+ * Gets timestamp.
+ *
+ * @return the timestamp
+ */
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ /**
+ * Sets timestamp.
+ *
+ * @param timestamp the timestamp
+ */
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ /**
+ * Gets event tag with number.
+ *
+ * @return the event tag with number
+ */
+ public Map getEventTagWithNumber() {
+ return eventTagWithNumber;
+ }
+
+ /**
+ * Gets event tag with bool.
+ *
+ * @return the event tag with bool
+ */
+ public Map getEventTagWithBool() {
+ return eventTagWithBool;
+ }
+
+ /**
+ * Gets event tag with str.
+ *
+ * @return the event tag with str
+ */
+ public Map getEventTagWithStr() {
+ return eventTagWithStr;
+ }
+
+ /**
+ * Adds a string tag to this event.
+ *
+ * @param key the tag key
+ * @param value the tag value
+ * @return this SpanEventData for chaining
+ */
+ public SpanEventData addTag(String key, String value) {
+ if (StringUtils.isNotBlank(key) && value != null) {
+ eventTagWithStr.put(key, value);
+ }
+ return this;
+ }
+
+ /**
+ * Adds a numeric tag to this event.
+ *
+ * @param key the tag key
+ * @param value the tag value
+ * @return this SpanEventData for chaining
+ */
+ public SpanEventData addTag(String key, Number value) {
+ if (StringUtils.isNotBlank(key) && value != null) {
+ eventTagWithNumber.put(key, value);
+ }
+ return this;
+ }
+
+ /**
+ * Adds a boolean tag to this event.
+ *
+ * @param key the tag key
+ * @param value the tag value
+ * @return this SpanEventData for chaining
+ */
+ public SpanEventData addTag(String key, Boolean value) {
+ if (StringUtils.isNotBlank(key) && value != null) {
+ eventTagWithBool.put(key, value);
+ }
+ return this;
+ }
+}
\ No newline at end of file
diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporterTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporterTest.java
new file mode 100644
index 000000000..3dba5567c
--- /dev/null
+++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporterTest.java
@@ -0,0 +1,156 @@
+/*
+ * 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 com.alipay.common.tracer.core.reporter.digest.event;
+
+import com.alipay.common.tracer.core.SofaTracer;
+import com.alipay.common.tracer.core.appender.self.SelfLog;
+import com.alipay.common.tracer.core.base.AbstractTestBase;
+import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration;
+import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext;
+import com.alipay.common.tracer.core.span.SofaTracerSpan;
+import com.alipay.common.tracer.core.tracertest.encoder.ClientSpanEventEncoder;
+import com.alipay.common.tracer.core.tracertest.type.TracerTestLogEnum;
+import com.alipay.common.tracer.core.utils.StringUtils;
+import io.opentracing.tag.Tags;
+import org.apache.commons.io.FileUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+import java.util.concurrent.*;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+/**
+ * @author yuqian
+ * @version : SpanEventDiskReporterTest.java, v 0.1 2025-03-10 16:59 yuqian Exp $$
+ */
+public class SpanEventDiskReporterTest extends AbstractTestBase {
+
+ private final String eventLogType = TracerTestLogEnum.RPC_CLIENT_EVENT
+ .getDefaultLogName();
+
+ private final String expectRollingPolicy = SofaTracerConfiguration
+ .getRollingPolicy(TracerTestLogEnum.RPC_CLIENT_EVENT
+ .getRollingKey());
+
+ private final String expectLogReserveConfig = SofaTracerConfiguration
+ .getLogReserveConfig(TracerTestLogEnum.RPC_CLIENT_EVENT
+ .getLogReverseKey());
+
+ private final ClientSpanEventEncoder clientSpanEventEncoder = new ClientSpanEventEncoder();
+
+ private SpanEventDiskReporter spanEventDiskReporter;
+
+ private SofaTracerSpan sofaTracerSpan;
+
+ @Before
+ public void before() {
+ this.spanEventDiskReporter = new SpanEventDiskReporter(eventLogType, expectRollingPolicy,
+ expectLogReserveConfig, clientSpanEventEncoder, null);
+ this.sofaTracerSpan = mock(SofaTracerSpan.class);
+ }
+
+ @Test
+ public void testGetDigestReporterType() {
+ assertEquals(eventLogType, this.spanEventDiskReporter.getEventLogType());
+ }
+
+ @Test
+ public void testDigestReport() throws InterruptedException {
+ this.spanEventDiskReporter.digestReport(this.sofaTracerSpan);
+ assertTrue(this.spanEventDiskReporter.getIsEventFileInited().get());
+ }
+
+ @Test
+ public void testGetDigestLogType() {
+ assertEquals(this.eventLogType, this.spanEventDiskReporter.getEventLogType());
+ }
+
+ @Test
+ public void testGetDigestRollingPolicy() {
+ String rollingPolicy = this.spanEventDiskReporter.getEventRollingPolicy();
+ assertEquals(expectRollingPolicy, rollingPolicy);
+ }
+
+ @Test
+ public void testGetDigestLogReserveConfig() {
+ String logReserveConfig = this.spanEventDiskReporter.getEventLogReserveConfig();
+ assertEquals(expectLogReserveConfig, logReserveConfig);
+ }
+
+ @Test
+ public void testGetContextEncoder() {
+ assertEquals(clientSpanEventEncoder, this.spanEventDiskReporter.getContextEncoder());
+ String logNameKey = this.spanEventDiskReporter.getLogNameKey();
+ assertTrue(StringUtils.isBlank(logNameKey));
+ }
+
+ @Test
+ public void testFixInitDigestFile() throws Exception {
+ //should be only one item log
+ SelfLog.warn("SelfLog init success!!!");
+ int nThreads = 30;
+ ExecutorService executor = new ThreadPoolExecutor(nThreads, nThreads, 0L,
+ TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
+ CountDownLatch countDownLatch = new CountDownLatch(nThreads);
+ for (int i = 0; i < nThreads; i++) {
+ Runnable worker = new WorkerInitThread(this.spanEventDiskReporter, "" + i,
+ countDownLatch);
+ executor.execute(worker);
+ }
+ //noinspection ResultOfMethodCallIgnored
+ countDownLatch.await(3, TimeUnit.SECONDS);
+ // When there is no control for concurrent initialization, report span will get an error;
+ // when the repair method is initialized,other threads need to wait for initialization to complete.
+ List contents = FileUtils.readLines(tracerSelfLog());
+ assertEquals("Actual concurrent init file size = " + contents.size(), 1, contents.size());
+ }
+
+ static class WorkerInitThread implements Runnable {
+ private final SpanEventDiskReporter reporter;
+ private final String command;
+ private final CountDownLatch countDownLatch;
+
+ public WorkerInitThread(SpanEventDiskReporter reporter, String s,
+ CountDownLatch countDownLatch) {
+ this.command = s;
+ this.reporter = reporter;
+ this.countDownLatch = countDownLatch;
+ }
+
+ @Override
+ public void run() {
+ processCommand();
+ countDownLatch.countDown();
+ }
+
+ private void processCommand() {
+ SofaTracerSpan span = new SofaTracerSpan(mock(SofaTracer.class),
+ System.currentTimeMillis(), "open", SofaTracerSpanContext.rootStart(), null);
+ span.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
+ this.reporter.digestReport(span);
+ }
+
+ @Override
+ public String toString() {
+ return this.command;
+ }
+ }
+}
\ No newline at end of file
diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java
index 7d67bf03d..3339a28b1 100644
--- a/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java
+++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java
@@ -22,8 +22,10 @@
import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext;
import com.alipay.common.tracer.core.generator.TraceIdGenerator;
import com.alipay.common.tracer.core.reporter.digest.DiskReporterImpl;
+import com.alipay.common.tracer.core.reporter.digest.event.SpanEventDiskReporter;
import com.alipay.common.tracer.core.reporter.facade.Reporter;
import com.alipay.common.tracer.core.tracertest.encoder.ClientSpanEncoder;
+import com.alipay.common.tracer.core.tracertest.encoder.ClientSpanEventEncoder;
import com.alipay.common.tracer.core.tracertest.encoder.ServerSpanEncoder;
import com.alipay.common.tracer.core.utils.StringUtils;
import com.google.common.collect.Lists;
@@ -38,12 +40,15 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
/**
* SofaTracerSpan Tester.
@@ -54,9 +59,13 @@
*/
public class SofaTracerSpanTest extends AbstractTestBase {
- private final String clientLogType = "client-log-test.log";
+ private final String clientLogType = "client-log-test.log";
- private final String serverLogType = "server-log-test.log";
+ private final String clientEventType = "client-event-log-test.log";
+
+ private final String serverLogType = "server-log-test.log";
+
+ private final String serverEventType = "server-event-log-test.log";
private SofaTracer sofaTracer;
@@ -68,10 +77,16 @@ public void setup() {
Reporter serverReporter = new DiskReporterImpl(serverLogType, new ServerSpanEncoder());
+ Reporter clientEventReporter = new SpanEventDiskReporter(clientEventType, "", "",
+ new ClientSpanEventEncoder(), null);
+
+ Reporter serverEventReporter = new SpanEventDiskReporter(serverEventType, "", "",
+ new ClientSpanEventEncoder(), null);
String tracerType = "SofaTracerSpanTest";
sofaTracer = new SofaTracer.Builder(tracerType)
.withTag("tracer", "SofaTraceContextHolderTest").withClientReporter(clientReporter)
- .withServerReporter(serverReporter).build();
+ .withServerReporter(serverReporter).withClientEventReporter(clientEventReporter)
+ .withServerEventReporter(serverEventReporter).build();
sofaTracerSpan = (SofaTracerSpan) this.sofaTracer.buildSpan("SofaTracerSpanTest").start();
}
@@ -216,6 +231,17 @@ public void testFinish() {
111 < span.getDurationMicroseconds() && span.getDurationMicroseconds() < endTime);
}
+ @Test
+ public void testEvent() {
+ SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testWithTimestamp")
+ .withStartTimestamp(111).start();
+ SpanEventData spanEventData = new SpanEventData();
+ spanEventData.setTimestamp(System.currentTimeMillis());
+ spanEventData.getEventTagWithStr().put("tag.key", "value");
+ span.addEvent(spanEventData);
+ span.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
+ }
+
/**
* Method: close()
*/
diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java
index 4864f4f60..611f612e6 100644
--- a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java
+++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java
@@ -22,11 +22,14 @@
import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration;
import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext;
import com.alipay.common.tracer.core.reporter.digest.DiskReporterImpl;
+import com.alipay.common.tracer.core.reporter.digest.event.SpanEventDiskReporter;
import com.alipay.common.tracer.core.reporter.facade.Reporter;
import com.alipay.common.tracer.core.samplers.Sampler;
import com.alipay.common.tracer.core.samplers.SofaTracerPercentageBasedSampler;
import com.alipay.common.tracer.core.span.SofaTracerSpan;
+import com.alipay.common.tracer.core.span.SpanEventData;
import com.alipay.common.tracer.core.tracertest.encoder.ClientSpanEncoder;
+import com.alipay.common.tracer.core.tracertest.encoder.ClientSpanEventEncoder;
import com.alipay.common.tracer.core.tracertest.encoder.ServerSpanEncoder;
import com.alipay.common.tracer.core.tracertest.type.TracerTestLogEnum;
import com.alipay.common.tracer.core.utils.StringUtils;
@@ -74,11 +77,22 @@ public void beforeInstance() {
DiskReporterImpl clientReporter = new DiskReporterImpl(
TracerTestLogEnum.RPC_CLIENT.getDefaultLogName(), new ClientSpanEncoder());
+ SpanEventDiskReporter clientEventReporter = new SpanEventDiskReporter(
+ TracerTestLogEnum.RPC_CLIENT_EVENT.getDefaultLogName(), "", "",
+ new ClientSpanEventEncoder(), null);
+
//server
DiskReporterImpl serverReporter = new DiskReporterImpl(
TracerTestLogEnum.RPC_SERVER.getDefaultLogName(), new ServerSpanEncoder());
+
+ SpanEventDiskReporter serverEventReporter = new SpanEventDiskReporter(
+ TracerTestLogEnum.RPC_SERVER.getDefaultLogName(), "", "", new ClientSpanEventEncoder(),
+ null);
+
sofaTracer = new SofaTracer.Builder(tracerType).withTag("tracer", "tracerTest")
.withClientReporter(clientReporter).withServerReporter(serverReporter)
+ .withClientEventReporter(clientEventReporter)
+ .withServerEventReporter(serverEventReporter)
.withTag(tracerGlobalTagKey, tracerGlobalTagValue).build();
}
@@ -132,6 +146,16 @@ public void testReportSpan() {
SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testInjectSpan")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
//Report Do not prohibit writing
+ SpanEventData spanEventData = new SpanEventData();
+ spanEventData.setTimestamp(System.currentTimeMillis());
+ spanEventData.getEventTagWithStr().put("kkk11", "vvv22");
+ span.addEvent(spanEventData);
+
+ SpanEventData spanEventData2 = new SpanEventData();
+ spanEventData2.setTimestamp(System.currentTimeMillis());
+ spanEventData2.getEventTagWithStr().put("kkk222", "vvv33");
+ span.addEvent(spanEventData2);
+
span.finish();
TestUtil.periodicallyAssert(() -> {
@@ -159,6 +183,10 @@ public void testIsDisableAllDigestLog() {
SofaTracerConfiguration.DISABLE_MIDDLEWARE_DIGEST_LOG_KEY, "true");
SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testInjectSpan")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
+ SpanEventData spanEventData = new SpanEventData();
+ spanEventData.getEventTagWithNumber().put("tag.num", 999);
+ spanEventData.getEventTagWithBool().put("tag.key", true);
+ span.addEvent(spanEventData);
//report
span.finish();
assertFalse(customFileLog(TracerTestLogEnum.RPC_CLIENT.getDefaultLogName()).exists());
@@ -178,6 +206,9 @@ public void testIsDisableClientDigestLog() {
//create
SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testInjectSpan")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
+ SpanEventData spanEventData = new SpanEventData();
+ spanEventData.getEventTagWithStr().put("kkk", "vvv");
+ span.addEvent(spanEventData);
//report
span.finish();
assertFalse(customFileLog(clientLogTypeName).exists());
@@ -195,6 +226,9 @@ public void testClose() {
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
this.sofaTracer.close();
//report
+ SpanEventData spanEventData = new SpanEventData();
+ spanEventData.getEventTagWithStr().put("kkk", "vvv");
+ span.addEvent(spanEventData);
span.finish();
String clientLogTypeName = TracerTestLogEnum.RPC_CLIENT.getDefaultLogName();
assertFalse(customFileLog(clientLogTypeName).exists());
diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/encoder/ClientSpanEventEncoder.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/encoder/ClientSpanEventEncoder.java
new file mode 100644
index 000000000..7e7369fb5
--- /dev/null
+++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/encoder/ClientSpanEventEncoder.java
@@ -0,0 +1,74 @@
+/*
+ * 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 com.alipay.common.tracer.core.tracertest.encoder;
+
+import com.alipay.common.tracer.core.appender.builder.XStringBuilder;
+import com.alipay.common.tracer.core.appender.encoder.SpanEncoder;
+import com.alipay.common.tracer.core.appender.self.Timestamp;
+import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext;
+import com.alipay.common.tracer.core.span.SofaTracerSpan;
+import com.alipay.common.tracer.core.utils.StringUtils;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * The type Client span event encoder.
+ *
+ * @author yuqian
+ * @version : ClientSpanEventEncoder.java, v 0.1 2025-03-10 17:02 yuqian Exp $$
+ */
+public class ClientSpanEventEncoder implements SpanEncoder {
+
+ private XStringBuilder xsb = new XStringBuilder();
+
+ @Override
+ public String encode(SofaTracerSpan span) throws IOException {
+ SofaTracerSpanContext spanContext = span.getSofaTracerSpanContext();
+ xsb.reset();
+ //
+ xsb.append(Timestamp.format(span.getEventData().getTimestamp()));
+ //traceId
+ xsb.append(spanContext.getTraceId());
+ //spanId
+ xsb.append(spanContext.getSpanId());
+ //tags string
+ xsb.append(StringUtils.mapToString(span.getEventData().getEventTagWithStr()));
+ //tags bool
+ Map tagsBool = span.getEventData().getEventTagWithBool();
+ StringBuilder tagsBoolBuild = new StringBuilder();
+ for (Map.Entry entry : tagsBool.entrySet()) {
+ tagsBoolBuild.append(entry.getKey()).append(StringUtils.EQUAL)
+ .append(entry.getValue().toString()).append(StringUtils.AND);
+ }
+ xsb.append(tagsBoolBuild.toString());
+
+ //tags number
+ Map tagsNum = span.getEventData().getEventTagWithNumber();
+ StringBuilder tagsNumBuild = new StringBuilder();
+ for (Map.Entry entry : tagsNum.entrySet()) {
+ tagsNumBuild.append(entry.getKey()).append(StringUtils.EQUAL)
+ .append(entry.getValue().toString()).append(StringUtils.AND);
+ }
+ xsb.append(tagsNumBuild.toString());
+
+ //baggage
+ Map baggage = spanContext.getBizBaggage();
+ xsb.appendEnd(StringUtils.mapToString(baggage));
+ return xsb.toString();
+ }
+}
\ No newline at end of file
diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/type/TracerTestLogEnum.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/type/TracerTestLogEnum.java
index 7a9838d12..b4ef27373 100644
--- a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/type/TracerTestLogEnum.java
+++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/type/TracerTestLogEnum.java
@@ -27,7 +27,10 @@ public enum TracerTestLogEnum {
RPC_CLIENT("rpc_client_log_name", "rpc_client.log", "rpc_client_rolling"), RPC_SERVER(
"rpc_server_log_name",
"rpc_server.log",
- "rpc_server_rolling");
+ "rpc_server_rolling"), RPC_CLIENT_EVENT(
+ "rpc_client_event_log_name",
+ "rpc_client_event.log",
+ "rpc_client_event_rolling"), ;
private String logReverseKey;
diff --git a/tracer-extensions/pom.xml b/tracer-extensions/pom.xml
index 56bad974f..faabb89f0 100644
--- a/tracer-extensions/pom.xml
+++ b/tracer-extensions/pom.xml
@@ -4,7 +4,7 @@
tracer-all-parent
com.alipay.sofa
- 3.1.9
+ 3.1.10
tracer-extensions
diff --git a/tracer-sofa-boot-starter/pom.xml b/tracer-sofa-boot-starter/pom.xml
index 846e6c098..cccb14aaa 100644
--- a/tracer-sofa-boot-starter/pom.xml
+++ b/tracer-sofa-boot-starter/pom.xml
@@ -5,7 +5,7 @@
tracer-all-parent
com.alipay.sofa
- 3.1.9
+ 3.1.10
../pom.xml
diff --git a/tracer-test/core-test/pom.xml b/tracer-test/core-test/pom.xml
index 8b3c5c630..556b42a28 100644
--- a/tracer-test/core-test/pom.xml
+++ b/tracer-test/core-test/pom.xml
@@ -4,7 +4,7 @@
tracer-all-parent
com.alipay.sofa
- 3.1.9
+ 3.1.10
../../pom.xml
diff --git a/tracer-test/log4j-test/pom.xml b/tracer-test/log4j-test/pom.xml
index 5b4f57359..6f6437246 100644
--- a/tracer-test/log4j-test/pom.xml
+++ b/tracer-test/log4j-test/pom.xml
@@ -4,7 +4,7 @@
tracer-all-parent
com.alipay.sofa
- 3.1.9
+ 3.1.10
../../pom.xml
diff --git a/tracer-test/log4j2-test/pom.xml b/tracer-test/log4j2-test/pom.xml
index 7d812dd8a..000731896 100644
--- a/tracer-test/log4j2-test/pom.xml
+++ b/tracer-test/log4j2-test/pom.xml
@@ -4,7 +4,7 @@
tracer-all-parent
com.alipay.sofa
- 3.1.9
+ 3.1.10
../../pom.xml
diff --git a/tracer-test/logback-test/pom.xml b/tracer-test/logback-test/pom.xml
index 021395303..b3366aa25 100644
--- a/tracer-test/logback-test/pom.xml
+++ b/tracer-test/logback-test/pom.xml
@@ -4,7 +4,7 @@
tracer-all-parent
com.alipay.sofa
- 3.1.9
+ 3.1.10
../../pom.xml