Skip to content

Commit

Permalink
Send data to local p8s (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay committed Nov 5, 2023
1 parent d897e9d commit 73c53d7
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 16 deletions.
2 changes: 1 addition & 1 deletion 03-app-instrumentation.md
Expand Up @@ -123,7 +123,7 @@ Now replace the `ConsoleSpanExporter` with an `OTLPTraceExporter` as outlined in
The metrics can be reported to the Prometheus server running locally:
```bash
docker run --rm -it -p 9090:9090 -p 4317:4317 --name=p8s -v ./app/prometheus-docker.yaml:/tmp/prometheus-docker.yaml:z prom/prometheus --config.file=/tmp/prometheus-docker.yaml --enable-feature=otlp-write-receiver
docker run --rm -it -p 9090:9090 --name=p8s -v ./app/prometheus-docker.yaml:/tmp/prometheus-docker.yaml:z prom/prometheus --config.file=/tmp/prometheus-docker.yaml --enable-feature=otlp-write-receiver
```
Alternatively, you can run the OpenTelemetry collector locally with debug exporter:
Expand Down
1 change: 1 addition & 0 deletions app/frontend/index.js
Expand Up @@ -6,6 +6,7 @@ const http = require("http");
const app = require("express")();
const pino = require('pino-http')()

// not included by default
//var otelsdkinit = require('./instrument.js');

app.use(pino)
Expand Down
12 changes: 9 additions & 3 deletions app/frontend/instrument.js
Expand Up @@ -10,7 +10,8 @@
const opentelemetry = require("@opentelemetry/sdk-node");
const { getNodeAutoInstrumentations } = require("@opentelemetry/auto-instrumentations-node");
const { OTLPTraceExporter } = require("@opentelemetry/exporter-trace-otlp-grpc");
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc');
const otlpGrpc = require('@opentelemetry/exporter-metrics-otlp-grpc');
const otlpHttp = require('@opentelemetry/exporter-metrics-otlp-http');

const { PeriodicExportingMetricReader, MeterProvider, ConsoleMetricExporter } = require('@opentelemetry/sdk-metrics')

Expand All @@ -25,8 +26,13 @@ const sdk = new opentelemetry.NodeSDK({
}),
traceExporter: new OTLPTraceExporter(),
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter(),
// exporter: new ConsoleMetricExporter()
// exporter: new ConsoleMetricExporter()
// by default send data to OTLP via gRPC
exporter: new otlpGrpc.OTLPMetricExporter(),
// for sending data to Prometheus
// exporter: new otlpHttp.OTLPMetricExporter({
// url: "http://localhost:9090/api/v1/otlp/v1/metrics", // p8s expose /v1/metrics under /api/v1/otlp
// }),
}),
instrumentations: [getNodeAutoInstrumentations()]
});
Expand Down
262 changes: 253 additions & 9 deletions app/frontend/package-lock.json

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

1 change: 1 addition & 0 deletions app/frontend/package.json
Expand Up @@ -3,6 +3,7 @@
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/auto-instrumentations-node": "^0.39.4",
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.44.0",
"@opentelemetry/exporter-metrics-otlp-http": "^0.43.0",
"@opentelemetry/exporter-prometheus": "^0.44.0",
"@opentelemetry/exporter-trace-otlp-grpc": "^0.44.0",
"@opentelemetry/sdk-metrics": "^1.17.1",
Expand Down
6 changes: 3 additions & 3 deletions app/prometheus-docker.yaml
Expand Up @@ -10,6 +10,6 @@ rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
# - job_name: "prometheus"
# static_configs:
# - targets: ["localhost:9090"]

0 comments on commit 73c53d7

Please sign in to comment.