Skip to content

Commit 71a642b

Browse files
authored
fix(graphql): mark graphql.execute spans as measured (#6113) [backport to 1.12] (#6126)
For consistency with other tracers, especially dd-trace-js. --------- Co-authored-by: Yun Kim <[email protected]> (cherry picked from commit 54110dd) ## Checklist - [x] foobar
1 parent cf1cf50 commit 71a642b

11 files changed

+116
-276
lines changed

ddtrace/contrib/graphql/patch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def _traced_execute(func, args, kwargs):
169169
) as span:
170170
span.set_tag_str(COMPONENT, config.graphql.integration_name)
171171

172+
span.set_tag(SPAN_MEASURED_KEY)
173+
172174
_set_span_operation_tags(span, document)
173175
span.set_tag_str(_GRAPHQL_SOURCE, source_str)
174176

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
graphql: ``graphql.execute`` spans are now marked as measured.

tests/snapshots/tests.contrib.graphene.test_graphene.test_schema_execute.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
"_dd.p.dm": "-0",
1313
"component": "graphql",
1414
"language": "python",
15-
"runtime-id": "9203e2a344a64d8da2a34d37d8fe3900"
15+
"runtime-id": "9cdfa74761ee41b8a9a989a2e4eab332"
1616
},
1717
"metrics": {
1818
"_dd.agent_psr": 1.0,
1919
"_dd.measured": 1,
2020
"_dd.top_level": 1,
2121
"_dd.tracer_kr": 1.0,
2222
"_sampling_priority_v1": 1,
23-
"process_id": 80357
23+
"process_id": 9620
2424
},
25-
"duration": 3735000,
26-
"start": 1659643443220117000
25+
"duration": 2463417,
26+
"start": 1686684417449812549
2727
},
2828
{
2929
"name": "graphql.parse",
@@ -38,8 +38,8 @@
3838
"component": "graphql",
3939
"graphql.source": "{ patron { id name age } }"
4040
},
41-
"duration": 229000,
42-
"start": 1659643443221007000
41+
"duration": 178833,
42+
"start": 1686684417450290133
4343
},
4444
{
4545
"name": "graphql.validate",
@@ -54,8 +54,8 @@
5454
"component": "graphql",
5555
"graphql.source": "{ patron { id name age } }"
5656
},
57-
"duration": 1316000,
58-
"start": 1659643443221350000
57+
"duration": 1565292,
58+
"start": 1686684417450525049
5959
},
6060
{
6161
"name": "graphql.execute",
@@ -71,6 +71,9 @@
7171
"graphql.operation.type": "query",
7272
"graphql.source": "{ patron { id name age } }"
7373
},
74-
"duration": 976000,
75-
"start": 1659643443222816000
74+
"metrics": {
75+
"_dd.measured": 1
76+
},
77+
"duration": 116541,
78+
"start": 1686684417452143508
7679
}]]

tests/snapshots/tests.contrib.graphene.test_graphene.test_schema_execute_with_resolvers.json

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
"_dd.p.dm": "-0",
1313
"component": "graphql",
1414
"language": "python",
15-
"runtime-id": "9203e2a344a64d8da2a34d37d8fe3900"
15+
"runtime-id": "9cdfa74761ee41b8a9a989a2e4eab332"
1616
},
1717
"metrics": {
1818
"_dd.agent_psr": 1.0,
1919
"_dd.measured": 1,
2020
"_dd.top_level": 1,
2121
"_dd.tracer_kr": 1.0,
2222
"_sampling_priority_v1": 1,
23-
"process_id": 80357
23+
"process_id": 9620
2424
},
25-
"duration": 2818000,
26-
"start": 1659643443277058000
25+
"duration": 2261625,
26+
"start": 1686684417655955174
2727
},
2828
{
2929
"name": "graphql.parse",
@@ -38,8 +38,8 @@
3838
"component": "graphql",
3939
"graphql.source": "{ patron { id name age } }"
4040
},
41-
"duration": 319000,
42-
"start": 1659643443277207000
41+
"duration": 150541,
42+
"start": 1686684417656227008
4343
},
4444
{
4545
"name": "graphql.validate",
@@ -54,8 +54,8 @@
5454
"component": "graphql",
5555
"graphql.source": "{ patron { id name age } }"
5656
},
57-
"duration": 1043000,
58-
"start": 1659643443277626000
57+
"duration": 1478042,
58+
"start": 1686684417656418799
5959
},
6060
{
6161
"name": "graphql.execute",
@@ -71,8 +71,11 @@
7171
"graphql.operation.type": "query",
7272
"graphql.source": "{ patron { id name age } }"
7373
},
74-
"duration": 1093000,
75-
"start": 1659643443278749000
74+
"metrics": {
75+
"_dd.measured": 1
76+
},
77+
"duration": 245666,
78+
"start": 1686684417657958133
7679
},
7780
{
7881
"name": "graphql.resolve",
@@ -86,8 +89,8 @@
8689
"meta": {
8790
"component": "graphql"
8891
},
89-
"duration": 60000,
90-
"start": 1659643443278923000
92+
"duration": 17500,
93+
"start": 1686684417658031299
9194
},
9295
{
9396
"name": "graphql.resolve",
@@ -101,8 +104,8 @@
101104
"meta": {
102105
"component": "graphql"
103106
},
104-
"duration": 33000,
105-
"start": 1659643443279216000
107+
"duration": 13875,
108+
"start": 1686684417658088133
106109
},
107110
{
108111
"name": "graphql.resolve",
@@ -116,8 +119,8 @@
116119
"meta": {
117120
"component": "graphql"
118121
},
119-
"duration": 27000,
120-
"start": 1659643443279338000
122+
"duration": 11750,
123+
"start": 1686684417658131341
121124
},
122125
{
123126
"name": "graphql.resolve",
@@ -131,6 +134,6 @@
131134
"meta": {
132135
"component": "graphql"
133136
},
134-
"duration": 27000,
135-
"start": 1659643443279449000
137+
"duration": 11708,
138+
"start": 1686684417658167841
136139
}]]

tests/snapshots/tests.contrib.graphene.test_graphene.test_schema_failing_execute.json

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
"error.message": "exception was raised in a graphene query\n\nGraphQL request:3:7\n2 | {\n3 | patron {\n | ^\n4 | id",
1515
"error.type": "graphql.error.graphql_error.GraphQLError",
1616
"language": "python",
17-
"runtime-id": "c1db560b55aa4f1284fbe0e80eaad453"
17+
"runtime-id": "9cdfa74761ee41b8a9a989a2e4eab332"
1818
},
1919
"metrics": {
2020
"_dd.agent_psr": 1.0,
2121
"_dd.measured": 1,
2222
"_dd.top_level": 1,
2323
"_dd.tracer_kr": 1.0,
2424
"_sampling_priority_v1": 1,
25-
"process_id": 80691
25+
"process_id": 9620
2626
},
27-
"duration": 4849000,
28-
"start": 1659643456601199000
27+
"duration": 6447083,
28+
"start": 1686684417701375966
2929
},
3030
{
3131
"name": "graphql.parse",
@@ -40,8 +40,8 @@
4040
"component": "graphql",
4141
"graphql.source": "{ patron { id name age } }"
4242
},
43-
"duration": 321000,
44-
"start": 1659643456601818000
43+
"duration": 170417,
44+
"start": 1686684417701833424
4545
},
4646
{
4747
"name": "graphql.validate",
@@ -56,8 +56,8 @@
5656
"component": "graphql",
5757
"graphql.source": "{ patron { id name age } }"
5858
},
59-
"duration": 2488000,
60-
"start": 1659643456602231000
59+
"duration": 1409583,
60+
"start": 1686684417702052716
6161
},
6262
{
6363
"name": "graphql.execute",
@@ -75,8 +75,11 @@
7575
"graphql.operation.type": "query",
7676
"graphql.source": "{ patron { id name age } }"
7777
},
78-
"duration": 1104000,
79-
"start": 1659643456604870000
78+
"metrics": {
79+
"_dd.measured": 1
80+
},
81+
"duration": 4237458,
82+
"start": 1686684417703531216
8083
},
8184
{
8285
"name": "graphql.resolve",
@@ -90,9 +93,9 @@
9093
"meta": {
9194
"component": "graphql",
9295
"error.message": "exception was raised in a graphene query",
93-
"error.stack": "Traceback (most recent call last):\n File \"/Users/munir.abdinur/Documents/ApmPython/dd-trace-py/ddtrace/contrib/graphql/patch.py\", line 219, in _resolver_middleware\n return next_middleware(root, info, **args)\n File \"/Users/munir.abdinur/Documents/ApmPython/dd-trace-py/tests/contrib/graphene/test_graphene.py\", line 26, in resolve_patron\n raise Exception(\"exception was raised in a graphene query\")\nException: exception was raised in a graphene query\n",
96+
"error.stack": "Traceback (most recent call last):\n File \"/root/project/ddtrace/contrib/graphql/patch.py\", line 236, in _resolver_middleware\n return next_middleware(root, info, **args)\n File \"/root/project/tests/contrib/graphene/test_graphene.py\", line 26, in resolve_patron\n raise Exception(\"exception was raised in a graphene query\")\nException: exception was raised in a graphene query\n",
9497
"error.type": "builtins.Exception"
9598
},
96-
"duration": 757000,
97-
"start": 1659643456605007000
99+
"duration": 3819708,
100+
"start": 1686684417703705258
98101
}]]

tests/snapshots/tests.contrib.graphene.test_graphene.test_schema_failing_execute_v2.json

Lines changed: 0 additions & 95 deletions
This file was deleted.

tests/snapshots/tests.contrib.graphql.test_graphql.test_graphql.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
"_dd.p.dm": "-0",
1313
"component": "graphql",
1414
"language": "python",
15-
"runtime-id": "bc0efee142884beb96fdb35ca56aa3dc"
15+
"runtime-id": "4fe099efe4794f50a7d4022ab0de907a"
1616
},
1717
"metrics": {
1818
"_dd.agent_psr": 1.0,
1919
"_dd.measured": 1,
2020
"_dd.top_level": 1,
2121
"_dd.tracer_kr": 1.0,
2222
"_sampling_priority_v1": 1,
23-
"process_id": 76591
23+
"process_id": 4098
2424
},
25-
"duration": 2409000,
26-
"start": 1658848788443487000
25+
"duration": 1675416,
26+
"start": 1686682179892854500
2727
},
2828
{
2929
"name": "graphql.parse",
@@ -38,8 +38,8 @@
3838
"component": "graphql",
3939
"graphql.source": "query HELLO { hello }"
4040
},
41-
"duration": 147000,
42-
"start": 1658848788444365000
41+
"duration": 125167,
42+
"start": 1686682179893382333
4343
},
4444
{
4545
"name": "graphql.validate",
@@ -54,8 +54,8 @@
5454
"component": "graphql",
5555
"graphql.source": "query HELLO { hello }"
5656
},
57-
"duration": 674000,
58-
"start": 1658848788444620000
57+
"duration": 810041,
58+
"start": 1686682179893565500
5959
},
6060
{
6161
"name": "graphql.execute",
@@ -72,6 +72,9 @@
7272
"graphql.operation.type": "query",
7373
"graphql.source": "query HELLO { hello }"
7474
},
75-
"duration": 399000,
76-
"start": 1658848788445460000
75+
"metrics": {
76+
"_dd.measured": 1
77+
},
78+
"duration": 87167,
79+
"start": 1686682179894427916
7780
}]]

0 commit comments

Comments
 (0)