Skip to content

Commit

Permalink
fix(otelgorm): renamed var and added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
William De Keyzer authored and William De Keyzer committed Feb 28, 2024
1 parent 869b05c commit ef37c51
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions otelgorm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ if err := db.WithContext(ctx).Raw("SELECT 42").Scan(&num).Error; err != nil {

See [example](/example/) for details.

## Usage: exceptions

In case you want to omit certain database operations from any trace/span, you can also set:
```go
db.Set(EnabledTraceDatabaseKey, false)
```
This will omit the database queries following after from any trace.

## Options

You can customize the plugin using configuration
Expand Down
2 changes: 1 addition & 1 deletion otelgorm/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

const (
DisabledTraceDatabaseKey = "otelgorm-trace-enabled"
EnabledTraceDatabaseKey = "otelgorm-trace-enabled"
)

type Option func(p *otelPlugin)
Expand Down
2 changes: 1 addition & 1 deletion otelgorm/otelgorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type parentCtxKey struct{}
// checkTraceEnabled checks if the 'special' database key was set and if so returns it
// This allows you to disable starting/registering a new trace for certain operations
func checkTraceEnabled(db *gorm.DB) bool {
value, ok := db.Get(DisabledTraceDatabaseKey)
value, ok := db.Get(EnabledTraceDatabaseKey)

// If value is not specifically set, it should start a new trace
if !ok {
Expand Down

0 comments on commit ef37c51

Please sign in to comment.