Skip to content

Commit a2daf60

Browse files
authored
docs(telemetry): Add documentation about traceId (#5639)
## Problem No documentation about traceIds ## Solution Add documentation about traceIds
1 parent 24840fd commit a2daf60

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

docs/telemetry.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,36 @@ outerB()
260260
return telemetry.my_Metric.run(() => b(), { functionId: { name: 'aButMoreUnique' } })
261261
}
262262
```
263+
264+
## Tracing Telemetry Events
265+
266+
All telemetry events include a traceId in addition to other attributes. Traceids allow for improved tracking and correlation of related events across a single operation or user flow.
267+
268+
### What is a traceId?
269+
270+
A traceId is a unique identifier that is generated for the top-level telemetry event in a flow and then propagated to all subsequent related events. This allows us to group and analyze all events associated with a particular operation.
271+
272+
### How it works
273+
274+
1. When a top-level telemetry event is created (e.g., `vscode_executeCommand`), a new traceId is generated.
275+
2. This traceId is then attached to all subsequent related telemetry events that occur as part of the same operation or flow.
276+
3. The traceId remains consistent for all events within the same flow
277+
278+
### Example
279+
280+
Consider a flow where `vscode_executeCommand` triggers `amazonq_enterFocusChat` and `amazonq_openChat`. The resulting telemetry events would look like this:
281+
282+
```
283+
vscode_executeCommand:
284+
traceId: 'aaaaa-aaaaa-aaaaa-aaaaa-aaaaa'
285+
286+
amazonq_enterFocusChat
287+
traceId: 'aaaaa-aaaaa-aaaaa-aaaaa-aaaaa'
288+
289+
amazonq_openChat
290+
traceId: 'aaaaa-aaaaa-aaaaa-aaaaa-aaaaa'
291+
```
292+
293+
allowing us to look up `traceId=aaaaa-aaaaa-aaaaa-aaaaa-aaaaa` in our telemetry instance and find all the related events.
294+
295+
For more information visit the OpenTelemetry documentation on traces: https://opentelemetry.io/docs/concepts/signals/traces/

packages/core/src/shared/telemetry/spans.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ export class TelemetryTracer extends TelemetryBase {
343343
*
344344
* All changes made to {@link attributes} (via {@link record}) during the execution are
345345
* reverted after the execution completes.
346+
*
347+
* This method automatically handles traceId generation and propagation:
348+
* - If no traceId exists in the current context, a new one is generated.
349+
* - The traceId is attached to all telemetry events created within this span.
350+
* - Child spans created within this execution will inherit the same traceId.
351+
* - Related concepts: https://opentelemetry.io/docs/concepts/signals/traces/
352+
*
353+
* See docs/telemetry.md
346354
*/
347355
public run<T, U extends MetricName>(name: U, fn: (span: Metric<MetricShapes[U]>) => T, options?: SpanOptions): T {
348356
const initTraceId = (callback: () => T): T => {

0 commit comments

Comments
 (0)