Skip to content
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

Add new package instrument: go-redis #1525

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http

### Added

- Support `github.com/go-redis/redis/v8`([#1522](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1525))
- Support `SELECT`, `INSERT`, `UPDATE`, and `DELETE` for database span names and `db.operation.name` attribute. ([#1253](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1253))
- Support `go.opentelemetry.io/[email protected]`. ([#1417](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1417))
- Support `google.golang.org/grpc` `1.69.0`. ([#1417](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1417))
Expand Down
7 changes: 7 additions & 0 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Tracing instrumentation is provided for the following Go libraries.
- [`github.com/segmentio/kafka-go`](#githubcomsegmentiokafka-go)
- [`google.golang.org/grpc`](#googlegolangorggrpc)
- [`net/http`](#nethttp)
- [`github.com/go-redis/redis/v8`](#githubcomgo-redisredisv8)

### database/sql

Expand Down Expand Up @@ -51,3 +52,9 @@ Supported version ranges:
Supported version ranges:

- `go1.12` to `go1.23.4`

### github.com/go-redis/redis/v8

[Package documentation](https://pkg.go.dev/github.com/go-redis/redis/v8)

- `v8.0.0` to `v8.11.5`
7 changes: 7 additions & 0 deletions examples/httpRedis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
WORKDIR /app
COPY ./*.go .
RUN go mod init main
RUN go mod tidy
RUN go build -o main
ENTRYPOINT ["/app/main"]
82 changes: 82 additions & 0 deletions examples/httpRedis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Example of Auto instrumentation of HTTP server + Redis

This example only test [go-redis/v8](https://pkg.go.dev/github.com/go-redis/redis/v8).

**It is highly recommended to deploy the demo using docker compose**.


## Docker compose

Setup the example:

```
docker compose up
```

Add a key-value pair to redis using below command:

```
curl -X POST http://localhost:8080/set -d '{"key":"name", "value":"Alice"}'
```

Every hit to the server should generate a trace that we can observe in [Jaeger UI](http://localhost:16686/).


## Local deployment

### Setup OpenTelemetry Collector and Jaeger

You can setup a local [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector) and start it.

Assuming you've exposed port `4318`, and configured the [Jaeger](http://jaegertracing.io/docs) backend service in collector.


### Setup auto-instrumentation binary

Build the binary

```
make build
```

You will get binary `otel-go-instrumentation` in current directory. Then start instrumenting the target app

```
sudo OTEL_GO_AUTO_TARGET_EXE=</path/to/executable_app> OTEL_SERVICE_NAME=eBPFApp OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 OTEL_GO_AUTO_INCLUDE_DB_STATEMENT=true ./otel-go-instrumentation
```

### Setup and run the demo
Build and run

```
go build -o main

./main
```

Set

```
curl -X POST http://localhost:8080/set -d '{"key":"name", "value":"Alice"}'
```

Get

```
curl -X POST http://localhost:8080/get -d '{"key":"name"}'
```

Sadd

```
curl -X POST http://localhost:8080/sadd -d '{"key":"mySet", "values":["val1", "val2", "val3", "val4"]}'
```

Pipelining mode

```
curl -X POST http://localhost:8080/pipeline -d '{ "commands": [ {"command": "set", "key": "key1", "value": "value1"}, {"command": "get", "key": "key1"}, {"command": "sadd", "key": "mySet", "value": "value1"} ] }'
```


You can observe the trace in [Jaeger UI](http://localhost:16686/).
70 changes: 70 additions & 0 deletions examples/httpRedis/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: "3.9"

networks:
default:
name: http-redis-network
driver: bridge

services:
http-redis:
depends_on:
- jaeger
- redis
build:
context: .
dockerfile: ./Dockerfile
pid: "host"
ports:
- "8080:8080"
volumes:
- /proc:/host/proc
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379

redis:
image: redis:latest
ports:
- "6379:6379"
volumes:
- redis_data:/data
restart: unless-stopped
deploy:
resources:
limits:
memory: 256M

go-auto:
depends_on:
- http-redis
build:
context: ../..
dockerfile: Dockerfile
privileged: true
pid: "host"
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318
- OTEL_GO_AUTO_TARGET_EXE=/app/main
- OTEL_GO_AUTO_INCLUDE_DB_STATEMENT=true
- OTEL_SERVICE_NAME=eBPF-httpRedis
- OTEL_PROPAGATORS=tracecontext,baggage
- CGO_ENABLED=1
volumes:
- /proc:/host/proc

jaeger:
image: jaegertracing/all-in-one:1.60@sha256:4fd2d70fa347d6a47e79fcb06b1c177e6079f92cba88b083153d56263082135e
ports:
- "16686:16686"
- "14268:14268"
environment:
- COLLECTOR_OTLP_ENABLED=true
- LOG_LEVEL=debug
deploy:
resources:
limits:
memory: 300M
restart: unless-stopped

volumes:
redis_data:
10 changes: 10 additions & 0 deletions examples/httpRedis/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module go.opentelemetry.io/auto/examples/httpRedis

go 1.23.1

require github.com/go-redis/redis/v8 v8.11.5

require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
)
24 changes: 24 additions & 0 deletions examples/httpRedis/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
Loading
Loading