Skip to content
This repository was archived by the owner on Jul 1, 2022. It is now read-only.

Commit 1d033d4

Browse files
authored
Do not encode span context in HTTP_HEADERS format (#721)
We know that string representation of a span context is safe to use in HTTP header. Thus, there is no need to encode it. JS & Go clients already avoid that unnecesserary encoding. This change is backward compatible because all clients unencode span context even if they do not encode it. More pragmatically, a client impacted by this change would already be incompatible with JS & Go clients. Signed-off-by: Clément MATHIEU <clement@unportant.info>
1 parent 016e0c3 commit 1d033d4

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

jaeger-core/src/main/java/io/jaegertracing/internal/propagation/TextMapCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static String contextAsString(JaegerSpanContext context) {
126126

127127
@Override
128128
public void inject(JaegerSpanContext spanContext, TextMap carrier) {
129-
carrier.put(contextKey, encodedValue(contextAsString(spanContext)));
129+
carrier.put(contextKey, contextAsString(spanContext));
130130
for (Map.Entry<String, String> entry : spanContext.baggageItems()) {
131131
carrier.put(keys.prefixedKey(entry.getKey(), baggagePrefix), encodedValue(entry.getValue()));
132132
}

jaeger-core/src/test/java/io/jaegertracing/internal/propagation/TextMapCodecTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,45 @@ public void testAdhocBaggageWithoutTraceId() {
158158
assertEquals("v2", context.getBaggageItem("k2"));
159159
assertEquals(null, context.getBaggageItem("k3"));
160160
}
161+
162+
@Test
163+
public void testInjectDoNotEncodeSpanContext() {
164+
TextMapCodec codec = new TextMapCodec(true);
165+
Map<String, String> headers = new HashMap<String, String>();
166+
long traceIdLow = 42;
167+
long spanId = 1;
168+
long parentId = 0;
169+
codec.inject(new JaegerSpanContext(0L, traceIdLow, spanId, parentId, (byte)1), new TextMapAdapter(headers));
170+
171+
String traceId = headers.get("uber-trace-id");
172+
assertEquals("2a:1:0:1", traceId);
173+
}
174+
175+
@Test
176+
public void testExtractSupportNonEncodedSpanContext() {
177+
Map<String, String> headers = new HashMap<String, String>();
178+
headers.put("uber-trace-id", "2a:1:0:1");
179+
180+
TextMapCodec codec = new TextMapCodec(true);
181+
JaegerSpanContext context = codec.extract(new TextMapAdapter(headers));
182+
183+
assertEquals(42, context.getTraceIdLow());
184+
assertEquals(0L, context.getTraceIdHigh());
185+
assertEquals(1L, context.getSpanId());
186+
assertTrue(context.isSampled());
187+
}
188+
189+
@Test
190+
public void testExtractSupportEncodedSpanContext() {
191+
Map<String, String> headers = new HashMap<String, String>();
192+
headers.put("uber-trace-id", "2a%3A1%3A0%3A1");
193+
194+
TextMapCodec codec = new TextMapCodec(true);
195+
JaegerSpanContext context = codec.extract(new TextMapAdapter(headers));
196+
197+
assertEquals(42, context.getTraceIdLow());
198+
assertEquals(0L, context.getTraceIdHigh());
199+
assertEquals(1L, context.getSpanId());
200+
assertTrue(context.isSampled());
201+
}
161202
}

0 commit comments

Comments
 (0)