Skip to content

Fix cURL instrumentation handling of null CURLOPT_CUSTOMREQUEST - #1520

Merged
intuibase merged 2 commits into
elastic:mainfrom
rajmundtoth0:null-curl
Nov 5, 2026
Merged

intuibase merged 2 commits into
elastic:mainfrom
rajmundtoth0:null-curl

Conversation

@rajmundtoth0

Copy link
Copy Markdown
Contributor

Summary

Fixes #742

This PR fixes an issue in the PHP agent's cURL auto-instrumentation where setting CURLOPT_CUSTOMREQUEST to null produces 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 expects CURLOPT_CUSTOMREQUEST to contain a string:

if (!$this->util->verifyIsString($optionValue)) {
    return;
}

However, passing null is valid cURL behavior and clears the custom HTTP method override.

As a result, the agent incorrectly logs:

[ERROR] [Auto-Instrumentation]
Actual type does not match the expected type
{"expected type":"string","actual type":"NULL"}

This creates unnecessary error logs during otherwise valid HTTP operations and can leave the agent with incorrect HTTP method tracking.

Changes

  • Allow null as a valid value for CURLOPT_CUSTOMREQUEST.
  • Handle resetting the custom HTTP method while preserving correct method tracking.
  • Keep existing validation for unexpected types.
  • Add regression coverage for setting and clearing custom HTTP methods.

Testing

Regression tests cover:

  • Setting a custom HTTP method.
  • Resetting CURLOPT_CUSTOMREQUEST to null.
  • Correct HTTP method tracking after resetting the override.
  • Both curl_setopt() and curl_setopt_array().
  • Existing HTTP method handling to prevent regressions.

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.

@github-actions

Copy link
Copy Markdown

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the changes supporting nullable cURL custom methods and tracking method overrides.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@intuibase
intuibase merged commit b822ba0 into elastic:main Nov 5, 2026
234 checks passed
@intuibase

Copy link
Copy Markdown
Contributor

@rajmundtoth0 Thank you for contributing this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InternalFailureException: Unexpected value type

3 participants