Skip to content

Commit 0af26e2

Browse files
authored
fix: arex trace context clear (#163)
fix: override chileValue exclude arex-record-id
1 parent b5f6c22 commit 0af26e2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/ctx/ArexThreadLocal.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public final void remove() {
4040
super.remove();
4141
}
4242

43+
@Override
44+
protected T childValue(T parentValue) {
45+
// no need to copy arex-record-id, TraceTransmitter will capture and replay
46+
if (parentValue instanceof String && ((String) parentValue).startsWith("AREX-")) {
47+
return null;
48+
}
49+
return super.childValue(parentValue);
50+
}
51+
4352
public void superRemove() {
4453
super.remove();
4554
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.arex.agent.bootstrap.ctx;
2+
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.CsvSource;
5+
6+
import static org.junit.jupiter.api.Assertions.*;
7+
8+
class ArexThreadLocalTest {
9+
10+
static final ArexThreadLocal<String> TRACE_CONTEXT = new ArexThreadLocal<>();
11+
12+
@ParameterizedTest
13+
@CsvSource({
14+
"AREX-mock, null",
15+
"mock, mock"
16+
})
17+
void childValue(String request, String expect) {
18+
String result = String.valueOf(TRACE_CONTEXT.childValue(request));
19+
System.out.println(result);
20+
assertEquals(expect, result);
21+
}
22+
}

0 commit comments

Comments
 (0)