Skip to content

Commit 57ec9fa

Browse files
committed
Document custom labels for Node.js
1 parent a544d52 commit 57ec9fa

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

content/en/profiler/guide/isolate-outliers-in-monolithic-services.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ In the previous image, notice that the `ModelTraining` operation is taking more
7878

7979
Endpoint and operation isolation is available in your profiles by default, but you may want to isolate a different piece of logic. For example, if the monolith is sensitive to specific customers, you can add a custom filter to the profiles:
8080

81-
{{< programming-lang-wrapper langs="java,go" >}}
81+
{{< programming-lang-wrapper langs="java,go,nodejs" >}}
8282
{{< programming-lang lang="java">}}
8383

8484

@@ -124,6 +124,29 @@ Then, open CPU or goroutine profiles for your service and select the `customer_n
124124
[1]: https://pkg.go.dev/runtime/pprof#Do
125125
[2]: https://pkg.go.dev/gopkg.in/DataDog/dd-trace-go.v1/profiler#WithCustomProfilerLabelKeys
126126
[3]: https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/profiler#WithCustomProfilerLabelKeys
127+
{{< /programming-lang >}}
128+
{{< programming-lang lang="nodejs">}}
129+
130+
The Node.js profiler supports custom labels for your business logic as of `dd-trace` version 5.97.0. To add labels, use `tracer.profiling.runWithLabels()`:
131+
132+
```javascript
133+
const tracer = require('dd-trace').init()
134+
135+
tracer.profiling.runWithLabels({ customer_name: <value> }, () => {
136+
/* customer-specific logic here */
137+
})
138+
```
139+
140+
All wall time and CPU time samples taken during the function's execution, including across async continuations, carry the custom labels. Nested `runWithLabels` calls merge labels, with inner values taking precedence for duplicate keys.
141+
142+
To specify which label keys you want to use for filtering, call `setCustomLabelKeys()` as a one-time setup before calling `runWithLabels()`:
143+
144+
```javascript
145+
tracer.profiling.setCustomLabelKeys(['customer_name'])
146+
```
147+
148+
Then, open wall time profiles for your service and select the `customer_name` value you're interested in under the `CPU time by` dropdown.
149+
127150
{{< /programming-lang >}}
128151
{{< /programming-lang-wrapper >}}
129152

0 commit comments

Comments
 (0)