Conversation
labbati
left a comment
There was a problem hiding this comment.
Thank you Bob, added a few comments in the meantime. I am also going to test a specific edge case I have in mind and that I think is not covered in a test, but I will report back on that with an additional comment
|
|
||
| if (\dd_trace_env_config('DD_TRACE_GENERATE_ROOT_SPAN')) { | ||
| self::initRootSpan($tracer); | ||
| self:: initRootSpan($tracer); |
|
|
||
| if (PHP_VERSION_ID >= 80000) { | ||
| foreach ($httpHeaders as $header => $value) { | ||
| if (stripos($header, Propagator::DEFAULT_ORIGIN_HEADER) === 0) { |
There was a problem hiding this comment.
This can fail in case one day any datadog product calling into PHP - e.g. DD Synthetics - adds a tag with the same prefix, e.g.x-datadog-origin-format (that I am totally making up).
I would prefer something like if (strtolower($header) === Propagator::DEFAULT_ORIGIN_HEADER) {...}.
In case you are concerned about the performance impact of lowering potentially many headers, we can lower only when we have to, meaning ...
if (stripos($header, Propagator::DEFAULT_ORIGIN_HEADER) === 0 && strtolower($header) === Propagator::DEFAULT_ORIGIN_HEADER).
I'd suggest to add a test for similar cases as well, and naming the additional header x-datadog-origin-format can be the perfect example I intend the test for.
There was a problem hiding this comment.
while that's totally possible, it's in line with the current handling: https://github.com/DataDog/dd-trace-php/blob/master/src/DDTrace/Propagators/CurlHeadersMap.php#L33 If we want to change that, we probably should do that separately...?
There was a problem hiding this comment.
good point, please create a ticket that we can address later as a low hanging fruit
| } | ||
|
|
||
| return $this->scopeManager->activate($span, $options->shouldFinishSpanOnClose()); | ||
| return $this->scopeManager->activate($span, $options->shouldFinishSpanOnClose() && (PHP_VERSION_ID >= 80000 && $span->getParentId() == 0)); |
There was a problem hiding this comment.
if this logic is what you meant to add, then parenthesis (, ) are redundant.
I am not getting this logic though (I am still going through the remaining code). Is it possible that you meant && (PHP_VERSION_ID < 80000 || $span->getParentId() == 0)?
In case this holds true, then we are definitely missing a test here :)
There was a problem hiding this comment.
Yeah that's not right. And there's also a failing test for that. (but as said, this current PR is fully untested, locally I've done some progress.)
|
|
||
| zend_string *key, *val; | ||
| if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &key, &val) == FAILURE) { | ||
| RETURN_THROWS(); |
There was a problem hiding this comment.
We should not throw. We can log a message in debug mode and proceed the execution.
In general, we never throw exceptions, so users' applications can keep working even if with tracing not perfectly working
| // TODO: also prevent closing internal root spans? Would need marker though | ||
| if (!DDTRACE_G(open_spans_top) || !DDTRACE_G(open_spans_top)->execute_data) { | ||
| zend_throw_exception(NULL, "There is no user-span on the top of the stack. Cannot close.", 0); | ||
| RETURN_THROWS(); |
There was a problem hiding this comment.
Same as above, let's not throw. The maximum that we can accept (but we should avoid it) is that tracing is not working as expected, but users' requests never have to be interrupted because of us.
| zend_string *tag_key; | ||
| zval *tag_value; | ||
| ZEND_HASH_FOREACH_STR_KEY_VAL(DDTRACE_G(additional_global_tags), tag_key, tag_value) { | ||
| zend_hash_add(DDTRACE_G(additional_global_tags), tag_key, tag_value); |
There was a problem hiding this comment.
Not sure I understand what this line does. I think that here we should add from DDTRACE_G(additional_global_tags) into Z_ARR_P(meta)?
If this holds true, then we are missing a test for global + additional globals?
There was a problem hiding this comment.
Yes - and yes, for sure that'll get a test.
| // this also gets set when creating a root span, but may not have the latest up-to-date data | ||
| if ('cli' !== PHP_SAPI && \ddtrace_config_url_resource_name_enabled() | ||
| && $rootScope = $this->getRootScope()) { | ||
| $this->addUrlAsResourceNameToSpan($rootScope->getSpan()); | ||
| } | ||
| /* | ||
| * Having this priority sampling here is actually a bug (should happen after service name | ||
| * substitutions), but it was this way before the refactor, so let's fix this in a | ||
| * subsequent release, when we will have ported everything else to the extension. | ||
| */ | ||
| $tracer = GlobalTracer::get(); | ||
| if (method_exists($tracer, "enforcePrioritySamplingOnRootSpan")) { | ||
| $tracer->enforcePrioritySamplingOnRootSpan(); | ||
| } |
There was a problem hiding this comment.
I am not understanding this part. Reaching out in private to have a quick sync.
cbb32e9 to
c954625
Compare
SammyK
left a comment
There was a problem hiding this comment.
Looking great so far! I'm still reviewing this but I left a few comments/questions so far.
| const zend_function_entry class_DDTrace_SpanData_methods[] = { | ||
| PHP_ME(DDTrace_SpanData, getDuration, arginfo_ddtrace_void, ZEND_ACC_PUBLIC) | ||
| PHP_ME(DDTrace_SpanData, getStartTime, arginfo_ddtrace_void, ZEND_ACC_PUBLIC) PHP_FE_END}; |
There was a problem hiding this comment.
The linter strikes again. :) Wrapping this with // clang-format {off|on} should keep it from getting mangled by the linter.
| /* {{{ proto string dd_trace_peek_span() */ | ||
| static PHP_FUNCTION(dd_trace_peek_span) { | ||
| UNUSED(execute_data); | ||
| if (DDTRACE_G(open_spans_top)) { | ||
| RETURN_OBJ_COPY(&DDTRACE_G(open_spans_top)->span.std); | ||
| } | ||
| RETURN_NULL(); | ||
| } |
There was a problem hiding this comment.
I assume this API is named similar to dd_trace_peek_span_id(), but since we're namespacing all new functions under DDTrace\, that function will likely become DDTrace\active_span_id() (to match the common "active span" terminology). Or we might remove it entirely since the span ID can be obtained from SpanData. WDYT of naming this function DDTrace\active_span()?
There was a problem hiding this comment.
The span id is is currently not exposed on SpanData, but we may add getters for that...
DDTrace\active_span() sounds good to me.
00b89fb to
db9ff73
Compare
Required to attach errors/exceptions to spans after userland is fully destroyed (e.g. in a bailout in shutdown) ... and unblocks incremental migration Signed-off-by: Bob Weinand <[email protected]>
db9ff73 to
4af6430
Compare
Description
Doing a lot of things:
Also note: DRAFT, UNTESTED AND BROKEN.
Readiness checklist
Reviewer checklist