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
{{ message }}
This repository was archived by the owner on Jan 21, 2026. It is now read-only.
BREAKING CHANGE: `TraceAgent` has been renamed to `Tracer`. In plugins, `Patch` has been renamed `Monkeypatch`, and `Patch` is now `Monkeypatch|Intercept` (this is a rename of `Instrumentation`). There are no user-visible JS changes.
`TraceAgent` is a misnomer since the module as a whole is the "agent", not the object that is returned when the Trace Agent is started. (This is already reflected in the docs, where it has been called `TraceApi`). This change makes things consistent so it is called `Tracer` everywhere.
The one implementation of `TraceAgent` (which was also called `TraceAgent`) is now `StackdriverTracer`. This object is never constructed by the user, so this is a no-op change for JS users.
A couple of unused imports have also been removed.
Copy file name to clipboardExpand all lines: doc/trace-api.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,41 +1,41 @@
1
-
# The `TraceApi` Object
1
+
# The `Tracer` Object
2
2
3
-
A `TraceApi` instance provides functions that facilitate the following:
3
+
A `Tracer` instance provides functions that facilitate the following:
4
4
5
5
- Creating trace spans and add labels to them.
6
6
- Getting information about how the trace agent was configured in the current application.
7
7
- Parsing and serializing trace contexts to support distributed tracing between microservices.
8
8
- Binding callbacks and event emitters in order to propagate trace contexts across asynchronous boundaries.
9
9
10
-
In addition to the above, `TraceApi` also provides a number of well-known label keys and constants through its `labels` and `constants` fields respectively.
10
+
In addition to the above, `Tracer` also provides a number of well-known label keys and constants through its `labels` and `constants` fields respectively.
11
11
12
12
## Trace Spans
13
13
14
14
These functions provide the capability to create trace spans, add labels to them, and close them.
15
15
16
-
*`TraceApi#runInRootSpan(options, fn)`
16
+
*`Tracer#runInRootSpan(options, fn)`
17
17
*`options`: [`TraceOptions`](#trace-span-options)
18
18
*`fn`: `function(Span): any`
19
19
* Returns `any` (return value of `fn`)
20
20
* Creates a root span and runs the given callback, passing it a `Span` object. In some instances, this `Span` object doesn't correspond to an actual trace span; this can be checked by consulting the value of `Span#type`:
21
-
*`TraceApi#spanTypes.ROOT`: This object corresponds to a real trace span.
22
-
*`TraceApi#spanTypes.UNTRACED`: There isn't a real trace span corresponding to this object, for one of the following reasons:
21
+
*`Tracer#spanTypes.ROOT`: This object corresponds to a real trace span.
22
+
*`Tracer#spanTypes.UNTRACED`: There isn't a real trace span corresponding to this object, for one of the following reasons:
23
23
* The trace policy, as specified by the user-given configuration, disallows a root span from being created under the current circumstances.
24
24
* The trace agent is disabled, either because it wasn't started at all, started in disabled mode, or encountered an initialization error.
25
25
* The incoming request had headers that explicitly specified that this request shouldn't be traced.
26
-
*`TraceApi#spanTypes.UNCORRELATED`: `runInRootSpan` was called for a request that already has a root span. This likely indicates a programmer error, as nested root spans are not allowed.
26
+
*`Tracer#spanTypes.UNCORRELATED`: `runInRootSpan` was called for a request that already has a root span. This likely indicates a programmer error, as nested root spans are not allowed.
27
27
***Note:** You must call `endSpan` on the span object provided as an argument for the span to be recorded.
28
-
*`TraceApi#createChildSpan(options)`
28
+
*`Tracer#createChildSpan(options)`
29
29
*`options`: [`TraceOptions`](#trace-span-options)
30
30
* Returns `Span`
31
31
* Creates a child `Span` object and returns it. In some instances, this `Span` object doesn't correspond to an actual trace span; this can be checked by consulting the value of `Span#type`:
32
-
*`TraceApi#spanTypes.CHILD`: This object corresponds to a real trace span.
33
-
*`TraceApi#spanTypes.UNTRACED`: There isn't a real trace span corresponding to this object, because this span's parent is also an `UNTRACED` (root) span.
34
-
*`TraceApi#spanTypes.UNCORRELATED`: There isn't a real trace span corresponding to this object, for one of the following reasons:
32
+
*`Tracer#spanTypes.CHILD`: This object corresponds to a real trace span.
33
+
*`Tracer#spanTypes.UNTRACED`: There isn't a real trace span corresponding to this object, because this span's parent is also an `UNTRACED` (root) span.
34
+
*`Tracer#spanTypes.UNCORRELATED`: There isn't a real trace span corresponding to this object, for one of the following reasons:
35
35
* A root span wasn't created beforehand because `runInRootSpan` was not called at all. This likely indicates a programmer error, because child spans should always be nested within a root span.
36
36
* A root span was created beforehand, but context was lost between then and now. This may also be a programmer error, because child spans should always be created within the context of a root span. See [`Context Propagation`](#context-propagation) for details on properly propagating root span context.
37
37
***Note:** You must call `endSpan` on the returned span object for the span to be recorded.
38
-
*`TraceApi#spanTypes`
38
+
*`Tracer#spanTypes`
39
39
* An enumeration of the types of spans: `ROOT`, `CHILD`, `UNTRACED`, `UNCORRELATED`
40
40
*`Span#addLabel(key, value)`
41
41
*`key`: `string`
@@ -64,7 +64,7 @@ Some functions above accept a `TraceOptions` object, which has the following fie
64
64
65
65
## Trace Agent Configuration
66
66
67
-
*`TraceApi#enhancedDatabaseReportingEnabled()`
67
+
*`Tracer#enhancedDatabaseReportingEnabled()`
68
68
* Returns `boolean`
69
69
* Returns whether the trace agent was started with an enhanced level of reporting. See the [configuration][config-js] object definition for more details.
70
70
@@ -78,11 +78,11 @@ Trace context is sent and received using the [`'x-cloud-trace-context'`][stackdr
78
78
79
79
Plugins that trace incoming HTTP requests (in other words, web frameworks) should support cross-service tracing by reading serialized trace context from the `'x-cloud-trace-context'` header, and supplying it as the [`traceContext` option](#trace-span-options) when creating a new root span. The trace agent will automatically deserialize the trace context and associate any new spans with it.
80
80
81
-
The string `'x-cloud-trace-context'` is provided as `TraceApi#constants.TRACE_CONTEXT_HEADER_NAME`.
81
+
The string `'x-cloud-trace-context'` is provided as `Tracer#constants.TRACE_CONTEXT_HEADER_NAME`.
82
82
83
83
It is highly recommended for plugins to set this header field in responses, _if_ the incoming request has this header. The trace context that should be written can be obtained with the following function:
0 commit comments