Skip to content
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

Curl headers are overwritten in v0.29 when using curl_copy_handle function #502

Closed
pdemers-seedbox opened this issue Jul 22, 2019 · 3 comments
Labels
🐛 bug Something isn't working 🎉 new-integration A new integration

Comments

@pdemers-seedbox
Copy link

pdemers-seedbox commented Jul 22, 2019

Hi,

we have a similar issue with Curl header being lost (#365).
The issue come from using "curl_copy_handle".
If i'm not mistaken, the problem come from the injectDistributedTracingHeaders in (src/DDTrace/Integrations/Curl/CurlIntegration.php). When we call exec on the new handle, the method try to retrieve the headers that were set on it (ArrayKVStore::getForResource($ch, Format::CURL_HTTP_HEADERS, []);) but since those were copied by PHP between the 2 handle and not set on the new handle, it returns nothing.

Here's a quick example that trigger the issue for me.
By Commenting the 'require' of the dd_init.php script you see the header changing in the 2nd curl call.

Currently, we deactivated Distributed Tracing and it 'fixes' the issue as the header are not overwritten then.

<?php

require '/opt/datadog-php/dd-trace-sources/bridge/dd_init.php';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

$result = curl_exec($ch);

$info = curl_getinfo($ch);
var_dump($info['request_header']);

// Before closing copy handle 
$ch2 = curl_copy_handle($ch);
curl_close($ch);

//Do a request on the new handle without setting the headers
curl_setopt($ch2, CURLINFO_HEADER_OUT, true);
$result = curl_exec($ch2);
$info = curl_getinfo($ch2);
var_dump($info['request_header']);
curl_close($ch2);

@SammyK
Copy link
Contributor

SammyK commented Jul 31, 2019

Thank you for the detailed report @pdemers-seedbox!

We are able to reproduce this issue on our end and are working on a fix. We will update this thread as soon as we are able to provide a patch. Until that time, you can temporarily disable the cURL integration by setting the following environment variable: DD_INTEGRATIONS_DISABLED=curl.

@SammyK SammyK added 🎉 new-integration A new integration 🐛 bug Something isn't working labels Jul 31, 2019
@labbati labbati changed the title Curl headers are overwritten in v0.29 Curl headers are overwritten in v0.29 when using curl_copy_handle function Aug 1, 2019
morrisonlevi added a commit that referenced this issue Sep 4, 2019
Fix #502: Curl headers are overwritten when using `curl_copy_handle` function
@morrisonlevi
Copy link
Collaborator

Imerged a fix for this into master, which should go into 0.31.0.

@morrisonlevi
Copy link
Collaborator

Version 0.31. has been released -- can you verify that this release fixes this issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🎉 new-integration A new integration
Projects
None yet
Development

No branches or pull requests

3 participants