@nestjs/observe 0.1.10 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/interfaces/observe-options.interface.d.ts +44 -0
- package/dist/observe.module.js +10 -1
- package/dist/services/collapse-repeated-spans.util.d.ts +76 -0
- package/dist/services/collapse-repeated-spans.util.js +216 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/operation-trace.registry.d.ts +14 -0
- package/dist/services/operation-trace.registry.js +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -113,6 +113,58 @@ export class ObserveConfig implements ObserveOptionsFactory {
|
|
|
113
113
|
}
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
+
## Repeated spans
|
|
117
|
+
|
|
118
|
+
Every provider is instrumented by default, framework-owned ones included, and
|
|
119
|
+
some of them run in loops the application never wrote. A `ValidationPipe`
|
|
120
|
+
registered through `APP_PIPE` runs once per argument of every GraphQL field
|
|
121
|
+
resolver, so a single list query produces hundreds or thousands of identical
|
|
122
|
+
sibling spans under the operation - each of them a metered event, and together
|
|
123
|
+
saying nothing a count would not.
|
|
124
|
+
|
|
125
|
+
The agent collapses those before a trace leaves the process. When more than
|
|
126
|
+
`threshold` siblings under one parent share a class and method:
|
|
127
|
+
|
|
128
|
+
- the slowest `keepSlowest` of them stay as ordinary spans,
|
|
129
|
+
- any instance that errored stays as an ordinary span, whatever its duration,
|
|
130
|
+
- the rest are replaced by one node that carries how many calls it stands for
|
|
131
|
+
and the **sum** of their durations.
|
|
132
|
+
|
|
133
|
+
Nothing is skipped outright and no duration cut-off is involved: what
|
|
134
|
+
validation costs is specific to each application, and the calls that explain a
|
|
135
|
+
slow request are exactly the ones kept whole. The collapsed node is metered as
|
|
136
|
+
a single event.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
ObserveModule.forRoot({
|
|
140
|
+
// ...
|
|
141
|
+
spanCollapse: { threshold: 20, keepSlowest: 3 }, // the defaults
|
|
142
|
+
// spanCollapse: false, // ship every span
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
What a collapsed node means:
|
|
147
|
+
|
|
148
|
+
- Its `observe.collapsed` tag is the number of calls it replaces, and its name
|
|
149
|
+
reads `ValidationPipe.transform ×27` so a waterfall shows an aggregate rather
|
|
150
|
+
than one more call.
|
|
151
|
+
- `duration` is the sum of the replaced calls' durations, not the wall-clock
|
|
152
|
+
span between the first and the last. That is what keeps the parent's self
|
|
153
|
+
time - its duration minus its children's - exactly what it was.
|
|
154
|
+
- `startOffset` is the earliest replaced call's, and the node sits where that
|
|
155
|
+
call sat among its siblings. Ordering _among_ the replaced calls is lost,
|
|
156
|
+
which is acceptable for calls that are identical by construction.
|
|
157
|
+
- The replaced calls' own children are carried onto the node, so the time of
|
|
158
|
+
whatever they called is still attributed to the class that spent it; a
|
|
159
|
+
repeated frame beneath them collapses in turn.
|
|
160
|
+
- Tags of the replaced calls are dropped. Manual spans are never collapsed.
|
|
161
|
+
|
|
162
|
+
The wire format is unchanged: the count travels inside `t` (tags), next to `n`
|
|
163
|
+
name, `o` origin, `d` duration, `e` error, `c` className, `m` methodKey, `ch`
|
|
164
|
+
children, `s` spanId and `so` startOffset. A collector that does not know the
|
|
165
|
+
tag stores it like any other and attributes the node as one call of its class
|
|
166
|
+
rather than as the number it carries.
|
|
167
|
+
|
|
116
168
|
## Optional peer dependencies
|
|
117
169
|
|
|
118
170
|
Protocol integrations are only loaded when you use them, and their packages are optional peers:
|