Skip to content

feat: API Gateway Tracing#3116

Merged
PROFeNoM merged 38 commits intomasterfrom
alex/AIDM-548_api-gateway-ter
Mar 31, 2025
Merged

feat: API Gateway Tracing#3116
PROFeNoM merged 38 commits intomasterfrom
alex/AIDM-548_api-gateway-ter

Conversation

@PROFeNoM
Copy link
Copy Markdown
Contributor

@PROFeNoM PROFeNoM commented Mar 4, 2025

Description

Based on the following implementation doc: GDoc

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

@PROFeNoM PROFeNoM self-assigned this Mar 4, 2025
@PROFeNoM PROFeNoM mentioned this pull request Mar 4, 2025
2 tasks
Comment thread ext/ddtrace.c Outdated
dd_start_span(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}

/* {{{ proto InferredSpanData\null DDTrace\start_inferred_span(array $headers, SpanData $rootSpan) */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the suggestion of getting rid of this function and instead putting the logic into consume_distributed_tracing_headers(). Did this not work out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, forgot about it. Will try it out 👍

Comment thread ext/span.c
Comment thread ext/span.c Outdated
if (span->std.ce == ddtrace_ce_root_span_data) {
ddtrace_root_span_data *root = ROOTSPANDATA(&span->std);
zval *inferred_span_zv = &root->property_inferred_span;
if (Z_TYPE_P(inferred_span_zv) == IS_OBJECT) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a condition that the inferred_span property is actually an instance of ddtrace_ce_inferred_span_data?

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.98%. Comparing base (760d4a6) to head (ddc3c19).
⚠️ Report is 755 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #3116      +/-   ##
============================================
+ Coverage     52.26%   56.98%   +4.71%     
  Complexity     2883     2883              
============================================
  Files           114      141      +27     
  Lines         11438    15844    +4406     
  Branches          0     1094    +1094     
============================================
+ Hits           5978     9028    +3050     
- Misses         5460     6243     +783     
- Partials          0      573     +573     
Flag Coverage Δ
appsec-extension 69.22% <ø> (?)
tracer-php 52.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 27 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 760d4a6...ddc3c19. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Mar 5, 2025

Benchmarks [ tracer ]

Benchmark execution time: 2025-03-28 19:58:05

Comparing candidate commit ddc3c19 in PR branch alex/AIDM-548_api-gateway-ter with baseline commit 760d4a6 in branch master.

Found 0 performance improvements and 7 performance regressions! Performance is the same for 171 metrics, 0 unstable metrics.

scenario:ContextPropagationBench/benchExtractHeaders128Bit

  • 🟥 execution_time [+61.739ns; +92.927ns] or [+7.756%; +11.674%]

scenario:ContextPropagationBench/benchExtractHeaders128Bit-opcache

  • 🟥 execution_time [+66.455ns; +80.212ns] or [+8.419%; +10.162%]

scenario:ContextPropagationBench/benchExtractTraceContext128Bit

  • 🟥 execution_time [+67.444ns; +112.556ns] or [+3.850%; +6.424%]

scenario:ContextPropagationBench/benchExtractTraceContext128Bit-opcache

  • 🟥 execution_time [+88.300ns; +157.700ns] or [+5.031%; +8.986%]

scenario:ContextPropagationBench/benchExtractTraceContext64Bit

  • 🟥 execution_time [+60.145ns; +89.855ns] or [+7.594%; +11.345%]

scenario:ContextPropagationBench/benchExtractTraceContext64Bit-opcache

  • 🟥 execution_time [+50.273ns; +93.727ns] or [+6.261%; +11.672%]

scenario:TraceFlushBench/benchFlushTrace

  • 🟥 execution_time [+1000.000ns; +1000.000ns] or [+100.000%; +100.000%]

Comment thread ext/serializer.c Outdated
})

if (inferred_span) {
ddtrace_serialize_span_to_array(inferred_span, array);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we could do all the transfer_data calls here (from serialized to inferred serialized), after the serializing step. But I won't insist.

Comment thread ext/serializer.c Outdated
}

if (inferred_span) {
ddtrace_serialize_span_to_array(inferred_span, array);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make ddtrace_serialize_span_to_array return the inserted array instead of refetching from Z_ARR_P(array).

Comment thread ext/serializer.c Outdated

add_next_index_zval(array, el);

return el;
Copy link
Copy Markdown
Collaborator

@bwoebi bwoebi Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noooo :-D
That returns a stack variable.

Use

return zend_hash_next_index_insert(Z_ARR_P(array), el);

(instead of add_next_index_zval)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok :-)

@PROFeNoM PROFeNoM marked this pull request as ready for review March 10, 2025 09:10
@PROFeNoM PROFeNoM requested a review from a team as a code owner March 10, 2025 09:10
Comment thread ext/span.c Outdated
ZVAL_OBJ(&root->property_inferred_span, &span->std);

span->span_id = ddtrace_generate_span_id();
ddtrace_set_global_span_properties(span);
Copy link
Copy Markdown
Collaborator

@bwoebi bwoebi Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the end of this function or e.g. DD_TAGS=stage:1 will lead to a memory leak

Comment thread ext/serializer.c Outdated
bool is_root_span = span->std.ce == ddtrace_ce_root_span_data;
zval meta_zv, *meta = &span->property_meta;
bool is_inferred_span = span->std.ce == ddtrace_ce_inferred_span_data;
zval meta_zv, *meta = &span->property_meta, *inferred_span_zv = NULL;
Copy link
Copy Markdown
Collaborator

@bwoebi bwoebi Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zval meta_zv, *meta = &span->property_meta, *inferred_span_zv = NULL;
zval meta_zv, *meta = &span->property_meta;
ddtrace_span_data *inferred_span = NULL;
if (is_root_span) {
inferred_span = ddtrace_get_inferred_span(ROOTSPANDATA(&span->std));
}

and then if(inferred_span) ...
Let's check it consistently the same way.

Comment thread ext/serializer.c Outdated
"resource": "GET /test",
"trace_id": 0,
"span_id": 1,
"parent_id": 3978455880403641907,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this assert that "error": 1, for the aws api gateway span too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a crazy catch. I see why.


read_header((zai_str)ZAI_STRL("X_DD_PROXY_PATH"), "x-dd-proxy-path", &result.path, data);
read_header((zai_str)ZAI_STRL("X_DD_PROXY_HTTPMETHOD"), "x-dd-proxy-httpmethod", &result.http_method, data);
read_header((zai_str)ZAI_STRL("X_DD_PROXY_DOMAIN_NAME"), "x-dd-proxy-domain-name", &result.domain, data);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the value of the service if x-dd-proxy-domain-name is not provided?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Asking because it's unclear to me from the test what happens)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read the code correctly, service then is never assigned and falls back to the empty string.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no fallback we should try to use DD_SERVICE where possible so we don't send the span with an empty service name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified to fallback to the root span's service name. I can modify it to strictly be DD_SERVICE, but then we'd have to have some special handling when altering DD_SERVICE (+The service is sometimes inferred from the app config - e.g. Laravel).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new behaviour is perfectly fine.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looping in @zarirhamza in case he has other feedback about this!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PROFeNoM PROFeNoM marked this pull request as draft March 18, 2025 08:03
@PROFeNoM PROFeNoM marked this pull request as ready for review March 18, 2025 08:33
Comment thread ext/serializer.c Outdated
transfer_data(serialized_meta, serialized_inferred_span_meta, ZEND_STRL("error"), false);
transfer_data(serialized_meta, serialized_inferred_span_meta, ZEND_STRL("track_error"), false);
transfer_data(Z_ARR_P(el), Z_ARR_P(serialized_inferred_span), ZEND_STRL("error"), false);
transfer_data(Z_ARR_P(el), Z_ARR_P(serialized_inferred_span), ZEND_STRL("track_error"), false);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

track_error is in meta though, right? Only array is top-level.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it? I looked at the following line, and considering that it is added the same way as error is, I would have assumed that it wasn't

Copy link
Copy Markdown
Collaborator

@bwoebi bwoebi Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, but that's because the code adding track_error is wrong :-( Should be on meta...
Could you please fix it over there in this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok 👍 Will do in the next commit

@PROFeNoM PROFeNoM marked this pull request as draft March 19, 2025 08:52
@PROFeNoM PROFeNoM marked this pull request as ready for review March 19, 2025 09:20
PROFeNoM and others added 6 commits March 27, 2025 08:46
# Conflicts:
#	ext/configuration.h
#	ext/ddtrace_arginfo.h
#	tests/Frameworks/Laravel/Latest/.env
#	tests/Integrations/CLI/Laravel/Latest/CommonScenariosTest.php
#	tests/Integrations/Laravel/Latest/CommonScenariosTest.php
Signed-off-by: Bob Weinand <[email protected]>
@bwoebi bwoebi force-pushed the alex/AIDM-548_api-gateway-ter branch from 7255612 to 088b3a2 Compare March 27, 2025 20:06
@bwoebi bwoebi force-pushed the alex/AIDM-548_api-gateway-ter branch from f234ee7 to 553515e Compare March 28, 2025 14:10
@PROFeNoM PROFeNoM merged commit dfe83ec into master Mar 31, 2025
751 of 769 checks passed
@PROFeNoM PROFeNoM deleted the alex/AIDM-548_api-gateway-ter branch March 31, 2025 08:31
@github-actions github-actions Bot added this to the 1.8.0 milestone Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants