Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dependabot/go_modules…
Browse files Browse the repository at this point in the history
…/go.opentelemetry.io/otel-1.6.1
  • Loading branch information
bharat-gadde-dev committed Mar 29, 2022
2 parents 24213df + 3f27b81 commit bb30cfa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions otelginmetrics/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type config struct {
groupedStatus bool
recorder Recorder
attributes func(serverName, route string, request *http.Request) []attribute.KeyValue
shouldRecord func(serverName, route string, request *http.Request) bool
}

func defaultConfig() *config {
Expand All @@ -23,6 +24,9 @@ func defaultConfig() *config {
recordSize: true,
groupedStatus: true,
attributes: DefaultAttributes,
shouldRecord: func(_, _ string, _ *http.Request) bool {
return true
},
}
}

Expand Down
5 changes: 4 additions & 1 deletion otelginmetrics/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ func Middleware(service string, options ...Option) gin.HandlerFunc {
if len(route) <= 0 {
route = "nonconfigured"
}
if !cfg.shouldRecord(service, route, ginCtx.Request) {
ginCtx.Next()
return
}

start := time.Now()

reqAttributes := cfg.attributes(service, route, ginCtx.Request)

if cfg.recordInFlight {
Expand Down
10 changes: 10 additions & 0 deletions otelginmetrics/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,18 @@ func WithGroupedStatusDisabled() Option {
})
}

// WithRecorder sets a recorder for recording requests
// By default the open telemetry recorder is used
func WithRecorder(recorder Recorder) Option {
return optionFunc(func(cfg *config) {
cfg.recorder = recorder
})
}

// WithShouldRecordFunc sets a func using which whether a record should be recorded
// By default the all api calls are recorded
func WithShouldRecordFunc(shouldRecord func(serverName, route string, request *http.Request) bool) Option {
return optionFunc(func(cfg *config) {
cfg.shouldRecord = shouldRecord
})
}

0 comments on commit bb30cfa

Please sign in to comment.