Skip to content

Commit

Permalink
feat(otelsql): add an option: WithQueryFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
jixiufeng committed Apr 1, 2022
1 parent fe410ed commit b7a9f06
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions otelsql/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type config struct {
meter metric.Meter

attrs []attribute.KeyValue

queryFormatter func(query string) string
}

func newConfig(opts []Option) *config {
Expand All @@ -44,6 +46,9 @@ func newConfig(opts []Option) *config {
}

func (c *config) formatQuery(query string) string {
if c.queryFormatter != nil {
return c.queryFormatter(query)
}
return query
}

Expand Down Expand Up @@ -161,6 +166,13 @@ func WithMeterProvider(meterProvider metric.MeterProvider) Option {
}
}

// WithQueryFormatter configures a query formatter
func WithQueryFormatter(queryFormatter func(query string) string) Option {
return func(c *config) {
c.queryFormatter = queryFormatter
}
}

// ReportDBStatsMetrics reports DBStats metrics using OpenTelemetry Metrics API.
func ReportDBStatsMetrics(db *sql.DB, opts ...Option) {
cfg := newConfig(opts)
Expand Down

0 comments on commit b7a9f06

Please sign in to comment.