You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The docs for router telemetry have new example configurations for common use cases for [selectors](https://www.apollographql.com/docs/graphos/reference/router/telemetry/instrumentation/selectors) and [condition](https://www.apollographql.com/docs/graphos/reference/router/telemetry/instrumentation/conditions).
4
+
5
+
By [@shorgi](https://github.com/shorgi) in https://github.com/apollographql/router/pull/6487
Copy file name to clipboardexpand all lines: docs/source/reference/router/telemetry/instrumentation/conditions.mdx
+74
Original file line number
Diff line number
Diff line change
@@ -154,3 +154,77 @@ The available basic conditions:
154
154
| `any` | A list of conditions of which at least one must be true |
155
155
156
156
You can create complex conditions by using these basic conditions as building blocks.
157
+
158
+
## Example condition configurations
159
+
160
+
Some example configuration of common use cases for conditions.
161
+
162
+
### Event for a specific subgraph
163
+
164
+
You can trigger an event for a specific subgraph by configuring a condition with the subgraph's name.
165
+
166
+
The example below uses the [`subgraph_name`](/router/configuration/telemetry/instrumentation/selectors#subgraph) selector to log subgraph responses for the subgraph named "products":
167
+
168
+
```yaml title=router.yaml
169
+
telemetry:
170
+
instrumentation:
171
+
events:
172
+
subgraph:
173
+
response:
174
+
level: info
175
+
condition:
176
+
eq:
177
+
- subgraph_name: true
178
+
- "products"
179
+
```
180
+
181
+
### On GraphQL error
182
+
183
+
You can use the [`on_graphql_error`](/router/configuration/telemetry/instrumentation/selectors#supergraph) selector to create a condition based on whether or not a GraphQL error is present.
184
+
185
+
The example configuration below uses `on_graphql_error` to log only supergraph responses that contain GraphQL errors:
186
+
187
+
```yaml title="router.yaml"
188
+
telemetry:
189
+
instrumentation:
190
+
events:
191
+
router:
192
+
request:
193
+
level: info
194
+
condition: # Only log the router request if you sent `x-log-request` with the value `enabled`
195
+
eq:
196
+
- request_header: x-log-request
197
+
- "enabled"
198
+
response: off
199
+
error: error
200
+
supergraph:
201
+
response:
202
+
level: info
203
+
condition: # Only log supergraph response containing GraphQL errors
204
+
eq:
205
+
- on_graphql_error: true
206
+
- true
207
+
error: error
208
+
```
209
+
210
+
### On large payloads
211
+
212
+
For observability of large payloads, you can set attributes using conditions that indicate whether the length of a request or response exceeds a threshold.
213
+
214
+
The example below sets a custom attribute to `true` if the length of a request is greater than 100:
215
+
216
+
```yaml
217
+
telemetry:
218
+
instrumentation:
219
+
spans:
220
+
mode: spec_compliant
221
+
router:
222
+
attributes:
223
+
trace_id: true
224
+
payload_is_to_big: # Set this attribute to true if the value of content-length header is > than 100
| `query_variable` | Yes | | The name of a GraphQL query variable |
58
59
| `request_header` | Yes | | The name of a request header |
59
60
| `response_header` | Yes | | The name of a response header |
60
-
| `is_primary_response` | No | `true`\|`false` | Boolean returning true if it's the primary response and not events like subscription events or deferred responses |
61
+
| `is_primary_response` | No | `true` \| `false` | Boolean returning true if it's the primary response and not events like subscription events or deferred responses |
61
62
| `response_data` | Yes | | JSON Path into the supergraph response body data (it might impact performance) |
62
63
| `response_errors` | Yes | | JSON Path into the supergraph response body errors (it might impact performance) |
63
64
| `request_context` | Yes | | The name of a request context key |
64
65
| `response_context` | Yes | | The name of a response context key |
65
-
| `on_graphql_error` | No | `true`\|`false` | Boolean set to true if the response payload contains a GraphQL error |
66
+
| `on_graphql_error` | No | `true` \| `false` | Boolean set to true if the response payload contains a GraphQL error |
66
67
| `baggage` | Yes | | The name of a baggage item |
67
68
| `env` | Yes | | The name of an environment variable |
68
69
| `static` | No | | A static string value |
@@ -74,30 +75,30 @@ The subgraph service executes multiple times during query execution, with each e
0 commit comments