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
Copy file name to clipboardExpand all lines: docs/telemetry.md
+35-36Lines changed: 35 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -150,15 +150,15 @@ not the path it took to get there. We sometimes need this stack trace to debug,
150
150
Common example: _"I have a function, `thisFailsSometimes()` that is called in multiple places. The function sometimes fails, I know from telemetry, but I do not know if it is failing when it is a specific caller. If I knew the call stack/trace that it took to call my function that would help me debug."_
151
151
152
152
```typescript
153
-
functionouterA() {
153
+
functionrunsSuccessfully() {
154
154
thisFailsSometimes(1) // this succeeds
155
155
}
156
156
157
-
functionouterB() {
157
+
functionthisThrows() {
158
158
thisFailsSometimes(0) // this fails
159
159
}
160
160
161
-
functionthisFailsSometimes(num:number) {
161
+
functionfailsDependingOnInput(num:number) {
162
162
returntelemetry.my_Metric.run(() => {
163
163
if (number===0) {
164
164
throwError('Cannot be 0')
@@ -170,7 +170,37 @@ function thisFailsSometimes(num: number) {
170
170
171
171
### Solution
172
172
173
-
Add a value to `function` in the options of a `run()`. This will result in a stack of functions identifiers that were previously called
173
+
On class methods use the `@withTelemetryContext()` decorator add context to the execution. Depending on the args set, it provides features like emitting the result, or adding it's context to errors.
174
+
175
+
> NOTE: Decorators are currently only supported for methods and not functions
// Results in a metric: { source: 'MyClass#thisThrows,failsDependingOnInput', result: 'Failed' }
199
+
// Results in an error that has context about the methods that lead up to it.
200
+
newMyClass().thisThrows()
201
+
```
202
+
203
+
Separately if you must use a function, add a value to `function` in the options of a `run()`. This will result in a stack of functions identifiers that were previously called
174
204
before `failsDependingOnInput()` was run. You can then retrieve the stack in the `run()` of your final metric using `getFunctionStack()`.
175
205
176
206
```typescript
@@ -197,40 +227,9 @@ function failsDependingOnInput(num: number) {
197
227
thisThrows()
198
228
```
199
229
200
-
Additionally the `@withTelemetryContext()` decorator can be added to methods to do the same as above, but with a cleaner syntax.
// Results in a metric: { theCallStack: 'MyClass#thisThrows,failsDependingOnInput', result: 'Failed' }
228
-
newMyClass().thisThrows()
229
-
```
230
-
231
230
### Important Notes
232
231
233
-
-Using `@withTelemetryContext`+ setting `errorCtx` will wrap errors with the functionId properties
232
+
-You can avoid redundancy when repeating fields like `class` in `@withTelemetryContext`by using `withTelemetryContextFactory()`. It builds a new decorator with pre-defined values that you choose.
234
233
235
234
- If a nested function does not use a `run()` then it will not be part of the call stack.
0 commit comments