-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d10c047
commit 550fe0c
Showing
10 changed files
with
1,207 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
all: | ||
node main.js |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
all: | ||
node main.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Using OTLP exporter with Uptrace | ||
|
||
This example shows how to configure | ||
[OTLP](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-exporter-collector) | ||
to export metrics to Uptrace. | ||
|
||
Install dependencies: | ||
|
||
```shell | ||
npm install | ||
``` | ||
|
||
To run this example, you need to | ||
[create an Uptrace project](https://uptrace.dev/get/get-started.html) and pass your project DSN via | ||
`UPTRACE_DSN` env variable: | ||
|
||
```go | ||
UPTRACE_DSN=https://<token>@api.uptrace.dev/<project_id> node main.js | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict' | ||
|
||
const otel = require('@opentelemetry/api') | ||
const { Resource } = require('@opentelemetry/resources') | ||
const { NodeSDK } = require('@opentelemetry/sdk-node') | ||
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-http') | ||
const { | ||
PeriodicExportingMetricReader, | ||
AggregationTemporality, | ||
} = require('@opentelemetry/sdk-metrics') | ||
|
||
const dsn = process.env.UPTRACE_DSN | ||
console.log('using dsn:', dsn) | ||
|
||
const exporter = new OTLPMetricExporter({ | ||
url: 'https://otlp.uptrace.dev/v1/metrics', | ||
headers: { 'uptrace-dsn': dsn }, | ||
compression: 'gzip', | ||
}) | ||
const metricReader = new PeriodicExportingMetricReader({ | ||
exporter: exporter, | ||
exportIntervalMillis: 15000, | ||
}) | ||
|
||
const sdk = new NodeSDK({ | ||
metricReader: metricReader, | ||
resource: new Resource({ | ||
'service.name': 'myservice', | ||
'service.version': '1.0.0', | ||
}), | ||
}) | ||
sdk.start() | ||
|
||
const meter = otel.metrics.getMeter('app_or_package_name', '1.0.0') | ||
|
||
const requestCounter = meter.createCounter('requests', { | ||
description: 'Example of a Counter', | ||
}) | ||
|
||
const upDownCounter = meter.createUpDownCounter('test_up_down_counter', { | ||
description: 'Example of a UpDownCounter', | ||
}) | ||
|
||
const attributes = { environment: 'staging' } | ||
|
||
setInterval(() => { | ||
requestCounter.add(1, attributes) | ||
upDownCounter.add(Math.random() > 0.5 ? 1 : -1, attributes) | ||
}, 1000) |
Oops, something went wrong.