-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No active span in long running process #1065
Comments
Our documentation on connecting logs in PHP has this example using $span = \DDTrace\GlobalTracer::get()->getActiveSpan();
$append = sprintf(
' [dd.trace_id=%d dd.span_id=%d]',
$span->getTraceId(),
\dd_trace_peek_span_id()
);
my_error_logger('Error message.' . $append); I realize it's inconvenient and unexpected, but it's an officially documented work-around that we'll support until the PHP <-> Extension gap is better handled, which we are working on this quarter and the next. |
If I read the issue correctly, the problem is that the value returned by The reason for it is that in case of long running scripts the root span is internal, while typically, for web requests and short leaved scripts, the root span is a user-land span, hence available from We can have a workaround and then I can provide mid and long term solutions. Workaround/short-term Instead of using automatic root span creation like I assume you (correctly) do today, e.g.
You can create the root span manually, unfortunately in a more invasive way. Instead of doing what's above, you do
You would do this ONLY for the root span, if you have other functions traced, you can leave them as they are, with the 'correct' automatic approach. You might add checks to only execute our code if the tracer is installed, just to be sure, but you got the idea. If you do this, then your root span will be populated and you can run the snippet as suggested by @morrisonlevi. mid-term Unfortunately, I cannot commit to release it with the next release, as we have to prioritize other work. long-term In any case we are moving away from userland spans altogether to rely only on internal spans, so this will require no work on your side if you already enrolled in the mid-term solution. |
in the docs for monolog you check for the activeSpan
but i still tried it:
$activeSpan is null unfortunately that doesn't help |
Hi @sFreezer, did you have a chance to test the manual approach? |
I am unfortunately not yet, I will try to test the next week and then contact you guys again |
we are using dd_trace_method() to define the methods we like to trace in our long running processes. |
We're also hitting this issue and is a major frustration. We're tracing most code via We really need this to be in a situation where the two interop properly, though I can't really see how this'll work in a post-hook C world, and a inner-hook style user-land world? Hopefully we're misunderstanding here as we're paying a decent chunk each month here for constant headaches upgrading, amends to become re-compatible and working around different breaks either intentionally or unintentionally in functionality each time, which is increasingly costly to us. |
I want to make sure I understand the issues completely:
We can mitigate the first two issues. Luca proposed adding a function like Did I understand everything here @sFreezer and @ben-challis? |
Hi @morrisonlevi - you've understood - thanks for explaining how this solution could work, great news.
Sure thing, will raise a separate issue for this. I took some time yesterday with more trial and error and I believe this is |
@morrisonlevi yes you got it right, the thing is that dd_trace_peek_span_id it not working -> getting "0" all the time link |
Thanks for the response, @sFreezer. In this specific case, I think the behavior seems consistent because there wasn't an active span. Does it seem right to you that there wasn't a span there? If there should be a span, can you create a sample for reproducing it? |
@morrisonlevi i don't quite understand what else you need from me, i have written all information in this ticket. |
Hi @sFreezer we released 0.53.0 (and updated the docs) to expose a function that correctly returns the trace id in all the various scenarios, please follow this guide: https://docs.datadoghq.com/tracing/connect_logs_and_traces/php/#manually-inject-trace-and-span-ids The function is Please confirm is this worked for you. |
Hi, @labbati, |
Bug description
we have a long running php process with this config:
in the formatter for the logging we like to add 'trace_id' and 'span_id':
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}
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
The text was updated successfully, but these errors were encountered: