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
+48-34Lines changed: 48 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,20 +142,23 @@ Finally, if `setupStep2()` was the thing that failed we would see a metric like:
142
142
143
143
## Adding a "Stack Trace" to your metric
144
144
145
-
### Problem
145
+
When errors are thrown we do not attach the stack trace in telemetry. We only know about the error itself, but
146
+
not the path it took to get there. We sometimes need this stack trace to debug, and only have telemetry to get insight on what happened since we do not have access to logs.
147
+
148
+
### Scenario
146
149
147
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."_
148
151
149
152
```typescript
150
-
functionouterA() {
153
+
functionrunsSuccessfully() {
151
154
thisFailsSometimes(1) // this succeeds
152
155
}
153
156
154
-
functionouterB() {
157
+
functionthisThrows() {
155
158
thisFailsSometimes(0) // this fails
156
159
}
157
160
158
-
functionthisFailsSometimes(num:number) {
161
+
functionfailsDependingOnInput(num:number) {
159
162
returntelemetry.my_Metric.run(() => {
160
163
if (number===0) {
161
164
throwError('Cannot be 0')
@@ -167,31 +170,61 @@ function thisFailsSometimes(num: number) {
167
170
168
171
### Solution
169
172
170
-
Add a value to `function` in the options of a `run()`. This will result in a stack of functions identifiers that were previously called
171
-
before `thisFailsSometimes()` was run. You can then retrieve the stack in the `run()` of your final metric using `getFunctionStack()`.
173
+
On class methods, use the `@withTelemetryContext()` decorator to 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
204
+
before `failsDependingOnInput()` was run. You can then retrieve the stack in the `run()` of your final metric using `getFunctionStack()`.
// Results in a metric: { theCallStack: 'outerB:thisFailsSometimes', result: 'Failed' }
193
-
// { theCallStack: 'outerB:thisFailsSometimes' } implies 'outerB' was run first, then 'thisFailsSometimes'. See docstrings for more info.
194
-
outerB()
225
+
// Results in a metric: { theCallStack: 'thisThrows:failsDependingOnInput', result: 'Failed' }
226
+
// { theCallStack: 'thisThrows:failsDependingOnInput' } implies 'thisThrows' was run first, then 'failsDependingOnInput'. See docstrings for more info.
227
+
thisThrows()
195
228
```
196
229
197
230
### Important Notes
@@ -216,25 +249,6 @@ outerB()
216
249
c() // result: 'a:c', note that 'b' is not included
0 commit comments