Skip to content

No active span in long running process #1065

Description

@sFreezer

Bug description

we have a long running php process with this config:

DD_TRACE_CLI_ENABLED: true
DD_TRACE_GENERATE_ROOT_SPAN: false
DD_TRACE_AUTO_FLUSH_ENABLED: true

in the formatter for the logging we like to add 'trace_id' and 'span_id':

$span = GlobalTracer::get()->getActiveSpan();
if (null !== $span) {
    $normalizedRecord["dd.trace_id"] = $span->getTraceId();
    $normalizedRecord["dd.span_id"] = $span->getSpanId();
}

but the $span is always null.

In Datadog, we can see that the spans and traces are there. I think the problem here is a bug in the communication with the Php Extension C layer and the Php process. The spans can be managed once through the extension or on PHP layer itself.
With $span = GlobalTracer::get()->getActiveSpan(); I mean only the spans are retrieved on PHP layer

PHP version

PHP 7.4.11 (cli) (built: Oct 22 2020 06:53:01) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with ddtrace v0.48.3, Copyright Datadog, by Datadog

Installed extensions

[PHP Modules]
bcmath
Core
ctype
curl
date
ddtrace
dom
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mongodb
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
rdkafka
readline
Reflection
session
SimpleXML
soap
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]
ddtrace

Diagnostics and configuration

Output of php --ri=ddtrace

DATADOG TRACER CONFIGURATION => {"date":"2020-10-26T16:12:33Z","os_name":"Linux consumer-787cc897dc-btmmk 4.19.112+ #1 SMP Fri Sep 4 12:00:04 PDT 2020 x86_64","os_version":"4.19.112+","version":"0.48.3","lang":"php","lang_version":"7.4.2","env":null,"enabled":true,"service":"pia","enabled_cli":true,"agent_url":"http://10.110.84.74:8126","debug":false,"analytics_enabled":false,"sample_rate":1.000000,"sampling_rules":null,"tags":null,"service_mapping":null,"distributed_tracing_enabled":true,"priority_sampling_enabled":true,"dd_version":null,"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":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,"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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions