Skip to content

Commit

Permalink
chore: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Feb 8, 2024
1 parent d10c047 commit 550fe0c
Show file tree
Hide file tree
Showing 10 changed files with 1,207 additions and 413 deletions.
2 changes: 2 additions & 0 deletions example/otlp-logs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
node main.js
129 changes: 65 additions & 64 deletions example/otlp-logs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/otlp-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@opentelemetry/exporter-logs-otlp-http": "^0.45.0",
"@opentelemetry/sdk-logs": "^0.45.0"
"@opentelemetry/exporter-logs-otlp-http": "0.48.0",
"@opentelemetry/sdk-logs": "0.48.0"
}
}
2 changes: 2 additions & 0 deletions example/otlp-metrics/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
node main.js
19 changes: 19 additions & 0 deletions example/otlp-metrics/README.md
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
```
49 changes: 49 additions & 0 deletions example/otlp-metrics/main.js
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)
Loading

0 comments on commit 550fe0c

Please sign in to comment.