Skip to content
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
9 changes: 8 additions & 1 deletion go/gin-dynamodb-valkey/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gin + DynamoDB + Valkey

Go/Gin service instrumented with the Last9 Go Agent — emits distributed traces for Amazon DynamoDB (via `otelaws`) and Valkey (via `valkeyotel`).
Go/Gin service instrumented with the Last9 Go Agent — emits distributed traces for Amazon DynamoDB (via `otelaws`), Valkey (via `valkeyotel`), SQS long-poll workers, and outbound HTTP (via `httpagent`). Demonstrates `context.Context` propagation end-to-end so spans link into one tree per request.

## Prerequisites

Expand Down Expand Up @@ -49,8 +49,13 @@ Go/Gin service instrumented with the Last9 Go Agent — emits distributed traces
curl -XPOST "http://localhost:8080/cache/hello?value=world"
curl http://localhost:8080/cache/hello
curl http://localhost:8080/users/u1
curl http://localhost:8080/external
```

## Context propagation

`main.go` threads `context.Context` from each gin handler through `Service` methods to every SDK call (DynamoDB, Valkey, SQS, outbound HTTP). This is what makes spans nest into a single trace per request. See the [Go Gin integration guide](https://last9.io/docs/integrations/golang-gin) for the full pattern + anti-patterns.

## Configuration

Replace every `<placeholder>` with your own values. `local`-only fields (marked with *) are for the docker-compose flow and should be removed in production.
Expand All @@ -66,6 +71,7 @@ Replace every `<placeholder>` with your own values. `local`-only fields (marked
| `AWS_ENDPOINT_URL`* | `http://localhost:8000` | DynamoDB-local only. **Omit in production.** |
| `AWS_ACCESS_KEY_ID`* / `AWS_SECRET_ACCESS_KEY`* | `local` / `local` | DynamoDB-local only. Use IAM role / instance profile in production. |
| `DYNAMODB_TABLE` | `<your-table-name>` | Defaults to `users` if unset |
| `SQS_QUEUE_URL` | `<your-sqs-queue-url>` | Optional. When set, starts the SQS long-poll worker. |
| `VALKEY_ADDR` | `<host:port>` or `<host1:port,host2:port>` | Comma-separated for cluster / sentinel |
| `VALKEY_TLS` | `true` \| `false` | Set `true` for managed Valkey with encryption in transit |
| `VALKEY_USERNAME` | `<acl-username>` or empty | Managed Valkey with ACL (e.g. MemoryDB, Upstash) |
Expand Down Expand Up @@ -170,6 +176,7 @@ WantedBy=multi-user.target

| Symptom | Cause |
|---|---|
| Spans not linked into one trace (orphan single-span traces) | See [span-linking troubleshooting in the product doc](https://last9.io/docs/integrations/golang-gin) — covers ctx propagation, outbound HTTP, SQS poller. |
| DynamoDB span missing `aws.dynamodb.table_names` | `WithAttributeSetter(DynamoDBAttributeSetter)` not passed to `AppendMiddlewares` |
| Valkey span missing or orphaned | Handler didn't pass `c.Request.Context()` into `valkeyClient.Do(...)` |
| No traces in Last9 | `OTEL_EXPORTER_OTLP_ENDPOINT` / `OTEL_EXPORTER_OTLP_HEADERS` not set before `agent.Start()` |
Expand Down
9 changes: 6 additions & 3 deletions go/gin-dynamodb-valkey/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ require (
github.com/aws/aws-sdk-go-v2 v1.32.6
github.com/aws/aws-sdk-go-v2/config v1.28.6
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.38.0
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.0
github.com/gin-gonic/gin v1.10.0
github.com/last9/go-agent v0.1.0
github.com/valkey-io/valkey-go v1.0.55
github.com/valkey-io/valkey-go/valkeyotel v1.0.55
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0
go.opentelemetry.io/otel v1.34.0
go.opentelemetry.io/otel/trace v1.34.0
)

require (
Expand All @@ -24,7 +27,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.6 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.24.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 // indirect
Expand All @@ -34,6 +36,7 @@ require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand All @@ -56,15 +59,15 @@ require (
github.com/ugorji/go/codec v1.2.12 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.52.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.52.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
go.opentelemetry.io/contrib/instrumentation/runtime v0.50.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.33.0 // indirect
Expand Down
15 changes: 0 additions & 15 deletions go/gin-dynamodb-valkey/go.mod.new

This file was deleted.

6 changes: 6 additions & 0 deletions go/gin-dynamodb-valkey/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQ
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
Expand Down Expand Up @@ -131,6 +133,10 @@ go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0/go.mod h1:aqXlYGrumc8b/n4z9eDHHoiLN4fq2DAO//wMnqdxPhg=
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.52.0 h1:vkioc4XBfqnZZ7u40wK3Kgbjj9JYkvW6FY1ghmM/Shk=
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.52.0/go.mod h1:vsyxiwPzPlijgouF1SRZRGqbuHod8fV6+MRCH7ltxDE=
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.52.0 h1:Ud1trPqDHGSxyMiJ9a2XAdtTCXmRy0Yf7MjhW4dXogI=
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.52.0/go.mod h1:l/UzmhdRx9YP37NI/nSr7l1bgG0dZnGfZf6C7TiV4jI=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 h1:9l89oX4ba9kHbBol3Xin3leYJ+252h0zszDtBwyKe2A=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0/go.mod h1:XLZfZboOJWHNKUv7eH0inh0E9VV6eWDFB/9yJyTLPp0=
go.opentelemetry.io/contrib/instrumentation/runtime v0.50.0 h1:6dck47miguAOny5MeqX1G8idd+HpzDFt86U33d7aW2I=
go.opentelemetry.io/contrib/instrumentation/runtime v0.50.0/go.mod h1:rdPhRwNd2sHiRmwJAGs8xcwitqmP/j8pvl9X5jloYjU=
go.opentelemetry.io/contrib/propagators/b3 v1.27.0 h1:IjgxbomVrV9za6bRi8fWCNXENs0co37SZedQilP2hm0=
Expand Down
Loading
Loading