DataDog / dd-trace-php

Datadog PHP Clients
https://docs.datadoghq.com/tracing/setup/php
Other
490 stars 152 forks source link

[Bug]: Can't pass less args to an untyped function than originally passed (minus extra args) #2174

Closed matthewnessworthy closed 1 year ago

matthewnessworthy commented 1 year ago

Bug report

Can't pass less args to an untyped function than originally passed (minus extra args) in /opt/datadog-php/dd-trace-sources/bridge/_generated_integrations.php:2054

PHP version

8.1

Tracer or profiler version

0.90.0

Installed extensions

No response

Output of phpinfo()

No response

Upgrading from

0.89.1

PROFeNoM commented 1 year ago

Hi Matthew,

Thank you for providing the debug log. I see why you are getting this error message, and I'm currently trying to reproduce the issue. However, it led to nothing currently...

Can I ask you some questions for reproducibility purposes?

matthewnessworthy commented 1 year ago

Hi @PROFeNoM, We're running Laravel 9 & 10 (different apps, same error), with the built-in MonoLog error logging library.

Here are the only snippets in the app where we interact with DD directly

        if (
            ($rootScope = \DDTrace\GlobalTracer::get()->getRootScope())
            && ($rootSpan = $rootScope->getSpan())
        ) {
            $rootSpan->setTag('domain', (string) $domain);
        }
        if (
            ($rootScope = \DDTrace\GlobalTracer::get()->getRootScope())
            && ($rootSpan = $rootScope->getSpan())
        ) {
            $rootSpan->setMetric('php.mem.peak_usage_bytes', memory_get_peak_usage(false));
            $rootSpan->setMetric('php.mem.peak_real_usage_bytes', memory_get_peak_usage(true));
        }
        if (
            ($rootScope = GlobalTracer::get()->getRootScope())
            && ($rootSpan = $rootScope->getSpan())
        ) {
            $rootSpan->setTag('domain', (string) tenant('slug'));

            $rootSpan->setTag('http.referer', $request->header('HTTP_REFERER'));
            $rootSpan->setTag('http.request_id', $request->server('HTTP_X_REQUEST_ID'));
            $rootSpan->setTag('http.useragent', $request->userAgent());
        }
        try {
            if (function_exists('\DDTrace\current_context')) {
                // @see https://docs.datadoghq.com/logs/log_collection/php/?tab=phpmonolog#laravel
                $context = \DDTrace\current_context();
                $record['dd']['trace_id'] = $context['trace_id'];
                $record['dd']['span_id'] = $context['span_id'];
            }
        } catch (Throwable $e) {
            $record['dd']['context_error'] = $e->getMessage();
        }
PROFeNoM commented 1 year ago

Hey @matthewnessworthy!

It looks like @bwoebi may have found out about your issue. Would it be possible for you to try out the corresponding artifact and see if it solves the problem? Let us know if there's anything else we can do to assist you.

🔧 Just in case you are not familiar with using the artifact, you simply need to replace the link of the installer (datadog-setup.php) to be the one provided above (generated here).

jpasquers commented 1 year ago

Able to reproduce this on php 8.1 and dd-trace-php 0.90.0. Our usage is as simple as:

        dd_trace_method(
            CController::class,
            'getViewFile',
            function ($span, array $args, string $result, $exception) {
                $span->service = 'monolith-app';
                $span->name = 'getView.file';
                $span->resource = $result;
            },
        );

Full log:

NOTICE: PHP message: Can't pass less args to an untyped function than originally passed (minus extra args) in /opt/datadog/dd-library/0.90.0/dd-trace-sources/bridge/_generated_integrations.php:2054

@matthewnessworthy did @PROFeNoM 's suggestion work? Or did you resolve this some other way?

jpasquers commented 1 year ago

Following up here, we isolated the issue to our usage of JIT with php8. Particularly, this exact addition to php.ini caused this log to be spammed:

opcache.jit_buffer_size=512M
opcache.jit=1255

I'm not sure if this helps @bwoebi or @PROFeNoM

PROFeNoM commented 1 year ago

Hi!

Good news, we've been able to reproduce this issue with the additional information you gave us, which confirms the artifact addresses the issue 😃

It will be fixed (#2227) in the next release, but in the meantime, you should be able to use the artifact above :+1: