Skip to content

[BUG] \DDTrace\trace_method not tracing nested/recursive method invocations #1105

Description

@numyx

Bug description

Hello, I noticed that \DDTrace\trace_method (and trace_function) is not properly tracing nested or recursive method invocations, only the initial invocation is traced, but all nested invocations are not.

I wrote some mini code sample that highlights the issue:

function test(int $x)
{
    if ($x > 0) {
        test($x - 1);
    }
}

\DDTrace\trace_function(
    'test',
    function (\DDTrace\SpanData $span, $args) {
        echo "Traced\n";
    }
);

test(3); // Expected 3 span and 3 "Traced" outputs, got only a single one.

While the pure recursive usage is probably an edge case, we noticed this issue when working with Symfony EventDispatcher where we are using event listeners to dispatch other events which results in nested calls of EventDispatcher::dispatch which are not getting traced by the built in Symfony integration.

PHP version

PHP 7.4.12 (cli) (built: Nov  5 2020 20:24:10) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.12, Copyright (c), by Zend Technologies
    with ddtrace v0.50.0, Copyright Datadog, by Datadog

Installed extensions

Click to expand!
[PHP Modules]
amqp
apcu
bcmath
Core
ctype
curl
date
ddtrace
dom
fileinfo
filter
ftp
gd
hash
iconv
igbinary
intl
json
libxml
mbstring
mysqlnd
newrelic
openssl
pcntl
pcov
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache
ddtrace

OS info

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster

Diagnostics and configuration

Output of phpinfo() (ddtrace >= 0.47.0)

Datadog PHP tracer extension
For help, check out the documentation at https://docs.datadoghq.com/tracing/languages/php/
(c) Datadog 2020

Datadog tracing support => enabled
Version => 0.50.0
DATADOG TRACER CONFIGURATION => {"date":"2020-11-24T08:29:24Z","os_name":"Linux web-01 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) x86_64","os_version":"4.9.0-13-amd64","version":"0.50.0","lang":"php","lang_version":"7.4.2","env":"stg","enabled":true,"service":"fxt.monolith.api.booking","enabled_cli":true,"agent_url":"http://localhost:8126","debug":false,"analytics_enabled":true,"sample_rate":1.000000,"sampling_rules":null,"tags":null,"service_mapping":"pdo:fxt.monolith.db","distributed_tracing_enabled":true,"priority_sampling_enabled":true,"dd_version":"17ffd7dc5e","architecture":"x86_64","sapi":"cli","ddtrace.request_init_hook":"/opt/datadog-php/dd-trace-sources/bridge/dd_wrap_autoloader.php","open_basedir_configured":false,"uri_fragment_regex":null,"uri_mapping_incoming":null,"uri_mapping_outgoing":null,"auto_flush_enabled":false,"generate_root_span":true,"http_client_split_by_domain":true,"measure_compile_time":true,"report_hostname_on_root_span":false,"traced_internal_functions":null,"auto_prepend_file_configured":false,"integrations_disabled":null,"enabled_from_env":true,"opcache.file_cache":null}

                               Diagnostics                               
Diagnostic checks => passed

Directive => Local Value => Master Value
ddtrace.disable => Off => Off
ddtrace.request_init_hook => /opt/datadog-php/dd-trace-sources/bridge/dd_wrap_autoloader.php => /opt/datadog-php/dd-trace-sources/bridge/dd_wrap_autoloader.php

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions