Skip to content

Commit b9f0323

Browse files
authored
Fix top Code Origin frame for ExecIntegration and KafkaIntegration (#3392)
* Fix top Code Origin frame for ExecIntegration and KafkaIntegration Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com> * Fix double code origin --------- Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
1 parent 83d8f2e commit b9f0323

9 files changed

+179
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Changelog for older versions can be found in our [release page](https://github.c
2222
- Fix names of global git tags for debugger #3377
2323
- Fix SQLSRVIntegration resource handling #3379
2424
- Set DD_APPSEC_RASP_ENABLED default to true as on the tracer #3374
25+
- Fix top Code Origin frame for ExecIntegration and KafkaIntegration #3392
2526

2627
### Internal
2728
- Update baggage telemetry typo #3382

ext/code_origins.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ void ddtrace_add_code_origin_information(ddtrace_span_data *span, int skip_frame
1717
if (skip_frames > 0) {
1818
--skip_frames;
1919
} else {
20+
if (current_frame == 0) {
21+
zval type, *kind = zend_hash_str_find_deref(meta, ZEND_STRL("span.kind"));
22+
ZVAL_STRING(&type, (kind && Z_TYPE_P(kind) == IS_STRING ? zend_string_equals_literal(Z_STR_P(kind), "server") || zend_string_equals_literal(Z_STR_P(kind), "producer") : &span->root->span == span) ? "entry" : "exit");
23+
if (!zend_hash_str_add(meta, ZEND_STRL("_dd.code_origin.type"), &type)) {
24+
zend_string_release(Z_STR(type));
25+
return; // skip if already present
26+
}
27+
}
28+
2029
zval zv;
2130
zend_string *key;
2231

@@ -48,17 +57,6 @@ void ddtrace_add_code_origin_information(ddtrace_span_data *span, int skip_frame
4857
}
4958
execute_data = EX(prev_execute_data);
5059
}
51-
52-
// current_frame is typically 0 when a file is the entrypoint.
53-
if (current_frame != 0) {
54-
zval *kind = zend_hash_str_find_deref(meta, ZEND_STRL("span.kind"));
55-
56-
zval type;
57-
ZVAL_STRING(&type, (kind && Z_TYPE_P(kind) == IS_STRING ? zend_string_equals_literal(Z_STR_P(kind), "server") || zend_string_equals_literal(Z_STR_P(kind), "producer") : &span->root->span == span) ? "entry" : "exit");
58-
if (!zend_hash_str_add(meta, ZEND_STRL("_dd.code_origin.type"), &type)) {
59-
zend_string_release(Z_STR(type));
60-
}
61-
}
6260
}
6361

6462
void ddtrace_maybe_add_code_origin_information(ddtrace_span_data *span) {

loader/tests/functional/test_ddtrace_is_fully_loaded.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
[type] => system
3737
[meta] => Array
3838
(
39+
[_dd.code_origin.frames.0.file] => %s/fixtures/ddtrace.php
40+
[_dd.code_origin.frames.0.line] => 1
41+
[_dd.code_origin.type] => exit
3942
[cmd.exit_code] => 0
4043
[cmd.shell] => echo using passthru
4144
[component] => subprocess

src/DDTrace/Integrations/Exec/ExecIntegration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ private static function createSpan(array $tags, string $resource)
278278
$span->meta = $tags;
279279
$span->type = Type::SYSTEM;
280280
$span->resource = $resource;
281+
\DDTrace\collect_code_origins(2); // manually collect origin, otherwise the top frame will be this integration
281282
switch_stack();
282283

283284
return $span;

src/DDTrace/Integrations/Kafka/KafkaIntegration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ function (HookData $hook) use ($integration) {
143143

144144
$hook->data['span'] = $span;
145145
$integration->setupKafkaConsumeSpan($hook, $this);
146+
\DDTrace\collect_code_origins(1);
146147
\DDTrace\close_span();
147148
}
148149
);

tests/snapshots/tests.integrations.cli.symfony.latest.common_scenarios_test.test_silenced_spans_are_dropped.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,37 @@
2626
"parent_id": 1,
2727
"type": "system",
2828
"meta": {
29+
"_dd.code_origin.frames.0.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/console/Terminal.php",
30+
"_dd.code_origin.frames.0.line": "199",
31+
"_dd.code_origin.frames.0.method": "readFromProcess",
32+
"_dd.code_origin.frames.0.type": "Symfony\\Component\\Console\\Terminal",
33+
"_dd.code_origin.frames.1.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/console/Terminal.php",
34+
"_dd.code_origin.frames.1.line": "196",
35+
"_dd.code_origin.frames.1.method": "getSttyColumns",
36+
"_dd.code_origin.frames.1.type": "Symfony\\Component\\Console\\Terminal",
37+
"_dd.code_origin.frames.2.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/console/Terminal.php",
38+
"_dd.code_origin.frames.2.line": "162",
39+
"_dd.code_origin.frames.2.method": "initDimensionsUsingStty",
40+
"_dd.code_origin.frames.2.type": "Symfony\\Component\\Console\\Terminal",
41+
"_dd.code_origin.frames.3.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/console/Terminal.php",
42+
"_dd.code_origin.frames.3.line": "153",
43+
"_dd.code_origin.frames.3.method": "initDimensions",
44+
"_dd.code_origin.frames.3.type": "Symfony\\Component\\Console\\Terminal",
45+
"_dd.code_origin.frames.4.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/console/Terminal.php",
46+
"_dd.code_origin.frames.4.line": "111",
47+
"_dd.code_origin.frames.4.method": "getHeight",
48+
"_dd.code_origin.frames.4.type": "Symfony\\Component\\Console\\Terminal",
49+
"_dd.code_origin.frames.5.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/console/Application.php",
50+
"_dd.code_origin.frames.5.line": "166",
51+
"_dd.code_origin.frames.5.method": "run",
52+
"_dd.code_origin.frames.5.type": "Symfony\\Component\\Console\\Application",
53+
"_dd.code_origin.frames.6.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php",
54+
"_dd.code_origin.frames.6.line": "49",
55+
"_dd.code_origin.frames.6.method": "run",
56+
"_dd.code_origin.frames.6.type": "Symfony\\Component\\Runtime\\Runner\\Symfony\\ConsoleApplicationRunner",
57+
"_dd.code_origin.frames.7.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/autoload_runtime.php",
58+
"_dd.code_origin.frames.7.line": "29",
59+
"_dd.code_origin.type": "exit",
2960
"cmd.exec": "[\"stty\",\"-a\"]",
3061
"cmd.exit_code": "0",
3162
"component": "subprocess"
@@ -78,6 +109,35 @@
78109
"parent_id": 1,
79110
"type": "system",
80111
"meta": {
112+
"_dd.code_origin.frames.0.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/console/Application.php",
113+
"_dd.code_origin.frames.0.line": "999",
114+
"_dd.code_origin.frames.0.method": "doRunCommand",
115+
"_dd.code_origin.frames.0.type": "Symfony\\Component\\Console\\Application",
116+
"_dd.code_origin.frames.1.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/framework-bundle/Console/Application.php",
117+
"_dd.code_origin.frames.1.line": "123",
118+
"_dd.code_origin.frames.1.method": "doRunCommand",
119+
"_dd.code_origin.frames.1.type": "Symfony\\Bundle\\FrameworkBundle\\Console\\Application",
120+
"_dd.code_origin.frames.2.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/console/Application.php",
121+
"_dd.code_origin.frames.2.line": "341",
122+
"_dd.code_origin.frames.2.method": "doRun",
123+
"_dd.code_origin.frames.2.type": "Symfony\\Component\\Console\\Application",
124+
"_dd.code_origin.frames.3.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/framework-bundle/Console/Application.php",
125+
"_dd.code_origin.frames.3.line": "77",
126+
"_dd.code_origin.frames.3.method": "doRun",
127+
"_dd.code_origin.frames.3.type": "Symfony\\Bundle\\FrameworkBundle\\Console\\Application",
128+
"_dd.code_origin.frames.4.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/console/Application.php",
129+
"_dd.code_origin.frames.4.line": "192",
130+
"_dd.code_origin.frames.4.method": "run",
131+
"_dd.code_origin.frames.4.type": "Symfony\\Component\\Console\\Application",
132+
"_dd.code_origin.frames.5.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php",
133+
"_dd.code_origin.frames.5.line": "49",
134+
"_dd.code_origin.frames.5.method": "run",
135+
"_dd.code_origin.frames.5.type": "Symfony\\Component\\Runtime\\Runner\\Symfony\\ConsoleApplicationRunner",
136+
"_dd.code_origin.frames.6.file": "{path}/tests/Frameworks/Symfony/Latest/vendor/autoload_runtime.php",
137+
"_dd.code_origin.frames.6.line": "29",
138+
"_dd.code_origin.frames.7.file": "{path}/tests/Frameworks/Symfony/Latest/bin/console",
139+
"_dd.code_origin.frames.7.line": "11",
140+
"_dd.code_origin.type": "exit",
81141
"cmd.shell": "stty -g",
82142
"component": "subprocess"
83143
}

tests/snapshots/tests.integrations.cli.symfony.v4_4.common_scenarios_test.test_silenced_spans_are_dropped.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,33 @@
2626
"parent_id": 1,
2727
"type": "system",
2828
"meta": {
29+
"_dd.code_origin.frames.0.file": "{path}/tests/Frameworks/Symfony/Version_4_4/vendor/symfony/console/Terminal.php",
30+
"_dd.code_origin.frames.0.line": "151",
31+
"_dd.code_origin.frames.0.method": "readFromProcess",
32+
"_dd.code_origin.frames.0.type": "Symfony\\Component\\Console\\Terminal",
33+
"_dd.code_origin.frames.1.file": "{path}/tests/Frameworks/Symfony/Version_4_4/vendor/symfony/console/Terminal.php",
34+
"_dd.code_origin.frames.1.line": "148",
35+
"_dd.code_origin.frames.1.method": "getSttyColumns",
36+
"_dd.code_origin.frames.1.type": "Symfony\\Component\\Console\\Terminal",
37+
"_dd.code_origin.frames.2.file": "{path}/tests/Frameworks/Symfony/Version_4_4/vendor/symfony/console/Terminal.php",
38+
"_dd.code_origin.frames.2.line": "114",
39+
"_dd.code_origin.frames.2.method": "initDimensionsUsingStty",
40+
"_dd.code_origin.frames.2.type": "Symfony\\Component\\Console\\Terminal",
41+
"_dd.code_origin.frames.3.file": "{path}/tests/Frameworks/Symfony/Version_4_4/vendor/symfony/console/Terminal.php",
42+
"_dd.code_origin.frames.3.line": "97",
43+
"_dd.code_origin.frames.3.method": "initDimensions",
44+
"_dd.code_origin.frames.3.type": "Symfony\\Component\\Console\\Terminal",
45+
"_dd.code_origin.frames.4.file": "{path}/tests/Frameworks/Symfony/Version_4_4/vendor/symfony/console/Terminal.php",
46+
"_dd.code_origin.frames.4.line": "52",
47+
"_dd.code_origin.frames.4.method": "getHeight",
48+
"_dd.code_origin.frames.4.type": "Symfony\\Component\\Console\\Terminal",
49+
"_dd.code_origin.frames.5.file": "{path}/tests/Frameworks/Symfony/Version_4_4/vendor/symfony/console/Application.php",
50+
"_dd.code_origin.frames.5.line": "118",
51+
"_dd.code_origin.frames.5.method": "run",
52+
"_dd.code_origin.frames.5.type": "Symfony\\Component\\Console\\Application",
53+
"_dd.code_origin.frames.6.file": "{path}/tests/Frameworks/Symfony/Version_4_4/bin/console",
54+
"_dd.code_origin.frames.6.line": "42",
55+
"_dd.code_origin.type": "exit",
2956
"cmd.exit_code": "0",
3057
"cmd.shell": "stty -a | grep columns",
3158
"component": "subprocess"

tests/snapshots/tests.integrations.cli.symfony.v5_2.common_scenarios_test.test_silenced_spans_are_dropped.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,33 @@
2626
"parent_id": 1,
2727
"type": "system",
2828
"meta": {
29+
"_dd.code_origin.frames.0.file": "{path}/tests/Frameworks/Symfony/Version_5_2/vendor/symfony/console/Terminal.php",
30+
"_dd.code_origin.frames.0.line": "151",
31+
"_dd.code_origin.frames.0.method": "readFromProcess",
32+
"_dd.code_origin.frames.0.type": "Symfony\\Component\\Console\\Terminal",
33+
"_dd.code_origin.frames.1.file": "{path}/tests/Frameworks/Symfony/Version_5_2/vendor/symfony/console/Terminal.php",
34+
"_dd.code_origin.frames.1.line": "148",
35+
"_dd.code_origin.frames.1.method": "getSttyColumns",
36+
"_dd.code_origin.frames.1.type": "Symfony\\Component\\Console\\Terminal",
37+
"_dd.code_origin.frames.2.file": "{path}/tests/Frameworks/Symfony/Version_5_2/vendor/symfony/console/Terminal.php",
38+
"_dd.code_origin.frames.2.line": "114",
39+
"_dd.code_origin.frames.2.method": "initDimensionsUsingStty",
40+
"_dd.code_origin.frames.2.type": "Symfony\\Component\\Console\\Terminal",
41+
"_dd.code_origin.frames.3.file": "{path}/tests/Frameworks/Symfony/Version_5_2/vendor/symfony/console/Terminal.php",
42+
"_dd.code_origin.frames.3.line": "97",
43+
"_dd.code_origin.frames.3.method": "initDimensions",
44+
"_dd.code_origin.frames.3.type": "Symfony\\Component\\Console\\Terminal",
45+
"_dd.code_origin.frames.4.file": "{path}/tests/Frameworks/Symfony/Version_5_2/vendor/symfony/console/Terminal.php",
46+
"_dd.code_origin.frames.4.line": "52",
47+
"_dd.code_origin.frames.4.method": "getHeight",
48+
"_dd.code_origin.frames.4.type": "Symfony\\Component\\Console\\Terminal",
49+
"_dd.code_origin.frames.5.file": "{path}/tests/Frameworks/Symfony/Version_5_2/vendor/symfony/console/Application.php",
50+
"_dd.code_origin.frames.5.line": "135",
51+
"_dd.code_origin.frames.5.method": "run",
52+
"_dd.code_origin.frames.5.type": "Symfony\\Component\\Console\\Application",
53+
"_dd.code_origin.frames.6.file": "{path}/tests/Frameworks/Symfony/Version_5_2/bin/console",
54+
"_dd.code_origin.frames.6.line": "43",
55+
"_dd.code_origin.type": "exit",
2956
"cmd.exit_code": "0",
3057
"cmd.shell": "stty -a | grep columns",
3158
"component": "subprocess"

tests/snapshots/tests.integrations.cli.symfony.v6_2.common_scenarios_test.test_silenced_spans_are_dropped.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,33 @@
2626
"parent_id": 1,
2727
"type": "system",
2828
"meta": {
29+
"_dd.code_origin.frames.0.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/console/Terminal.php",
30+
"_dd.code_origin.frames.0.line": "207",
31+
"_dd.code_origin.frames.0.method": "readFromProcess",
32+
"_dd.code_origin.frames.0.type": "Symfony\\Component\\Console\\Terminal",
33+
"_dd.code_origin.frames.1.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/console/Terminal.php",
34+
"_dd.code_origin.frames.1.line": "204",
35+
"_dd.code_origin.frames.1.method": "getSttyColumns",
36+
"_dd.code_origin.frames.1.type": "Symfony\\Component\\Console\\Terminal",
37+
"_dd.code_origin.frames.2.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/console/Terminal.php",
38+
"_dd.code_origin.frames.2.line": "170",
39+
"_dd.code_origin.frames.2.method": "initDimensionsUsingStty",
40+
"_dd.code_origin.frames.2.type": "Symfony\\Component\\Console\\Terminal",
41+
"_dd.code_origin.frames.3.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/console/Terminal.php",
42+
"_dd.code_origin.frames.3.line": "153",
43+
"_dd.code_origin.frames.3.method": "initDimensions",
44+
"_dd.code_origin.frames.3.type": "Symfony\\Component\\Console\\Terminal",
45+
"_dd.code_origin.frames.4.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/console/Terminal.php",
46+
"_dd.code_origin.frames.4.line": "111",
47+
"_dd.code_origin.frames.4.method": "getHeight",
48+
"_dd.code_origin.frames.4.type": "Symfony\\Component\\Console\\Terminal",
49+
"_dd.code_origin.frames.5.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/console/Application.php",
50+
"_dd.code_origin.frames.5.line": "142",
51+
"_dd.code_origin.frames.5.method": "run",
52+
"_dd.code_origin.frames.5.type": "Symfony\\Component\\Console\\Application",
53+
"_dd.code_origin.frames.6.file": "{path}/tests/Frameworks/Symfony/Version_6_2/bin/console",
54+
"_dd.code_origin.frames.6.line": "43",
55+
"_dd.code_origin.type": "exit",
2956
"cmd.exec": "[\"stty\",\"-a\"]",
3057
"cmd.exit_code": "0",
3158
"component": "subprocess"
@@ -72,6 +99,29 @@
7299
"parent_id": 1,
73100
"type": "system",
74101
"meta": {
102+
"_dd.code_origin.frames.0.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/console/Application.php",
103+
"_dd.code_origin.frames.0.line": "972",
104+
"_dd.code_origin.frames.0.method": "doRunCommand",
105+
"_dd.code_origin.frames.0.type": "Symfony\\Component\\Console\\Application",
106+
"_dd.code_origin.frames.1.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/framework-bundle/Console/Application.php",
107+
"_dd.code_origin.frames.1.line": "88",
108+
"_dd.code_origin.frames.1.method": "doRunCommand",
109+
"_dd.code_origin.frames.1.type": "Symfony\\Bundle\\FrameworkBundle\\Console\\Application",
110+
"_dd.code_origin.frames.2.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/console/Application.php",
111+
"_dd.code_origin.frames.2.line": "314",
112+
"_dd.code_origin.frames.2.method": "doRun",
113+
"_dd.code_origin.frames.2.type": "Symfony\\Component\\Console\\Application",
114+
"_dd.code_origin.frames.3.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/framework-bundle/Console/Application.php",
115+
"_dd.code_origin.frames.3.line": "77",
116+
"_dd.code_origin.frames.3.method": "doRun",
117+
"_dd.code_origin.frames.3.type": "Symfony\\Bundle\\FrameworkBundle\\Console\\Application",
118+
"_dd.code_origin.frames.4.file": "{path}/tests/Frameworks/Symfony/Version_6_2/vendor/symfony/console/Application.php",
119+
"_dd.code_origin.frames.4.line": "168",
120+
"_dd.code_origin.frames.4.method": "run",
121+
"_dd.code_origin.frames.4.type": "Symfony\\Component\\Console\\Application",
122+
"_dd.code_origin.frames.5.file": "{path}/tests/Frameworks/Symfony/Version_6_2/bin/console",
123+
"_dd.code_origin.frames.5.line": "43",
124+
"_dd.code_origin.type": "exit",
75125
"cmd.shell": "stty -g",
76126
"component": "subprocess"
77127
}

0 commit comments

Comments
 (0)