@@ -221,6 +221,14 @@ void parse_datadog_tracestate(ExtractedData& result, StringView datadog_value) {
221221 (*result.sampling_priority > 0 ) == (priority > 0 )) {
222222 result.sampling_priority = priority;
223223 }
224+ } else if (key == " p" ) {
225+ if (value.size () != 16 ) {
226+ // chaff!
227+ pair_begin = pair_end == end ? end : pair_end + 1 ;
228+ continue ;
229+ }
230+
231+ result.datadog_w3c_parent_id = std::string (value);
224232 } else if (starts_with (key, " t." )) {
225233 // The part of the key that follows "t." is the name of a trace tag,
226234 // except without the "_dd.p." prefix.
@@ -300,6 +308,7 @@ Expected<ExtractedData> extract_w3c(
300308 return result;
301309 }
302310
311+ result.datadog_w3c_parent_id = " 0000000000000000" ;
303312 extract_tracestate (result, headers);
304313
305314 return result;
@@ -326,11 +335,14 @@ std::string encode_traceparent(TraceID trace_id, std::uint64_t span_id,
326335}
327336
328337std::string encode_datadog_tracestate (
329- int sampling_priority, const Optional<std::string>& origin,
338+ uint64_t span_id, int sampling_priority,
339+ const Optional<std::string>& origin,
330340 const std::vector<std::pair<std::string, std::string>>& trace_tags,
331341 const Optional<std::string>& additional_datadog_w3c_tracestate) {
332342 std::string result = " dd=s:" ;
333343 result += std::to_string (sampling_priority);
344+ result += " ;p:" ;
345+ result += hex_padded (span_id);
334346
335347 if (origin) {
336348 result += " ;o:" ;
@@ -382,12 +394,14 @@ std::string encode_datadog_tracestate(
382394}
383395
384396std::string encode_tracestate (
385- int sampling_priority, const Optional<std::string>& origin,
397+ uint64_t span_id, int sampling_priority,
398+ const Optional<std::string>& origin,
386399 const std::vector<std::pair<std::string, std::string>>& trace_tags,
387400 const Optional<std::string>& additional_datadog_w3c_tracestate,
388401 const Optional<std::string>& additional_w3c_tracestate) {
389- std::string result = encode_datadog_tracestate (
390- sampling_priority, origin, trace_tags, additional_datadog_w3c_tracestate);
402+ std::string result =
403+ encode_datadog_tracestate (span_id, sampling_priority, origin, trace_tags,
404+ additional_datadog_w3c_tracestate);
391405
392406 if (additional_w3c_tracestate) {
393407 result += ' ,' ;
0 commit comments