Skip to content

Commit e73428c

Browse files
authored
ref(develop/spans): Expand ignoreSpans type and implementation specification (#14571)
Develop Docs PR that expands the specification for `ignoreSpans`: - add object accepting `name` and `attributes` - specify behaviour around dropping and reparenting of root vs child spans
1 parent 1baf5ed commit e73428c

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

develop-docs/sdk/telemetry/spans/filtering.mdx

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,74 @@ Any APIs exposed to the user to filter spans MUST adhere to the following design
1919

2020
## Filter with `ignoreSpans`
2121

22-
The `ignoreSpans` option accepts a glob pattern or string.
22+
The `ignoreSpans` option MUST accept a string, RegExp or glob pattern (whichever of the two the platform supports). These values MUST be matched against the span name.
23+
24+
Furthermore, `ignoreSpans` SHOULD accept an Object with patterns matching the span name, or span attributes (see type definitions below).
25+
26+
```ts
27+
type IgnoreSpanNamePattern = string | RegExp | GlobPattern;
28+
29+
// all allowed values for span attributes (unlikely but could differ by platform)
30+
type AttributeValueTypes = string | boolean | number | Array<string> | Array<boolean> | Array<number>;
31+
type EnhancedAttributeValueTypes = AttributeValueTypes | RegExp | GlobPattern;
32+
33+
type IgnoreSpanFilter = {
34+
name: IgnoreSpanNamePattern;
35+
attributes?: Record<string, EnhancedAttributeValueTypes>;
36+
} | {
37+
name?: IgnoreSpanNamePattern;
38+
attributes?: Record<string, EnhancedAttributeValueTypes>;
39+
}
40+
41+
type IgnoreSpans = Array<IgnoreSpanNamePattern | IgnoreSpanFilter>
42+
```
43+
(Note: `GlobPattern` is used as an illustrative type for platforms that support matching glob patterns. It is not a valid TypeScript type.)
44+
45+
Example:
2346
2447
```js
2548
Sentry.init({
2649
ignoreSpans: [
50+
// apply on span name
2751
'GET /about',
2852
'events.signal *',
53+
/api\/\d+/,
54+
// ignore health check GET requests with 200 status code
55+
{
56+
name: /healthz?/,
57+
attributes: {
58+
'http.method': 'GET',
59+
'http.status_code': 200,
60+
}
61+
},
62+
// ignore all GET requests to /api/ with 200 status code
63+
// (i.e. span name doesn't matter)
64+
{
65+
attributes: {
66+
'http.method': /GET \/api\/.*/,
67+
'http.status_code': 200,
68+
}
69+
},
70+
// ignore all spans with name starting with /imprint-
71+
// if glob patterns are supported
72+
{
73+
name: '/imprint-*'
74+
}
2975
]
3076
})
3177
```
78+
(Note: The glob patterns used in the example serve an illustrative purpose. They are not supported in JavaScript.)
79+
80+
### Implementation Requirements
81+
82+
1. The `ignoreSpans` patterns MUST be applied to all spans, including the root or segment span.
83+
- If a pattern matches the root span, the span and all its children MUST be ignored.
84+
- If a pattern matches a child span, the span MUST be ignored but any potential child spans MUST be attempted to be reparented to the parent span of the ignored span.
85+
86+
2. If SDKs accept `IgnoreSpanFilter` objects, attributes MUST be matched by value. This also applies to attributes with array values.
87+
- String attribute values are matched in the same fashion as span names: If a string is provided, the string MUST match (contains), if a `RegExp` or glob pattern is provided, the value MUST match the pattern.
88+
- Any other attribute value type MUST strictly equal the provided value.
89+
3290
3391
## Filter with `integrations`
3492

0 commit comments

Comments
 (0)