Skip to content

chore: update & fix otel example #3466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 97 additions & 32 deletions example/otel/README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,124 @@
# Example for go-redis OpenTelemetry instrumentation
# go-redis OpenTelemetry Monitoring with Uptrace

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

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

**Step 1**. Download the example using Git:
This integration provides:

```shell
- **Distributed tracing** for Redis operations
- **Performance monitoring** with latency and throughput metrics
- **Error tracking** and debugging capabilities
- **Visual dashboards** for Redis health monitoring
- **Production-ready** observability stack with Docker

## Prerequisites

- Go 1.19+
- Docker and Docker Compose
- Basic understanding of Redis and OpenTelemetry

## Quick Start

### 1. Clone and Navigate

```bash
git clone https://github.com/redis/go-redis.git
cd example/otel
```

**Step 2**. Start the services using Docker:
### 2. Start the Monitoring Stack

Launch Redis and Uptrace services:

```shell
docker-compose up -d
```bash
docker compose up -d
```

**Step 3**. Make sure Uptrace is running:
This starts:

- Redis server on `localhost:6379`
- Uptrace APM on `http://localhost:14318`

```shell
docker-compose logs uptrace
### 3. Verify Services

Check that Uptrace is running properly:

```bash
docker compose logs uptrace
```

**Step 4**. Run the Redis client example and Follow the link to view the trace:
Look for successful startup messages without errors.

### 4. Run the Example

Execute the instrumented Redis client:

```shell
```bash
go run client.go
```

You should see output similar to:

```
trace: http://localhost:14318/traces/ee029d8782242c8ed38b16d961093b35
```

![Redis trace](./image/redis-trace.png)
Click the trace URL to view detailed operation traces in Uptrace.

![Redis trace visualization](./image/redis-trace.png)

### 5. Explore the Dashboard

Open the Uptrace UI at [http://localhost:14318](http://localhost:14318/metrics/1) to explore:

- **Traces**: Individual Redis operation details
- **Metrics**: Performance statistics and trends
- **Logs**: Application and system logs
- **Service Map**: Visual representation of dependencies

## Advanced Monitoring Setup

### Redis Performance Metrics

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

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

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

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

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

![Redis dashboard](./image/metrics.png)
### Key Metrics Monitored

- **Connection Statistics**: Active connections, connection pool utilization
- **Command Performance**: Operation latency, throughput, error rates
- **Memory Usage**: Memory consumption, key distribution
- **Replication Health**: Master-slave sync status and lag

### Logs and Debugging

View service logs:

```bash
# All services
docker compose logs

# Specific service
docker compose logs redis
docker compose logs uptrace
```

## Links
## Additional Resources

- [Uptrace open-source APM](https://uptrace.dev/get/open-source-apm.html)
- [OpenTelemetry Go instrumentations](https://uptrace.dev/opentelemetry/instrumentations/?lang=go)
- [OpenTelemetry Go Tracing API](https://uptrace.dev/opentelemetry/go-tracing.html)
- [Complete go-redis Monitoring Guide](https://redis.uptrace.dev/guide/go-redis-monitoring.html)
- [OpenTelemetry Go Instrumentation](https://uptrace.dev/get/opentelemetry-go/tracing)
- [Uptrace Open Source APM](https://uptrace.dev/get/hosted/open-source-apm)
5 changes: 3 additions & 2 deletions example/otel/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"sync"
"time"

"github.com/uptrace/uptrace-go/uptrace"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/codes"

"github.com/uptrace/uptrace-go/uptrace"

"github.com/redis/go-redis/extra/redisotel/v9"
"github.com/redis/go-redis/v9"
)
Expand All @@ -22,7 +23,7 @@ func main() {

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

uptrace.WithServiceName("myservice"),
uptrace.WithServiceVersion("v1.0.0"),
Expand Down
20 changes: 13 additions & 7 deletions example/otel/config/otel-collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ receivers:
redis:
endpoint: 'redis-server:6379'
collection_interval: 10s
jaeger:
protocols:
grpc:
postgresql:
endpoint: postgres:5432
transport: tcp
username: uptrace
password: uptrace
databases:
- uptrace
tls:
insecure: true

processors:
resourcedetection:
Expand All @@ -37,10 +43,10 @@ processors:

exporters:
otlp/uptrace:
endpoint: http://uptrace:14317
endpoint: http://uptrace:4317
tls:
insecure: true
headers: { 'uptrace-dsn': 'http://project2_secret_token@localhost:14317/2' }
headers: { 'uptrace-dsn': 'http://project1_secret@localhost:14318/2?grpc=14317' }
debug:

service:
Expand All @@ -49,15 +55,15 @@ service:
# level: DEBUG
pipelines:
traces:
receivers: [otlp, jaeger]
receivers: [otlp]
processors: [batch]
exporters: [otlp/uptrace]
metrics:
receivers: [otlp]
processors: [cumulativetodelta, batch]
exporters: [otlp/uptrace]
metrics/hostmetrics:
receivers: [hostmetrics, redis]
receivers: [hostmetrics, redis, postgresql]
processors: [cumulativetodelta, batch, resourcedetection]
exporters: [otlp/uptrace]
logs:
Expand Down
43 changes: 26 additions & 17 deletions example/otel/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
version: '3'

services:
clickhouse:
image: clickhouse/clickhouse-server:23.7
image: clickhouse/clickhouse-server:25.3.5
restart: on-failure
environment:
CLICKHOUSE_USER: uptrace
CLICKHOUSE_PASSWORD: uptrace
CLICKHOUSE_DB: uptrace
healthcheck:
test: ['CMD', 'wget', '--spider', '-q', 'localhost:8123/ping']
interval: 1s
timeout: 1s
retries: 30
volumes:
- ch_data2:/var/lib/clickhouse
- ch_data:/var/lib/clickhouse
ports:
- '8123:8123'
- '9000:9000'

postgres:
image: postgres:15-alpine
image: postgres:17-alpine
restart: on-failure
environment:
PGDATA: /var/lib/postgresql/data/pgdata
Expand All @@ -31,27 +31,27 @@ services:
timeout: 1s
retries: 30
volumes:
- 'pg_data2:/var/lib/postgresql/data/pgdata'
- 'pg_data:/var/lib/postgresql/data/pgdata'
ports:
- '5432:5432'

uptrace:
image: 'uptrace/uptrace:1.6.2'
image: 'uptrace/uptrace:2.0.0'
#image: 'uptrace/uptrace-dev:latest'
restart: on-failure
volumes:
- ./uptrace.yml:/etc/uptrace/uptrace.yml
- ./uptrace.yml:/etc/uptrace/config.yml
#environment:
# - DEBUG=2
ports:
- '14317:14317'
- '14318:14318'
- '14317:4317'
- '14318:80'
depends_on:
clickhouse:
condition: service_healthy

otelcol:
image: otel/opentelemetry-collector-contrib:0.91.0
image: otel/opentelemetry-collector-contrib:0.123.0
restart: on-failure
volumes:
- ./config/otel-collector.yaml:/etc/otelcol-contrib/config.yaml
Expand All @@ -64,11 +64,19 @@ services:
volumes:
- ./config/vector.toml:/etc/vector/vector.toml:ro

mailhog:
image: mailhog/mailhog:v1.0.1
restart: on-failure
mailpit:
image: axllent/mailpit
restart: always
ports:
- '8025:8025'
- 1025:1025
- 8025:8025
environment:
MP_MAX_MESSAGES: 5000
MP_DATA_FILE: /data/mailpit.db
MP_SMTP_AUTH_ACCEPT_ANY: 1
MP_SMTP_AUTH_ALLOW_INSECURE: 1
volumes:
- mailpit_data:/data

redis-server:
image: redis
Expand All @@ -78,5 +86,6 @@ services:
image: redis

volumes:
ch_data2:
pg_data2:
ch_data:
pg_data:
mailpit_data:
Binary file modified example/otel/image/metrics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified example/otel/image/redis-trace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading