Repository navigation
Fix cURL instrumentation handling of null CURLOPT_CUSTOMREQUEST - #1520
Merged
Merged
Conversation
🤖 GitHub commentsJust comment with:
|
There was a problem hiding this comment.
🟡 Changes recommended
The custom HTTP method override survives curl_reset(), causing the agent to record DELETE when cURL sends POST on a reused handle; tracked options need resetting and regression coverage.
1 open issue
What changed in this PR
This PR addresses #742 by allowing the PHP agent’s cURL instrumentation to accept CURLOPT_CUSTOMREQUEST = null and track the underlying HTTP method after the override is cleared.
Changes:
- Add nullable-string validation while retaining validation for unexpected types.
- Track custom method overrides separately and use the effective method in span names and HTTP context.
- Add regression tests for both option-setting APIs, method precedence, null resets, and copied handles.
| File | Description |
|---|---|
| tests/ElasticApmTests/UnitTests/CurlAutoInstrumentationUnitTest.php | Adds method-tracking and validation regression tests. |
| agent/php/ElasticApm/Impl/AutoInstrument/Util/AutoInstrumentationUtil.php | Adds a nullable-string validation helper. |
| agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleTracker.php | Separates custom overrides from underlying methods and preserves them when copying handles. |
Review effort: Balanced
intuibase
approved these changes
Nov 5, 2026
Contributor
|
@rajmundtoth0 Thank you for contributing this fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #742
This PR fixes an issue in the PHP agent's cURL auto-instrumentation where setting
CURLOPT_CUSTOMREQUESTtonullproduces an unexpected type validation error.The issue was encountered in production while downloading files through Laravel's filesystem abstraction, using the AWS SDK and Guzzle.
Problem
CurlHandleTracker::processSetOpt()currently expectsCURLOPT_CUSTOMREQUESTto contain a string:However, passing
nullis valid cURL behavior and clears the custom HTTP method override.As a result, the agent incorrectly logs:
This creates unnecessary error logs during otherwise valid HTTP operations and can leave the agent with incorrect HTTP method tracking.
Changes
nullas a valid value forCURLOPT_CUSTOMREQUEST.Testing
Regression tests cover:
CURLOPT_CUSTOMREQUESTtonull.curl_setopt()andcurl_setopt_array().Motivation
APM instrumentation should observe valid application behavior without introducing misleading errors.
This is a small compatibility fix that improves the reliability and accuracy of cURL instrumentation without requiring changes to applications or their HTTP clients.