DataDog/dd-trace-php

[Bug]: Crash in OpenTelemetry Span::getCurrent() when accessing span link from auto instrumentation

tvanhateren opened this issue · 2 comments

Bug report

Context:
A Laravel application instumented with the automatic DataDog instrumentation.
We are trying to add extra metadata to a span using the OpenTelemetry SDK.

So we try to get the current span via the OpenTelemetry SDK.

$span = \OpenTelemetry\SDK\Trace\Span::getCurrent()

Which results in the following error

Error: Typed property DDTrace\SpanLink::$attributes must not be accessed before initialization
 at OpenTelemetry\Context\Context::activateParent (Context:189)
 at OpenTelemetry\Context\Context::activateParent (Context:169)
 at OpenTelemetry\Context\Context::activateParent (Context:169)
 at OpenTelemetry\Context\Context::getCurrent (Context:110)
 at OpenTelemetry\API\Trace\Span::getCurrent (Span:25)

As can be seen in the debugger, the span link does not contain an attributes key
Scherm­afbeelding 2024-07-19 om 17 12 05

PHP version

8.2.19

Tracer or profiler version

1.1.0

Installed extensions

[PHP Modules]
apcu
bcmath
bz2
calendar
Core
ctype
curl
date
ddappsec
ddtrace
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imagick
intl
json
libxml
mailparse
mbstring
openssl
pcntl
pcre
PDO
pdo_sqlite
pdo_sqlsrv
Phar
posix
random
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
sqlite3
sqlsrv
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xdebug
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Xdebug
Zend OPcache
ddappsec
ddtrace

Output of phpinfo()

DATADOG TRACER CONFIGURATION => {
    "date": "2024-07-19T15:15:44Z",
    "os_name": "Linux hub 6.6.32-linuxkit #1 SMP PREEMPT_DYNAMIC Thu Jun 13 14:14:43 UTC 2024 x86_64",
    "os_version": "6.6.32-linuxkit",
    "version": "1.1.0",
    "lang": "php",
    "lang_version": "8.2.13",
    "env": "local",
    "enabled": true,
    "service": "hub-worker",
    "enabled_cli": false,
    "agent_url": "http:\/\/localhost:8126",
    "debug": false,
    "analytics_enabled": false,
    "sample_rate": -1,
    "sampling_rules": [],
    "tags": [],
    "service_mapping": [],
    "distributed_tracing_enabled": true,
    "dd_version": "dev",
    "architecture": "x86_64",
    "instrumentation_telemetry_enabled": true,
    "sapi": "cli",
    "datadog.trace.sources_path": "\/opt\/datadog\/dd-library\/1.1.0\/dd-trace-sources\/src",
    "open_basedir_configured": false,
    "uri_fragment_regex": null,
    "uri_mapping_incoming": null,
    "uri_mapping_outgoing": null,
    "auto_flush_enabled": true,
    "generate_root_span": false,
    "http_client_split_by_domain": false,
    "measure_compile_time": true,
    "report_hostname_on_root_span": false,
    "traced_internal_functions": null,
    "enabled_from_env": false,
    "opcache.file_cache": null,
    "sidecar_trace_sender": false
}

Upgrading from

No response

Hi @tvanhateren
We've just released version 1.2.0, which fixes this issue.

Thanks for the quick fix, I can confirm it works in the new release.