Skip to content

Commit 81b49cd

Browse files
authored
[RUM-12424] GraphQL Documentation (#32784)
* graphQL documentation * Enhance documentation * Nitpick * Consistency with other parameter * Add a link to graphql doc in attributes * Modify title
1 parent f566b98 commit 81b49cd

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

content/en/real_user_monitoring/application_monitoring/browser/data_collected.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ Detailed network timing data for the loading of an application's resources are c
143143
| `resource.provider.domain` | string | The resource provider domain. |
144144
| `resource.provider.type` | string | The resource provider type (for example, `first-party`, `cdn`, `ad`, or `analytics`). |
145145

146+
### GraphQL attributes
147+
148+
For GraphQL requests configured in `allowedGraphQlUrls`, additional metadata is automatically collected. See [Track GraphQL requests][15] for configuration details.
149+
150+
| Attribute | Type | Description |
151+
|---------------------------------|--------|------------------------------------------------------------------------------------------------------|
152+
| `resource.graphql.operation_type` | string | The GraphQL operation type: `query`, `mutation`, or `subscription`. |
153+
| `resource.graphql.operation_name` | string | The GraphQL operation name, if provided in the request. |
154+
| `resource.graphql.variables` | string | The GraphQL variables sent with the request. |
155+
| `resource.graphql.payload` | string | The GraphQL query (limited to 32 KB, available only if `trackPayload` is enabled). |
156+
| `resource.graphql.errors_count` | number | Number of errors returned in the GraphQL response (available only if `trackResponseErrors` is enabled). |
157+
| `resource.graphql.errors` | array | Array of GraphQL errors with `message`, `code`, `locations`, and `path` (available only if `trackResponseErrors` is enabled). |
158+
146159
### Long task timing attributes
147160

148161
| Attribute | Type | Description |
@@ -222,3 +235,4 @@ Source errors include code-level information about the error. For more informati
222235
[12]: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming
223236
[13]: /real_user_monitoring/application_monitoring/browser/tracking_user_actions/?tab=npm#action-timing-telemetry
224237
[14]: /real_user_monitoring/application_monitoring/browser/tracking_user_actions/?tab=npm#custom-actions
238+
[15]: /real_user_monitoring/application_monitoring/browser/monitoring_resource_performance/#track-graphql-requests

content/en/real_user_monitoring/application_monitoring/browser/monitoring_resource_performance.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,53 @@ See [Connect RUM and Traces][2] for information about setting up this feature.
3434

3535
{{< img src="real_user_monitoring/browser/resource_performance_graph.png" alt="APM Trace information for a RUM Resource" >}}
3636

37-
## Resource attributes
37+
## Track GraphQL requests
38+
39+
The Browser SDK can automatically enrich GraphQL requests with operation-specific metadata, making it easier to identify and debug individual operations in RUM.
40+
41+
### Setup
42+
43+
Configure `allowedGraphQlUrls` during SDK initialization to specify which endpoints should be treated as GraphQL:
44+
45+
```javascript
46+
import { datadogRum } from '@datadog/browser-rum'
47+
48+
datadogRum.init({
49+
applicationId: '<DATADOG_APPLICATION_ID>',
50+
clientToken: '<DATADOG_CLIENT_TOKEN>',
51+
site: 'datadoghq.com',
52+
allowedGraphQlUrls: [
53+
// String: matches any URL starting with the value
54+
"https://api.example.com/graphql",
55+
// RegExp: tests against the full URL
56+
/\/graphql$/,
57+
// Function: evaluates with the URL as parameter, returning true for a match
58+
(url) => url.includes("graphql")
59+
]
60+
})
61+
```
62+
63+
### Advanced options
64+
65+
To collect additional data, use the extended configuration:
66+
67+
```javascript
68+
datadogRum.init({
69+
allowedGraphQlUrls: [
70+
{
71+
match: "https://api.example.com/graphql",
72+
trackPayload: true, // Include GraphQL query (limited to 32 KB)
73+
trackResponseErrors: true // Capture GraphQL errors from responses
74+
}
75+
]
76+
})
77+
```
78+
79+
For matching requests, the SDK automatically extracts operation type, operation name, variables, and optionally the GraphQL query payload and response errors. See [GraphQL attributes][8] for the complete list of collected attributes.
80+
81+
**Note**: You can modify GraphQL variables in the [`beforeSend` callback][9] if needed (for example, to redact sensitive data).
82+
83+
## Resource timing attributes
3884

3985
Detailed network timing data for resources is collected from the Fetch and XHR native browser methods and from the [Performance Resource Timing API][3].
4086

@@ -96,3 +142,5 @@ To collect the resource status code, add the `Access-Control-Allow-Origin` HTTP
96142
[5]: https://developer.mozilla.org/en-US/docs/Web/API/Performance_API/Resource_timing#cross-origin_timing_information
97143
[6]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin
98144
[7]: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin
145+
[8]: /real_user_monitoring/application_monitoring/browser/data_collected/#graphql-attributes
146+
[9]: /real_user_monitoring/application_monitoring/browser/advanced_configuration/#modify-the-content-of-a-rum-event

0 commit comments

Comments
 (0)