Repository navigation
feat(otel): propagate TransactionManager context and add pkg/contrib/… #16
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
Open
simonnix
wants to merge
3
commits into
main
Choose a base branch
from
feat/otel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,14 @@ | ||
| { | ||
| "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", | ||
| "packages": { | ||
| ".": { | ||
| "release-type": "go" | ||
| }, | ||
| "pkg/contrib/otel": { | ||
| "release-type": "go", | ||
| "component": "pkg/contrib/otel", | ||
| "include-component-in-tag": true, | ||
| "tag-separator": "/" | ||
| } | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
This file contains hidden or 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 hidden or 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,3 @@ | ||
| { | ||
| ".": "0.3.1" | ||
| } |
This file contains hidden or 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,77 @@ | ||
| --- | ||
| title: "9. OpenTelemetry Integration" | ||
| weight: 9 | ||
| --- | ||
|
|
||
| # OpenTelemetry Integration | ||
|
|
||
| Rays ORM integrates with `rays-otel` to trace GORM SQL queries and propagate active spans across repositories and transactions. | ||
|
|
||
| ## Context Propagation | ||
|
|
||
| `GormTransactionalManager` automatically binds `TransactionManager.GetContext()` to every `*gorm.DB` operation (both outside and inside active transactions). When combined with `rays-fiber` or `rays-otel`, SQL spans created by GORM automatically become children of the active HTTP or service span. | ||
|
|
||
| ## Automatic GORM Instrumentation (`pkg/contrib/otel`) | ||
|
|
||
| The optional `github.com/BeamFoundry/rays-orm/pkg/contrib/otel` sub-module provides `GormOtelAutoConfiguration`, which automatically instruments every `*gorm.DB` beam in the container with `gorm.io/plugin/opentelemetry/tracing` using the container's `trace.TracerProvider` when available. | ||
|
|
||
| ### 📦 Installation | ||
|
|
||
| ```bash | ||
| go get github.com/BeamFoundry/rays-orm/pkg/contrib/otel | ||
| ``` | ||
|
|
||
| ### Usage | ||
|
|
||
| Underscore-import `github.com/BeamFoundry/rays-orm/pkg/contrib/otel` in your `main.go`: | ||
|
|
||
| ```go | ||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
| "github.com/BeamFoundry/rays" | ||
|
|
||
| _ "github.com/BeamFoundry/rays-orm" | ||
| _ "github.com/BeamFoundry/rays-orm/pkg/contrib/otel" | ||
| _ "github.com/BeamFoundry/rays-otel" | ||
| ) | ||
|
|
||
| func main() { | ||
| ctx := rays.ApplicationContext() | ||
| if err := ctx.Initialize(); err != nil { | ||
| err.LogErrorWithStackTrace() | ||
| os.Exit(1) | ||
| } | ||
| ctx.Run() | ||
| } | ||
| ``` | ||
|
|
||
| ### Configuration (`rays.orm.otel`) | ||
|
|
||
| You can configure the plugin in your `application.yaml`: | ||
|
|
||
| ```yaml | ||
| rays: | ||
| orm: | ||
| otel: | ||
| dbSystem: sqlite | ||
| withoutMetrics: false | ||
| withoutQueryVariables: false | ||
| withoutServerAddress: false | ||
| recordStackTrace: false | ||
| ``` | ||
|
|
||
| ### Customizing Options (`GormOtelCustomizer`) | ||
|
|
||
| Any Beam implementing `GormOtelCustomizer` can append or override `tracing.Option` values: | ||
|
|
||
| ```go | ||
| type CustomGormOtel struct { | ||
| Service | ||
| } | ||
|
|
||
| func (this *CustomGormOtel) CustomizeGormOtel(options []tracing.Option) []tracing.Option { | ||
| return append(options, tracing.WithAttributes(attribute.String("db.role", "primary"))) | ||
| } | ||
| ``` |
This file contains hidden or 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 hidden or 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 hidden or 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,68 @@ | ||
| module github.com/BeamFoundry/rays-orm/pkg/contrib/otel | ||
|
|
||
| go 1.27 | ||
|
|
||
| require ( | ||
| github.com/BeamFoundry/rays v0.5.0-rc3 | ||
| github.com/onsi/ginkgo/v2 v2.34.0 | ||
| github.com/onsi/gomega v1.44.0 | ||
| go.opentelemetry.io/otel v1.47.0 | ||
| go.opentelemetry.io/otel/sdk v1.47.0 | ||
| go.opentelemetry.io/otel/trace v1.47.0 | ||
| gorm.io/driver/sqlite v1.6.0 | ||
| gorm.io/gorm v1.31.2 | ||
| gorm.io/plugin/opentelemetry v0.1.16 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/ClickHouse/ch-go v0.61.5 // indirect | ||
| github.com/ClickHouse/clickhouse-go/v2 v2.30.0 // indirect | ||
| github.com/Masterminds/semver/v3 v3.4.0 // indirect | ||
| github.com/andybalholm/brotli v1.1.1 // indirect | ||
| github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
| github.com/gabriel-vasile/mimetype v1.4.16 // indirect | ||
| github.com/go-faster/city v1.0.1 // indirect | ||
| github.com/go-faster/errors v0.7.1 // indirect | ||
| github.com/go-logr/logr v1.4.4 // indirect | ||
| github.com/go-logr/stdr v1.2.2 // indirect | ||
| github.com/go-playground/locales v0.14.2 // indirect | ||
| github.com/go-playground/universal-translator v0.18.2 // indirect | ||
| github.com/go-playground/validator/v10 v10.30.6 // indirect | ||
| github.com/go-sql-driver/mysql v1.7.0 // indirect | ||
| github.com/go-task/slim-sprig/v3 v3.0.0 // indirect | ||
| github.com/google/go-cmp v0.7.0 // indirect | ||
| github.com/google/pprof v0.0.0-20260402051712-545e8a4df936 // indirect | ||
| github.com/google/uuid v1.6.0 // indirect | ||
| github.com/hashicorp/go-version v1.6.0 // indirect | ||
| github.com/jackc/pgpassfile v1.0.0 // indirect | ||
| github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect | ||
| github.com/jackc/pgx/v5 v5.5.5 // indirect | ||
| github.com/jackc/puddle/v2 v2.2.1 // indirect | ||
| github.com/jinzhu/inflection v1.0.0 // indirect | ||
| github.com/jinzhu/now v1.1.5 // indirect | ||
| github.com/klauspost/compress v1.17.8 // indirect | ||
| github.com/leodido/go-urn v1.5.0 // indirect | ||
| github.com/mattn/go-sqlite3 v1.14.22 // indirect | ||
| github.com/paulmach/orb v0.11.1 // indirect | ||
| github.com/pierrec/lz4/v4 v4.1.21 // indirect | ||
| github.com/pkg/errors v0.9.1 // indirect | ||
| github.com/segmentio/asm v1.2.0 // indirect | ||
| github.com/shopspring/decimal v1.4.0 // indirect | ||
| github.com/timandy/routine v1.1.6 // indirect | ||
| go.opentelemetry.io/auto/sdk v1.2.1 // indirect | ||
| go.opentelemetry.io/otel/log v1.47.0 // indirect | ||
| go.opentelemetry.io/otel/metric v1.47.0 // indirect | ||
| go.yaml.in/yaml/v3 v3.0.5 // indirect | ||
| golang.org/x/crypto v0.58.0 // indirect | ||
| golang.org/x/mod v0.42.0 // indirect | ||
| golang.org/x/net v0.61.0 // indirect | ||
| golang.org/x/sync v0.24.0 // indirect | ||
| golang.org/x/sys v0.50.0 // indirect | ||
| golang.org/x/term v0.48.0 // indirect | ||
| golang.org/x/text v0.43.0 // indirect | ||
| golang.org/x/tools v0.52.0 // indirect | ||
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| gorm.io/driver/clickhouse v0.7.0 // indirect | ||
| gorm.io/driver/mysql v1.5.7 // indirect | ||
| gorm.io/driver/postgres v1.5.11 // indirect | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.