dd-trace-php icon indicating copy to clipboard operation
dd-trace-php copied to clipboard

[Feature] Add phpStan stub file so

Open NickStallman opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. phpstan will statically analyse source code to find potential issues. Currently as ddtrace defines functions like trace_method and classes like SpanData that phpstan doesn't know about, it will complain loudly about any custom tracing code.

Describe the solution you'd like An official stub file to give phpStan the information it needs would be fantastic.

An initial file I've been using is: ddtrace.stub

<?php

namespace DDTrace;

/**
 * @param array<mixed> $args
 */
function trace_method(\DDTrace\SpanData $span, array $args, mixed $retval, ?\Exception $exception): void
{
}

namespace DDTrace;
class SpanData
{
    public string $name;
    public string $resource;
    public string $service;
    public string $type;
    /** @var string[] $meta */
    public $meta;
    /** @var float[] $metrics */
    public $metrics;
}

NickStallman avatar Apr 21 '22 23:04 NickStallman

We have planned on moving towards PHP stub files (As a starting point I've begun experimenting with https://github.com/DataDog/dd-trace-php/blob/52106acf64fb45acd6c74f85fc58adead4a5ff4c/ext/hook/uhook.stub.php).

Expect to see this becoming reality in the coming months :-)

bwoebi avatar Apr 22 '22 11:04 bwoebi

Looking forward to stub files, any movement here? Thanks!

ralphschindler avatar Jan 31 '23 14:01 ralphschindler

We are actively planning on doing this in the next 2-3 months.

bwoebi avatar Jan 31 '23 15:01 bwoebi

We now have the following .stub.php files (to be released soon as 0.85.0):

  • ext/ddtrace.stub.php
  • ext/hook/uhook.stub.php
  • ext/hook/uhook_attributes.stub.php

@ralphschindler and @NickStallman I hope that's solving all the doc and autocompletion issues you were having :-)

bwoebi avatar Mar 10 '23 11:03 bwoebi

Brilliant! Thanks. :)

NickStallman avatar Mar 10 '23 16:03 NickStallman