Skip to content

Commit 2c29ded

Browse files
authored
chore(otel): upgrade otel example to Uptrace v2 (#3466)
Uptrace v2 comes with a new config file and new defaults. Also updated dependencies to the latest versions.
1 parent b7838dc commit 2c29ded

File tree

7 files changed

+551
-309
lines changed

7 files changed

+551
-309
lines changed

example/otel/README.md

Lines changed: 97 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,124 @@
1-
# Example for go-redis OpenTelemetry instrumentation
1+
# go-redis OpenTelemetry Monitoring with Uptrace
22

3-
This example demonstrates how to monitor Redis using OpenTelemetry and
4-
[Uptrace](https://github.com/uptrace/uptrace). It requires Docker to start Redis Server and Uptrace.
3+
This example demonstrates how to instrument and monitor Redis operations in Go applications using
4+
OpenTelemetry and [Uptrace](https://github.com/uptrace/uptrace), providing comprehensive
5+
observability into your Redis performance and operations.
56

6-
See
7-
[Monitoring Go Redis Performance and Errors](https://redis.uptrace.dev/guide/go-redis-monitoring.html)
8-
for details.
7+
## Overview
98

10-
**Step 1**. Download the example using Git:
9+
This integration provides:
1110

12-
```shell
11+
- **Distributed tracing** for Redis operations
12+
- **Performance monitoring** with latency and throughput metrics
13+
- **Error tracking** and debugging capabilities
14+
- **Visual dashboards** for Redis health monitoring
15+
- **Production-ready** observability stack with Docker
16+
17+
## Prerequisites
18+
19+
- Go 1.19+
20+
- Docker and Docker Compose
21+
- Basic understanding of Redis and OpenTelemetry
22+
23+
## Quick Start
24+
25+
### 1. Clone and Navigate
26+
27+
```bash
1328
git clone https://github.com/redis/go-redis.git
1429
cd example/otel
1530
```
1631

17-
**Step 2**. Start the services using Docker:
32+
### 2. Start the Monitoring Stack
33+
34+
Launch Redis and Uptrace services:
1835

19-
```shell
20-
docker-compose up -d
36+
```bash
37+
docker compose up -d
2138
```
2239

23-
**Step 3**. Make sure Uptrace is running:
40+
This starts:
41+
42+
- Redis server on `localhost:6379`
43+
- Uptrace APM on `http://localhost:14318`
2444

25-
```shell
26-
docker-compose logs uptrace
45+
### 3. Verify Services
46+
47+
Check that Uptrace is running properly:
48+
49+
```bash
50+
docker compose logs uptrace
2751
```
2852

29-
**Step 4**. Run the Redis client example and Follow the link to view the trace:
53+
Look for successful startup messages without errors.
54+
55+
### 4. Run the Example
56+
57+
Execute the instrumented Redis client:
3058

31-
```shell
59+
```bash
3260
go run client.go
61+
```
62+
63+
You should see output similar to:
64+
65+
```
3366
trace: http://localhost:14318/traces/ee029d8782242c8ed38b16d961093b35
3467
```
3568

36-
![Redis trace](./image/redis-trace.png)
69+
Click the trace URL to view detailed operation traces in Uptrace.
70+
71+
![Redis trace visualization](./image/redis-trace.png)
72+
73+
### 5. Explore the Dashboard
74+
75+
Open the Uptrace UI at [http://localhost:14318](http://localhost:14318/metrics/1) to explore:
76+
77+
- **Traces**: Individual Redis operation details
78+
- **Metrics**: Performance statistics and trends
79+
- **Logs**: Application and system logs
80+
- **Service Map**: Visual representation of dependencies
81+
82+
## Advanced Monitoring Setup
83+
84+
### Redis Performance Metrics
3785

38-
You can also open Uptrace UI at [http://localhost:14318](http://localhost:14318) to view available
39-
spans, logs, and metrics.
86+
For production environments, enable comprehensive Redis monitoring by installing the OpenTelemetry
87+
Collector:
4088

41-
## Redis monitoring
89+
The [OpenTelemetry Collector](https://uptrace.dev/opentelemetry/collector) acts as a telemetry agent
90+
that:
4291

43-
You can also [monitor Redis performance](https://uptrace.dev/opentelemetry/redis-monitoring.html)
44-
metrics By installing OpenTelemetry Collector.
92+
- Pulls performance metrics directly from Redis
93+
- Collects system-level statistics
94+
- Forwards data to Uptrace via OTLP protocol
4595

46-
[OpenTelemetry Collector](https://uptrace.dev/opentelemetry/collector.html) is an agent that pulls
47-
telemetry data from systems you want to monitor and sends it to APM tools using the OpenTelemetry
48-
protocol (OTLP).
96+
When configured, Uptrace automatically generates a Redis dashboard:
4997

50-
When telemetry data reaches Uptrace, it automatically generates a Redis dashboard from a pre-defined
51-
template.
98+
![Redis performance dashboard](./image/metrics.png)
5299

53-
![Redis dashboard](./image/metrics.png)
100+
### Key Metrics Monitored
101+
102+
- **Connection Statistics**: Active connections, connection pool utilization
103+
- **Command Performance**: Operation latency, throughput, error rates
104+
- **Memory Usage**: Memory consumption, key distribution
105+
- **Replication Health**: Master-slave sync status and lag
106+
107+
### Logs and Debugging
108+
109+
View service logs:
110+
111+
```bash
112+
# All services
113+
docker compose logs
114+
115+
# Specific service
116+
docker compose logs redis
117+
docker compose logs uptrace
118+
```
54119

55-
## Links
120+
## Additional Resources
56121

57-
- [Uptrace open-source APM](https://uptrace.dev/get/open-source-apm.html)
58-
- [OpenTelemetry Go instrumentations](https://uptrace.dev/opentelemetry/instrumentations/?lang=go)
59-
- [OpenTelemetry Go Tracing API](https://uptrace.dev/opentelemetry/go-tracing.html)
122+
- [Complete go-redis Monitoring Guide](https://redis.uptrace.dev/guide/go-redis-monitoring.html)
123+
- [OpenTelemetry Go Instrumentation](https://uptrace.dev/get/opentelemetry-go/tracing)
124+
- [Uptrace Open Source APM](https://uptrace.dev/get/hosted/open-source-apm)

example/otel/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
"sync"
88
"time"
99

10-
"github.com/uptrace/uptrace-go/uptrace"
1110
"go.opentelemetry.io/otel"
1211
"go.opentelemetry.io/otel/codes"
1312

13+
"github.com/uptrace/uptrace-go/uptrace"
14+
1415
"github.com/redis/go-redis/extra/redisotel/v9"
1516
"github.com/redis/go-redis/v9"
1617
)
@@ -22,7 +23,7 @@ func main() {
2223

2324
uptrace.ConfigureOpentelemetry(
2425
// copy your project DSN here or use UPTRACE_DSN env var
25-
uptrace.WithDSN("http://project2_secret_token@localhost:14317/2"),
26+
uptrace.WithDSN("http://project1_secret@localhost:14318/2?grpc=14317"),
2627

2728
uptrace.WithServiceName("myservice"),
2829
uptrace.WithServiceVersion("v1.0.0"),

example/otel/config/otel-collector.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ receivers:
2323
redis:
2424
endpoint: 'redis-server:6379'
2525
collection_interval: 10s
26-
jaeger:
27-
protocols:
28-
grpc:
26+
postgresql:
27+
endpoint: postgres:5432
28+
transport: tcp
29+
username: uptrace
30+
password: uptrace
31+
databases:
32+
- uptrace
33+
tls:
34+
insecure: true
2935

3036
processors:
3137
resourcedetection:
@@ -37,10 +43,10 @@ processors:
3743

3844
exporters:
3945
otlp/uptrace:
40-
endpoint: http://uptrace:14317
46+
endpoint: http://uptrace:4317
4147
tls:
4248
insecure: true
43-
headers: { 'uptrace-dsn': 'http://project2_secret_token@localhost:14317/2' }
49+
headers: { 'uptrace-dsn': 'http://project1_secret@localhost:14318/2?grpc=14317' }
4450
debug:
4551

4652
service:
@@ -49,15 +55,15 @@ service:
4955
# level: DEBUG
5056
pipelines:
5157
traces:
52-
receivers: [otlp, jaeger]
58+
receivers: [otlp]
5359
processors: [batch]
5460
exporters: [otlp/uptrace]
5561
metrics:
5662
receivers: [otlp]
5763
processors: [cumulativetodelta, batch]
5864
exporters: [otlp/uptrace]
5965
metrics/hostmetrics:
60-
receivers: [hostmetrics, redis]
66+
receivers: [hostmetrics, redis, postgresql]
6167
processors: [cumulativetodelta, batch, resourcedetection]
6268
exporters: [otlp/uptrace]
6369
logs:

example/otel/docker-compose.yml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
version: '3'
2-
31
services:
42
clickhouse:
5-
image: clickhouse/clickhouse-server:23.7
3+
image: clickhouse/clickhouse-server:25.3.5
64
restart: on-failure
75
environment:
6+
CLICKHOUSE_USER: uptrace
7+
CLICKHOUSE_PASSWORD: uptrace
88
CLICKHOUSE_DB: uptrace
99
healthcheck:
1010
test: ['CMD', 'wget', '--spider', '-q', 'localhost:8123/ping']
1111
interval: 1s
1212
timeout: 1s
1313
retries: 30
1414
volumes:
15-
- ch_data2:/var/lib/clickhouse
15+
- ch_data:/var/lib/clickhouse
1616
ports:
1717
- '8123:8123'
1818
- '9000:9000'
1919

2020
postgres:
21-
image: postgres:15-alpine
21+
image: postgres:17-alpine
2222
restart: on-failure
2323
environment:
2424
PGDATA: /var/lib/postgresql/data/pgdata
@@ -31,27 +31,27 @@ services:
3131
timeout: 1s
3232
retries: 30
3333
volumes:
34-
- 'pg_data2:/var/lib/postgresql/data/pgdata'
34+
- 'pg_data:/var/lib/postgresql/data/pgdata'
3535
ports:
3636
- '5432:5432'
3737

3838
uptrace:
39-
image: 'uptrace/uptrace:1.6.2'
39+
image: 'uptrace/uptrace:2.0.0'
4040
#image: 'uptrace/uptrace-dev:latest'
4141
restart: on-failure
4242
volumes:
43-
- ./uptrace.yml:/etc/uptrace/uptrace.yml
43+
- ./uptrace.yml:/etc/uptrace/config.yml
4444
#environment:
4545
# - DEBUG=2
4646
ports:
47-
- '14317:14317'
48-
- '14318:14318'
47+
- '14317:4317'
48+
- '14318:80'
4949
depends_on:
5050
clickhouse:
5151
condition: service_healthy
5252

5353
otelcol:
54-
image: otel/opentelemetry-collector-contrib:0.91.0
54+
image: otel/opentelemetry-collector-contrib:0.123.0
5555
restart: on-failure
5656
volumes:
5757
- ./config/otel-collector.yaml:/etc/otelcol-contrib/config.yaml
@@ -64,11 +64,19 @@ services:
6464
volumes:
6565
- ./config/vector.toml:/etc/vector/vector.toml:ro
6666

67-
mailhog:
68-
image: mailhog/mailhog:v1.0.1
69-
restart: on-failure
67+
mailpit:
68+
image: axllent/mailpit
69+
restart: always
7070
ports:
71-
- '8025:8025'
71+
- 1025:1025
72+
- 8025:8025
73+
environment:
74+
MP_MAX_MESSAGES: 5000
75+
MP_DATA_FILE: /data/mailpit.db
76+
MP_SMTP_AUTH_ACCEPT_ANY: 1
77+
MP_SMTP_AUTH_ALLOW_INSECURE: 1
78+
volumes:
79+
- mailpit_data:/data
7280

7381
redis-server:
7482
image: redis
@@ -78,5 +86,6 @@ services:
7886
image: redis
7987

8088
volumes:
81-
ch_data2:
82-
pg_data2:
89+
ch_data:
90+
pg_data:
91+
mailpit_data:

example/otel/image/metrics.png

-8.07 KB
Loading

example/otel/image/redis-trace.png

1.37 KB
Loading

0 commit comments

Comments
 (0)