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: website_docs/exporters.md
+43-2Lines changed: 43 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,15 @@ title: "Exporters"
3
3
weight: 3
4
4
---
5
5
6
-
In order to visualize and analyze your traces, you will need to export them to a tracing backend such as Jaeger or Zipkin.
7
-
OpenTelemetry JS provides exporters for some common open source tracing backends.
6
+
In order to visualize and analyze your traces and metrics, you will need to export them to a backend such as [Jaeger](https://www.jaegertracing.io/) or [Zipkin](https://zipkin.io/). OpenTelemetry JS provides exporters for some common open source backends.
8
7
9
8
Below you will find some introductions on how to setup backends and the matching exporters.
@@ -220,3 +226,119 @@ Now, when you open <http://localhost:8080> in your web browser, you should see t
220
226
```
221
227
222
228
</details>
229
+
230
+
## Metrics
231
+
232
+
### Dependencies
233
+
234
+
The following dependencies are required to collect metrics in your Node.js application.
235
+
236
+
#### Core Dependencies
237
+
238
+
These dependencies are required to configure the tracing SDK and create spans.
239
+
240
+
- `@opentelemetry/metrics`
241
+
242
+
#### Exporter
243
+
244
+
In the following example, we will use the `ConsoleMetricExporter` which prints all spans to the console.
245
+
246
+
In order to visualize and analyze your metrics, you will need to export them to a metrics backend.
247
+
Follow [these instructions](../exporters.md) for setting up a backend and exporter.
248
+
249
+
### Setup
250
+
251
+
You need a `Meter` to create and monitor metrics. A `Meter` in OpenTelemetry is the mechanism used to create and manage metrics, labels, and metric exporters.
252
+
253
+
Create a file named `monitoring.js` and add the following code:
Now you can require this file from your application code and use the `Meter` to create and manage metrics. The simplest of these metrics is a counter.
268
+
269
+
Let's create and export from your `monitoring.js` file a middleware function that express can use to count all requests by route. Modify the `monitoring.js` file so it looks like this:
Now when you make requests to your service, your meter will count all requests.
314
+
315
+
**Note**: Creating a new labelSet and binding on every request is not ideal because creating the labelSet can often be an expensive operation. Therefore, the instruments are created and stored in a Map according to the route key.
316
+
317
+
### Run Application
318
+
319
+
First, install the dependencies as described above. Here you need to add the following:
320
+
321
+
```shell
322
+
npm install --save @opentelemetry/metrics
323
+
```
324
+
325
+
Now you can run your application:
326
+
327
+
```shell
328
+
$ node app.js
329
+
Listening for requests on http://localhost:8080
330
+
```
331
+
332
+
Now, when you open <http://localhost:8080> in your web browser, you should see the metrics printed in the console by the `ConsoleMetricExporter`.
Copy file name to clipboardExpand all lines: website_docs/instrumentation.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,14 @@ weight: 3
5
5
6
6
This guide will cover creating and annotating spans, creating and annotating metrics, how to pass context, and a guide to automatic instrumentation for JavaScript. This simple example works in the browser as well as with Node.JS
7
7
8
+
-[Example Application](#example-application)
9
+
-[Creating Spans](#creating-spans)
10
+
-[Attributes](#attributes)
11
+
-[Semantic Attributes](#semantic-attributes)
12
+
-[Span Status](#span-status)
13
+
14
+
## Example Application
15
+
8
16
In the following this guide will use the following sample app:
9
17
10
18
```javascript
@@ -161,3 +169,30 @@ function doWork(parent) {
161
169
span.end();
162
170
}
163
171
```
172
+
173
+
## Span Status
174
+
175
+
A status can be set on a span, to indicate if the traced operation has completed successfully (`Ok`) or with an `Error`. The default status is `Unset`.
176
+
177
+
The status can be set at any time before the span is finished:
178
+
179
+
```javascript
180
+
functiondoWork(parent) {
181
+
constspan=tracer.startSpan('doWork', {
182
+
parent,
183
+
});
184
+
span.setStatus({
185
+
code:opentelemetry.SpanStatusCode.OK,
186
+
message:'Ok.'
187
+
})
188
+
for (let i =0; i <=Math.floor(Math.random() *40000000); i +=1) {
0 commit comments