-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rueidis): add auto instrumentation for github.com/redis/rueidis.
- Loading branch information
1 parent
e6f3f3c
commit 3d25b75
Showing
21 changed files
with
2,659 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM golang:1.23.4@sha256:7ea4c9dcb2b97ff8ee80a67db3d44f98c8ffa0d191399197007d8459c1453041 | ||
WORKDIR /app | ||
COPY ./*.go . | ||
RUN go mod init main | ||
RUN go mod tidy | ||
RUN go build -o main | ||
ENTRYPOINT ["/app/main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Example of Auto instrumentation of HTTP server | ||
|
||
Server exposes an endpoint `/do.` When we hit the endpoint, it sets a random value for `test_key` in redis and then | ||
retrieves it using rueidis client. | ||
|
||
For testing auto instrumentation, we can use the docker compose. | ||
|
||
To run the example, bring up the services using the command. | ||
|
||
``` | ||
docker compose up --build | ||
``` | ||
|
||
Now, you can hit roll dice server using the below command | ||
``` | ||
curl localhost:8081/do | ||
``` | ||
Every hit to the server should generate a trace that we can observe in [Jaeger UI](http://localhost:16686/) | ||
|
||
Example trace ![Image](jaeger.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
networks: | ||
default: | ||
name: rueidis | ||
driver: bridge | ||
|
||
services: | ||
redis: | ||
image: redis:7.2 | ||
|
||
app: | ||
depends_on: | ||
- jaeger | ||
- redis | ||
build: | ||
context: . | ||
dockerfile: ./Dockerfile | ||
pid: "host" | ||
ports: | ||
- "8081:8081" | ||
volumes: | ||
- /proc:/host/proc | ||
|
||
go-auto: | ||
depends_on: | ||
- app | ||
build: | ||
context: ../.. | ||
dockerfile: Dockerfile | ||
privileged: true | ||
pid: "host" | ||
environment: | ||
- OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318 | ||
- OTEL_GO_AUTO_TARGET_EXE=/app/main | ||
- OTEL_SERVICE_NAME=rueidis-app | ||
- OTEL_PROPAGATORS=tracecontext,baggage | ||
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 | ||
- JAEGER_DISABLED=true | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 300M | ||
restart: unless-stopped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module go.opentelemetry.io/auto/examples/rueidis | ||
|
||
go 1.20 | ||
|
||
require github.com/redis/rueidis v1.0.40 | ||
|
||
require golang.org/x/sys v0.19.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo= | ||
github.com/redis/rueidis v1.0.40 h1:zoC+GUTdNHhP7ZHrnMiIDcP16DUEVcxsPThQsvD7yDg= | ||
github.com/redis/rueidis v1.0.40/go.mod h1:bnbkk4+CkXZgDPEbUtSos/o55i4RhFYYesJ4DS2zmq0= | ||
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= | ||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= | ||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"math/rand" | ||
"net/http" | ||
|
||
"github.com/redis/rueidis" | ||
) | ||
|
||
const testKey = "test_key" | ||
|
||
type server struct { | ||
client rueidis.Client | ||
} | ||
|
||
func (s *server) Do(w http.ResponseWriter, req *http.Request) { | ||
randomValue := fmt.Sprintf("random_value_%d", rand.Intn(1000)) | ||
err := setKey(req.Context(), s.client, testKey, randomValue) | ||
if err != nil { | ||
fmt.Println(fmt.Errorf("failed to set key: %v", err)) | ||
} | ||
fmt.Printf("Set key '%s' with value: %s\n", testKey, randomValue) | ||
|
||
value, err := getKey(req.Context(), s.client, testKey) | ||
if err != nil { | ||
fmt.Println(fmt.Errorf("failed to get key: %v", err)) | ||
} | ||
fmt.Printf("Got value for key '%s': %s\n", testKey, value) | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(200) | ||
_ = json.NewEncoder(w).Encode(map[string]string{"value": value}) | ||
} | ||
|
||
func main() { | ||
address := "redis:6379" | ||
fmt.Println("Connecting to redis server...") | ||
fmt.Println(address) | ||
|
||
client, err := rueidis.NewClient(rueidis.ClientOption{ | ||
InitAddress: []string{address}, | ||
SelectDB: 0, | ||
}) | ||
if err != nil { | ||
log.Fatalf("Failed to create Redis client: %v", err) | ||
} | ||
defer client.Close() | ||
|
||
s := &server{client: client} | ||
|
||
http.HandleFunc("/do", s.Do) | ||
port := ":8081" | ||
fmt.Printf("Server starting on port %s\n", port) | ||
log.Fatal(http.ListenAndServe(port, nil)) | ||
} | ||
|
||
func setKey(ctx context.Context, client rueidis.Client, key, value string) error { | ||
cmd := client.B().Set().Key(key).Value(value).Build() | ||
return client.Do(ctx, cmd).Error() | ||
} | ||
|
||
func getKey(ctx context.Context, client rueidis.Client, key string) (string, error) { | ||
cmd := client.B().Get().Key(key).Build() | ||
result := client.Do(ctx, cmd) | ||
if result.Error() != nil { | ||
return "", result.Error() | ||
} | ||
return result.ToString() | ||
} |
Oops, something went wrong.