Skip to content

Commit c25d80c

Browse files
committed
nits/cleanup comments
1 parent 58564f8 commit c25d80c

4 files changed

Lines changed: 19 additions & 23 deletions

File tree

ddtrace/tracer/tracer.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -926,24 +926,24 @@ func (t *tracer) StartSpan(operationName string, options ...StartSpanOption) *Sp
926926
}
927927
span := spanStart(operationName, &t.sharedAttrs, options...)
928928

929-
// Snapshot all stable config fields needed below under a single RLock to avoid
929+
// Snapshot all internal config fields needed below under a single RLock to avoid
930930
// reader-counter contention on Config.mu when many goroutines call StartSpan.
931-
snap := t.config.internalConfig.SpanStartSnapshot()
931+
cSnap := t.config.internalConfig.SpanStartSnapshot()
932932

933933
if span.service == "" {
934-
span.service = snap.ServiceName
934+
span.service = cSnap.ServiceName
935935
}
936936

937937
// For non-universal version, promote main-service spans to the version-inclusive
938938
// shared attrs before applying any tags. This makes the subsequent version write
939939
// (from config or global tags) a COW no-op instead of triggering a Clone.
940-
if !t.config.universalVersion && span.service == snap.ServiceName {
940+
if !t.config.universalVersion && span.service == cSnap.ServiceName {
941941
span.meta.ReplaceSharedAttrs(&t.sharedAttrs, &t.sharedAttrsForMainSvc)
942942
}
943943

944-
span.noDebugStack = !snap.DebugStack
945-
if snap.Hostname != "" && snap.ReportHostname {
946-
span.setMetaInit(keyHostname, snap.Hostname)
944+
span.noDebugStack = !cSnap.DebugStack
945+
if cSnap.Hostname != "" && cSnap.ReportHostname {
946+
span.setMetaInit(keyHostname, cSnap.Hostname)
947947
}
948948
span.supportsEvents = t.config.agent.load().spanEventsAvailable
949949

@@ -955,15 +955,15 @@ func (t *tracer) StartSpan(operationName string, options ...StartSpanOption) *Sp
955955
span.serviceSource = ext.ServiceSourceMapping
956956
}
957957

958-
if snap.Version != "" {
959-
if t.config.universalVersion || span.service == snap.ServiceName {
958+
if cSnap.Version != "" {
959+
if t.config.universalVersion || span.service == cSnap.ServiceName {
960960
delete(span.metrics, ext.Version)
961-
span.meta.Set(ext.Version, snap.Version)
961+
span.meta.Set(ext.Version, cSnap.Version)
962962
}
963963
}
964-
if snap.Env != "" {
964+
if cSnap.Env != "" {
965965
delete(span.metrics, ext.Environment)
966-
span.meta.Set(ext.Environment, snap.Env)
966+
span.meta.Set(ext.Environment, cSnap.Env)
967967
}
968968
if _, ok := span.context.SamplingPriority(); !ok {
969969
// if not already sampled or a brand new trace, sample it
@@ -974,12 +974,12 @@ func (t *tracer) StartSpan(operationName string, options ...StartSpanOption) *Sp
974974
log.Debug("Started Span: %v, Operation: %s, Resource: %s, Tags: %v, %v", //nolint:gocritic // Debug logging needs full span representation
975975
span, span.name, span.resource, &span.meta, span.metrics)
976976
}
977-
if snap.ProfilerHotspotsEnabled || snap.ProfilerEndpoints {
978-
t.applyPPROFLabels(span.pprofCtxRestore, span, snap)
977+
if cSnap.ProfilerHotspotsEnabled || cSnap.ProfilerEndpoints {
978+
t.applyPPROFLabels(span.pprofCtxRestore, span, cSnap)
979979
} else {
980980
span.pprofCtxRestore = nil
981981
}
982-
if snap.DebugAbandonedSpans {
982+
if cSnap.DebugAbandonedSpans {
983983
select {
984984
case t.abandonedSpansDebugger.In <- newAbandonedSpanCandidate(span, false):
985985
// ok

internal/config/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ for attempt := 0; attempt <= sendRetries; attempt++ {
6262
When a hot path reads ~3+ `Config` fields, define a snapshot struct + method in `snapshots.go` and have the caller read from the local copy.
6363

6464
- **Why**: at high concurrency the bottleneck isn't blocking — readers don't block each other — but cache-line contention on `sync.RWMutex`'s reader counter. Folding N `RLock` pairs into 1 collapses N atomic ops on a shared cache line into 1.
65-
- **Convention**: one bespoke struct per caller. Don't build a generic `Snapshot(fields...)` API — see the comment at the top of `snapshots.go` for the reasoning.
65+
- **Convention**: one bespoke struct per caller (e.g, a calling function `StartSpan` gets a snapshot API called `SpanStartSnapshot`).
6666
- **Prior art**: `SpanStartSnapshot` for `tracer.StartSpan` (13 → 1 RLock acquisitions, ~60% speedup on `BenchmarkStartSpanConcurrent-8`).
6767

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type programmaticOverride struct {
6161
// Config represents global configuration properties.
6262
// Config instances should be obtained via Get() which always returns a non-nil value.
6363
// Methods on Config assume a non-nil receiver and will panic if called on nil.
64-
// Hot paths that read many fields should use a snapshot (see snapshots.go) to
64+
// Hot paths that read many fields within a single function should use a snapshot (see snapshots.go) to
6565
// avoid per-field RLock contention on the reader counter.
6666
type Config struct {
6767
mu sync.RWMutex

internal/config/snapshots.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99
// on the RWMutex's reader counter when many goroutines call the hot path
1010
// concurrently.
1111
//
12-
// Convention: one bespoke struct + method per caller. A generic
13-
// Snapshot(fields...) API would either box values through interface{} (costly
14-
// in a hot path) or expose unexported fields through a callback (no win over
15-
// adding a method here directly). Add a new struct + method below when a new
16-
// hot path needs more than ~3 fields under lock.
12+
// Add a new struct + method below when a new hot path needs more than ~3 fields
13+
// under the lock.
1714

1815
package config
1916

20-
// SpanStartSnapshot holds the config fields read by tracer.StartSpan.
2117
type SpanStartSnapshot struct {
2218
ServiceName string
2319
Env string

0 commit comments

Comments
 (0)