-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contrib/go-pg/pg.v10 add options, ServiceName
- Loading branch information
1 parent
102a0e6
commit 68fea95
Showing
3 changed files
with
99 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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,60 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016 Datadog, Inc. | ||
|
||
package pg | ||
|
||
import ( | ||
"math" | ||
|
||
"gopkg.in/DataDog/dd-trace-go.v1/internal" | ||
) | ||
|
||
type clientConfig struct { | ||
serviceName string | ||
analyticsRate float64 | ||
} | ||
|
||
// ClientOption represents an option that can be used to create or wrap a client. | ||
type ClientOption func(*clientConfig) | ||
|
||
func defaults(cfg *clientConfig) { | ||
cfg.serviceName = "gopg.db" | ||
// cfg.analyticsRate = globalconfig.AnalyticsRate() | ||
if internal.BoolEnv("DD_TRACE_GOPG_ANALYTICS_ENABLED", false) { | ||
cfg.analyticsRate = 1.0 | ||
} else { | ||
cfg.analyticsRate = math.NaN() | ||
} | ||
} | ||
|
||
// WithServiceName sets the given service name for the client. | ||
func WithServiceName(name string) ClientOption { | ||
return func(cfg *clientConfig) { | ||
cfg.serviceName = name | ||
} | ||
} | ||
|
||
// WithAnalytics enables Trace Analytics for all started spans. | ||
func WithAnalytics(on bool) ClientOption { | ||
return func(cfg *clientConfig) { | ||
if on { | ||
cfg.analyticsRate = 1.0 | ||
} else { | ||
cfg.analyticsRate = math.NaN() | ||
} | ||
} | ||
} | ||
|
||
// WithAnalyticsRate sets the sampling rate for Trace Analytics events | ||
// correlated to started spans. | ||
func WithAnalyticsRate(rate float64) ClientOption { | ||
return func(cfg *clientConfig) { | ||
if rate >= 0.0 && rate <= 1.0 { | ||
cfg.analyticsRate = rate | ||
} else { | ||
cfg.analyticsRate = math.NaN() | ||
} | ||
} | ||
} |
This file contains 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 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