Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
nhulston committed Nov 6, 2024
1 parent 5dd43b0 commit 2c29165
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ddtrace/tracer/remote_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func convertRemoteSamplingRules(rules *[]rcSamplingRule) *[]SamplingRule {
}
var convertedRules []SamplingRule
for _, rule := range *rules {
fmt.Printf("[A] Sample rate: %f\n", rule.SampleRate)
if rule.Tags != nil && len(rule.Tags) != 0 {
tags := make(map[string]*regexp.Regexp, len(rule.Tags))
tagsStrs := make(map[string]string, len(rule.Tags))
Expand All @@ -85,6 +86,7 @@ func convertRemoteSamplingRules(rules *[]rcSamplingRule) *[]SamplingRule {

convertedRules = append(convertedRules, x)
} else {
fmt.Printf("[B] Sample rate: %f\n", rule.SampleRate)
x := SamplingRule{
Service: globMatch(rule.Service),
Name: globMatch(rule.Name),
Expand Down Expand Up @@ -164,7 +166,9 @@ func (t *tracer) onRemoteConfigUpdate(u remoteconfig.ProductUpdate) map[string]s
statuses[path] = state.ApplyStatus{State: state.ApplyStateAcknowledged}
}
log.Debug("Resetting configurations")
fmt.Printf("[C] Sample rate: %v\n", t.config.traceSampleRate)
updated := t.config.traceSampleRate.reset()
fmt.Printf("[D] Sample rate: %v\n", t.config.traceSampleRate)
if updated {
telemConfigs = append(telemConfigs, t.config.traceSampleRate.toTelemetry())
}
Expand Down Expand Up @@ -215,7 +219,9 @@ func (t *tracer) onRemoteConfigUpdate(u remoteconfig.ProductUpdate) map[string]s
continue
}
statuses[path] = state.ApplyStatus{State: state.ApplyStateAcknowledged}
fmt.Printf("[E] Sample rate: %v\n", c.LibConfig.SamplingRate)
updated := t.config.traceSampleRate.handleRC(c.LibConfig.SamplingRate)
fmt.Printf("[F] Sample rate: %v\n", c.LibConfig.SamplingRate)
if updated {
telemConfigs = append(telemConfigs, t.config.traceSampleRate.toTelemetry())
}
Expand Down Expand Up @@ -331,6 +337,8 @@ func (t *tracer) startRemoteConfig(rcConfig remoteconfig.ClientConfig) error {
remoteconfig.APMTracingEnabled,
remoteconfig.APMTracingSampleRules,
)
fmt.Printf("[G] Sample rate: %v\n", remoteconfig.APMTracingSampleRate)
fmt.Printf("[H] Sample rules: %v\n", remoteconfig.APMTracingSampleRules)

if apmTracingError != nil || dynamicInstrumentationError != nil {
return fmt.Errorf("could not subscribe to at least one remote config product: %s; %s",
Expand Down
8 changes: 8 additions & 0 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package tracer
import (
gocontext "context"
"encoding/binary"
"fmt"
"math"
"os"
"runtime/pprof"
Expand Down Expand Up @@ -263,16 +264,22 @@ func newUnstartedTracer(opts ...StartOption) *tracer {
c.spanRules = spans
}
rulesSampler := newRulesSampler(c.traceRules, c.spanRules, c.globalSampleRate)
fmt.Printf("[I] Sample rate: %v\n", c.globalSampleRate)
fmt.Printf("[J] Sample rules: %v\n", c.traceRules)
fmt.Printf("[K] Sample rules: %v\n", c.spanRules)
c.traceSampleRate = newDynamicConfig("trace_sample_rate", c.globalSampleRate, rulesSampler.traces.setGlobalSampleRate, equal[float64])
fmt.Printf("[L] Sample rate: %v\n", c.traceSampleRate)
// If globalSampleRate returns NaN, it means the environment variable was not set or valid.
// We could always set the origin to "env_var" inconditionally, but then it wouldn't be possible
// to distinguish between the case where the environment variable was not set and the case where
// it default to NaN.
if !math.IsNaN(c.globalSampleRate) {
fmt.Printf("[M] NaN\n")
c.traceSampleRate.cfgOrigin = telemetry.OriginEnvVar
}
c.traceSampleRules = newDynamicConfig("trace_sample_rules", c.traceRules,
rulesSampler.traces.setTraceSampleRules, EqualsFalseNegative)
fmt.Printf("[N] Sample rules: %v\n", c.traceSampleRules)
var dataStreamsProcessor *datastreams.Processor
if c.dataStreamsMonitoringEnabled {
dataStreamsProcessor = datastreams.NewProcessor(statsd, c.env, c.serviceName, c.version, c.agentURL, c.httpClient)
Expand Down Expand Up @@ -711,6 +718,7 @@ func (t *tracer) Inject(ctx ddtrace.SpanContext, carrier interface{}) error {
// updateSampling runs trace sampling rules on the context, since properties like resource / tags
// could change and impact the result of sampling. This must be done once before context is propagated.
func (t *tracer) updateSampling(ctx ddtrace.SpanContext) {
fmt.Printf("[O] Sample rules: %v\n", t.rulesSampling)
sctx, ok := ctx.(*spanContext)
if sctx == nil || !ok {
return
Expand Down

0 comments on commit 2c29165

Please sign in to comment.