Skip to content

Commit

Permalink
move common func to options
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahkm committed Oct 28, 2024
1 parent e6b61b2 commit 9e23b52
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions contrib/julienschmidt/httprouter/internal/tracing/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/DataDog/dd-trace-go/v2/ddtrace/ext"
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
"github.com/DataDog/dd-trace-go/v2/instrumentation"
"github.com/DataDog/dd-trace-go/v2/instrumentation/httptrace"
"github.com/DataDog/dd-trace-go/v2/instrumentation/options"
)

type Config struct {
Expand All @@ -23,7 +23,7 @@ type Config struct {

func NewConfig(opts ...Option) *Config {
cfg := new(Config)
if httptrace.GetBoolEnv("DD_TRACE_HTTPROUTER_ANALYTICS_ENABLED", false) {
if options.GetBoolEnv("DD_TRACE_HTTPROUTER_ANALYTICS_ENABLED", false) {
cfg.analyticsRate = 1.0
} else {
cfg.analyticsRate = instr.AnalyticsRate(true)
Expand Down
5 changes: 3 additions & 2 deletions contrib/net/http/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
"github.com/DataDog/dd-trace-go/v2/instrumentation"
"github.com/DataDog/dd-trace-go/v2/instrumentation/httptrace"
"github.com/DataDog/dd-trace-go/v2/instrumentation/options"
)

type commonConfig struct {
Expand Down Expand Up @@ -62,7 +63,7 @@ func (o HandlerOptionFn) apply(cfg *config) {
}

func defaults(cfg *config) {
if httptrace.GetBoolEnv("DD_TRACE_HTTP_ANALYTICS_ENABLED", false) {
if options.GetBoolEnv("DD_TRACE_HTTP_ANALYTICS_ENABLED", false) {
cfg.analyticsRate = 1.0
} else {
cfg.analyticsRate = instr.AnalyticsRate(true)
Expand Down Expand Up @@ -200,7 +201,7 @@ func newRoundTripperConfig() *roundTripperConfig {
commonConfig: sharedCfg,
propagation: true,
spanNamer: defaultSpanNamer,
queryString: httptrace.GetBoolEnv(envClientQueryStringEnabled, true),
queryString: options.GetBoolEnv(envClientQueryStringEnabled, true),
isStatusError: isClientError,
}
v := os.Getenv(envClientErrorStatuses)
Expand Down
8 changes: 0 additions & 8 deletions instrumentation/httptrace/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/DataDog/dd-trace-go/v2/ddtrace/ext"
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
"github.com/DataDog/dd-trace-go/v2/instrumentation"
"github.com/DataDog/dd-trace-go/v2/internal"
"github.com/DataDog/dd-trace-go/v2/internal/appsec/listener/httpsec"
)

Expand Down Expand Up @@ -144,10 +143,3 @@ func HeaderTagsFromRequest(req *http.Request, headerTags instrumentation.HeaderT
}
}
}

// This is a workaround needed because of v2 changes that prevents contribs from accessing
// the internal directory. This function should not be used if the internal directory
// can be
func GetBoolEnv(key string, def bool) bool {
return internal.BoolEnv(key, def)
}
9 changes: 9 additions & 0 deletions instrumentation/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package options

import "github.com/DataDog/dd-trace-go/v2/internal"

// Copy should be used any time existing options are copied into
// a new locally scoped set of options. This is to avoid data races and
// accidental side effects.
Expand All @@ -29,3 +31,10 @@ func Expand[T any](opts []T, initialPosition, trailCapacity int) []T {
copy(dup[initialPosition:], opts)
return dup
}

// This is a workaround needed because of v2 changes that prevents contribs from accessing
// the internal directory. This function should not be used if the internal directory
// can be
func GetBoolEnv(key string, def bool) bool {
return internal.BoolEnv(key, def)
}

0 comments on commit 9e23b52

Please sign in to comment.