Skip to content

Commit 28999b9

Browse files
danielbdiasjfermiAdnan Rahić
authored
chore: adding observability stack example (#3578)
* chore: adding observability stack example * adding README * Apply suggestions from code review Co-authored-by: Julianne Fermi <[email protected]> * update example * Apply suggestions from code review Co-authored-by: Adnan Rahić <[email protected]> * update readme * add suggestion --------- Co-authored-by: Julianne Fermi <[email protected]> Co-authored-by: Adnan Rahić <[email protected]>
1 parent 22396d8 commit 28999b9

13 files changed

+3136
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Observability Stack Example
2+
3+
This folder has minimal code to run a local observability stack, plug an API into it, and do some trace-based tests.
4+
5+
To run the observability stack and the local API, execute:
6+
7+
```sh
8+
# run the observability stack
9+
docker compose up -d
10+
11+
# install dependencies and run API
12+
npm install
13+
npm run with-telemetry
14+
```
15+
16+
To run it with trace-based tests, execute:
17+
18+
```sh
19+
# run the observability stack
20+
export TRACETEST_API_KEY="{{Your Tracetest.io Token}}"
21+
docker compose -f ./docker-compose.yaml -f docker-compose.tracetest.yaml up -d
22+
23+
# install dependencies and run API
24+
npm install
25+
npm run with-telemetry
26+
```
27+
28+
And then run a test with:
29+
```sh
30+
tracetest run test -f ./test-api.yaml
31+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const opentelemetry = require('@opentelemetry/sdk-node')
2+
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node')
3+
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc')
4+
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc')
5+
const { PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics')
6+
const grpc = require('@grpc/grpc-js')
7+
8+
const exporterConfig = {
9+
url: 'localhost:4317',
10+
credentials: grpc.ChannelCredentials.createInsecure()
11+
}
12+
13+
const sdk = new opentelemetry.NodeSDK({
14+
metricReader: new PeriodicExportingMetricReader({
15+
exporter: new OTLPMetricExporter(exporterConfig)
16+
}),
17+
traceExporter: new OTLPTraceExporter(exporterConfig),
18+
instrumentations: [getNodeAutoInstrumentations()],
19+
serviceName: 'test-api',
20+
})
21+
sdk.start()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const express = require("express")
2+
const app = express()
3+
4+
app.get("/", (req, res) => {
5+
setTimeout(() => {
6+
res.send("Hello World")
7+
}, 1000);
8+
})
9+
10+
app.listen(8080, () => {
11+
console.log(`Listening for requests on http://localhost:8080`)
12+
})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# config file version
2+
apiVersion: 1
3+
4+
datasources:
5+
- name: Prometheus
6+
type: prometheus
7+
uid: prometheus
8+
access: proxy
9+
orgId: 1
10+
url: http://prometheus:9090
11+
basicAuth: false
12+
isDefault: false
13+
version: 1
14+
editable: false
15+
jsonData:
16+
httpMethod: GET
17+
18+
- name: Tempo
19+
type: tempo
20+
access: proxy
21+
orgId: 1
22+
url: http://tempo:3200
23+
basicAuth: false
24+
isDefault: true
25+
version: 1
26+
editable: false
27+
apiVersion: 1
28+
uid: tempo
29+
jsonData:
30+
httpMethod: GET
31+
serviceMap:
32+
datasourceUid: prometheus
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
http:
6+
cors:
7+
allowed_origins:
8+
- "http://*"
9+
- "https://*"
10+
11+
processors:
12+
batch:
13+
timeout: 100ms
14+
15+
exporters:
16+
debug:
17+
verbosity: detailed
18+
19+
otlp/tempo:
20+
endpoint: tempo:4317
21+
tls:
22+
insecure: true
23+
24+
prometheus:
25+
endpoint: 0.0.0.0:8889
26+
27+
extensions:
28+
health_check: {}
29+
30+
service:
31+
pipelines:
32+
metrics:
33+
receivers: [otlp]
34+
processors: [batch]
35+
exporters: [debug, prometheus]
36+
37+
traces:
38+
receivers: [otlp]
39+
processors: [batch]
40+
exporters: [debug, otlp/tempo]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
global:
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
4+
5+
scrape_configs:
6+
- job_name: otel-collector
7+
static_configs:
8+
- targets: ['otel-collector:8889']
9+
- targets: ['otel-collector:8888']
10+
11+
tracing:
12+
endpoint: otel-collector:4317
13+
insecure: true
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
stream_over_http_enabled: true
2+
3+
server:
4+
http_listen_port: 3200
5+
log_level: info
6+
7+
query_frontend:
8+
search:
9+
duration_slo: 5s
10+
throughput_bytes_slo: 1.073741824e+09
11+
trace_by_id:
12+
duration_slo: 5s
13+
14+
distributor:
15+
receivers:
16+
otlp:
17+
protocols:
18+
http:
19+
endpoint: 0.0.0.0:4318
20+
grpc:
21+
endpoint: 0.0.0.0:4317
22+
23+
ingester:
24+
max_block_duration: 5m # cut the headblock when this much time passes. this is being set for demo purposes and should probably be left alone normally
25+
26+
compactor:
27+
compaction:
28+
block_retention: 1h # overall Tempo trace retention. set for demo purposes
29+
30+
metrics_generator:
31+
registry:
32+
external_labels:
33+
source: tempo
34+
cluster: docker-compose
35+
storage:
36+
path: /tmp/tempo/generator/wal
37+
remote_write:
38+
- url: http://prometheus:9090/api/v1/write
39+
send_exemplars: true
40+
41+
storage:
42+
trace:
43+
backend: local # backend configuration to use
44+
wal:
45+
path: /tmp/tempo/wal # where to store the the wal locally
46+
local:
47+
path: /tmp/tempo/blocks
48+
49+
overrides:
50+
defaults:
51+
metrics_generator:
52+
processors: [service-graphs, span-metrics] # enables metrics generator
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "3.7"
2+
3+
services:
4+
tracetest:
5+
image: kubeshop/tracetest-agent:latest
6+
platform: linux/amd64
7+
depends_on:
8+
otel-collector:
9+
condition: service_started
10+
environment:
11+
TRACETEST_API_KEY: ${TRACETEST_API_KEY}
12+
extra_hosts:
13+
- "host.docker.internal:host-gateway"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
version: "3.7"
2+
3+
services:
4+
grafana:
5+
image: grafana/grafana:10.2.3
6+
user: "472"
7+
depends_on:
8+
- prometheus
9+
- tempo
10+
- otel-collector
11+
ports:
12+
- 33000:33000
13+
environment:
14+
- GF_SERVER_HTTP_PORT=33000
15+
- GF_AUTH_ANONYMOUS_ENABLED=true
16+
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
17+
- GF_AUTH_DISABLE_LOGIN_FORM=true
18+
volumes:
19+
- type: bind
20+
source: ./config/grafana.datasource.yaml
21+
target: /etc/grafana/provisioning/datasources/datasources.yaml
22+
23+
otel-collector:
24+
image: otel/opentelemetry-collector-contrib:0.92.0
25+
command:
26+
- "--config"
27+
- "/otel-local-config.yaml"
28+
volumes:
29+
- ./config/otel-collector.config.yaml:/otel-local-config.yaml
30+
ports:
31+
- 4317:4317
32+
33+
tempo:
34+
image: grafana/tempo:2.3.1
35+
command: ["-config.file=/etc/tempo.yaml"]
36+
volumes:
37+
- type: bind
38+
source: ./config/tempo.config.yaml
39+
target: /etc/tempo.yaml
40+
41+
prometheus:
42+
image: prom/prometheus:v2.49.1
43+
command:
44+
- --config.file=/etc/prometheus.yaml
45+
- --web.enable-remote-write-receiver
46+
- --enable-feature=exemplar-storage
47+
volumes:
48+
- type: bind
49+
source: ./config/prometheus.config.yaml
50+
target: /etc/prometheus.yaml

0 commit comments

Comments
 (0)