dd-trace-php icon indicating copy to clipboard operation
dd-trace-php copied to clipboard

[Bug]: duplicate header values through `psr/http-message` & `psr/http-client` with curl

Open mrtus opened this issue 8 months ago • 2 comments

Bug report

When a request is comes in from RUM, the headers x-datadog-<x> are added already on the request. When such a request is reused & forwarded to a next service, those headers will still be there.

However, when the request is used and converted to a curl call to the next service, the datadog context values are added again, creating a comma separated header value with duplicate values.

Example: Image

The next service then tries to parse these headers but fails and creates a new trace root.

Given that the tracing should mostly require no code changes to codebases, I would assume we shouldn't have to strip these headers ourselves to ensure a smooth tracing.

Would it be a fix to replace these header values instead of appending them?

Thanks!

PHP version

8.3

Tracer or profiler version

1.5.1

Installed extensions

No response

Output of phpinfo()

No response

Upgrading from

No response

mrtus avatar Mar 19 '25 20:03 mrtus

What we effectively do is calling curl_setopt(CURLOPT_HTTPHEADER, array_merge($existing_headers, $injecting_headers)); right before the actual curl_(multi_)exec; so yes, it would be possible to walk through the existing passed headers and strip those away.

We will fix this for the next minor version.

Thanks for the report @mrtus!

bwoebi avatar Mar 19 '25 21:03 bwoebi

Awesome, thanks @bwoebi !

mrtus avatar Mar 20 '25 07:03 mrtus