-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove baggage propagation from xray propagator #1178
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,6 @@ | |
|
||
package io.opentelemetry.contrib.awsxray.propagator; | ||
|
||
import io.opentelemetry.api.baggage.Baggage; | ||
import io.opentelemetry.api.baggage.BaggageBuilder; | ||
import io.opentelemetry.api.baggage.BaggageEntry; | ||
import io.opentelemetry.api.internal.StringUtils; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.SpanContext; | ||
|
@@ -21,7 +18,6 @@ | |
import io.opentelemetry.context.propagation.TextMapSetter; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.BiConsumer; | ||
import java.util.logging.Logger; | ||
import javax.annotation.Nullable; | ||
|
||
|
@@ -112,49 +108,20 @@ public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> se | |
char samplingFlag = spanContext.isSampled() ? IS_SAMPLED : NOT_SAMPLED; | ||
// TODO: Add OT trace state to the X-Ray trace header | ||
|
||
StringBuilder traceHeader = new StringBuilder(); | ||
traceHeader | ||
.append(TRACE_ID_KEY) | ||
.append(KV_DELIMITER) | ||
.append(xrayTraceId) | ||
.append(TRACE_HEADER_DELIMITER) | ||
.append(PARENT_ID_KEY) | ||
.append(KV_DELIMITER) | ||
.append(parentId) | ||
.append(TRACE_HEADER_DELIMITER) | ||
.append(SAMPLED_FLAG_KEY) | ||
.append(KV_DELIMITER) | ||
.append(samplingFlag); | ||
|
||
Baggage baggage = Baggage.fromContext(context); | ||
// Truncate baggage to 256 chars per X-Ray spec. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about this comment:
My read of this is that including up to 256 baggage bytes is a bug that should be fixed, instead of removing baggage encoding altogether. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. #563 is StepFunction receives a xray header over 256. AWS Lambda is working on a new encoding algorithm to reducing the xray header to be less than 256, then we can fix the bug by truncating xray header to be 256, not truncating baggage to 256. |
||
baggage.forEach( | ||
new BiConsumer<String, BaggageEntry>() { | ||
|
||
private int baggageWrittenBytes; | ||
|
||
@Override | ||
public void accept(String key, BaggageEntry entry) { | ||
if (key.equals(TRACE_ID_KEY) | ||
|| key.equals(PARENT_ID_KEY) | ||
|| key.equals(SAMPLED_FLAG_KEY)) { | ||
return; | ||
} | ||
// Size is key/value pair, excludes delimiter. | ||
int size = key.length() + entry.getValue().length() + 1; | ||
if (baggageWrittenBytes + size > 256) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It looks like the code is only trying to include baggage entires if the entire entry can be included without exceeding 256 bytes. When you talk about corrupting entries, are you referring to some entries being present while others not? Can you help me understand why this is problematic? |
||
return; | ||
} | ||
traceHeader | ||
.append(TRACE_HEADER_DELIMITER) | ||
.append(key) | ||
.append(KV_DELIMITER) | ||
.append(entry.getValue()); | ||
baggageWrittenBytes += size; | ||
} | ||
}); | ||
|
||
setter.set(carrier, TRACE_HEADER_KEY, traceHeader.toString()); | ||
String traceHeader = | ||
TRACE_ID_KEY | ||
+ KV_DELIMITER | ||
+ xrayTraceId | ||
+ TRACE_HEADER_DELIMITER | ||
+ PARENT_ID_KEY | ||
+ KV_DELIMITER | ||
+ parentId | ||
+ TRACE_HEADER_DELIMITER | ||
+ SAMPLED_FLAG_KEY | ||
+ KV_DELIMITER | ||
+ samplingFlag; | ||
|
||
setter.set(carrier, TRACE_HEADER_KEY, traceHeader); | ||
} | ||
|
||
@Override | ||
|
@@ -180,9 +147,6 @@ private static <C> Context getContextFromHeader( | |
String spanId = SpanId.getInvalid(); | ||
Boolean isSampled = false; | ||
|
||
BaggageBuilder baggage = null; | ||
int baggageReadBytes = 0; | ||
|
||
int pos = 0; | ||
while (pos < traceHeader.length()) { | ||
int delimiterIndex = traceHeader.indexOf(TRACE_HEADER_DELIMITER, pos); | ||
|
@@ -210,12 +174,6 @@ private static <C> Context getContextFromHeader( | |
spanId = parseSpanId(value); | ||
} else if (trimmedPart.startsWith(SAMPLED_FLAG_KEY)) { | ||
isSampled = parseTraceFlag(value); | ||
} else if (baggageReadBytes + trimmedPart.length() <= 256) { | ||
if (baggage == null) { | ||
baggage = Baggage.builder(); | ||
} | ||
baggage.put(trimmedPart.substring(0, equalsIndex), value); | ||
baggageReadBytes += trimmedPart.length(); | ||
} | ||
} | ||
if (isSampled == null) { | ||
|
@@ -241,9 +199,6 @@ private static <C> Context getContextFromHeader( | |
if (spanContext.isValid()) { | ||
context = context.with(Span.wrap(spanContext)); | ||
} | ||
if (baggage != null) { | ||
context = context.with(baggage.build()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use a new key "XRAY_HEADER_ADDITIONAL_FIELDS"
FYI #1178 (comment) |
||
} | ||
return context; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't seem to find a spec document for the xray spec format. If there is a document, and it does talk about including baggage like this, we should likely follow the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of a formal specification as well, but I usually follow this reference: https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html#Tracing-header:~:text=sampling%20rules.-,Tracing%20header,-All%20requests%20are
It seems that there is no equivalent concept to baggage, at least in the reference above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reference to baggage here, so maybe its right to delete it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to the comment, using key "XRAY_HEADER_ADDITIONAL_FIELDS"