Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddtrace/tracer: add IsTraceRoot to clients-side-stats #2821

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,21 @@ func newAggregableSpan(s *span, obfuscator *obfuscate.Obfuscator) *aggregableSpa
statusCode = uint32(c)
}
}
var isTraceRoot trilean
if s.ParentID == 0 {
isTraceRoot = trilean_true
} else {
isTraceRoot = trilean_false
}

key := aggregation{
Name: s.Name,
Resource: obfuscatedResource(obfuscator, s.Type, s.Resource),
Service: s.Service,
Type: s.Type,
Synthetics: strings.HasPrefix(s.Meta[keyOrigin], "synthetics"),
StatusCode: statusCode,
Name: s.Name,
Resource: obfuscatedResource(obfuscator, s.Type, s.Resource),
Service: s.Service,
Type: s.Type,
Synthetics: strings.HasPrefix(s.Meta[keyOrigin], "synthetics"),
StatusCode: statusCode,
IsTraceRoot: isTraceRoot,
}
return &aggregableSpan{
key: key,
Expand Down
18 changes: 10 additions & 8 deletions ddtrace/tracer/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ func TestNewAggregableSpan(t *testing.T) {
Type: "sql",
}, o)
assert.Equal(t, aggregation{
Name: "name",
Type: "sql",
Resource: "SELECT * FROM table WHERE password = ?",
Service: "service",
Name: "name",
Type: "sql",
Resource: "SELECT * FROM table WHERE password = ?",
Service: "service",
IsTraceRoot: 1,
}, aggspan.key)
})

Expand All @@ -190,10 +191,11 @@ func TestNewAggregableSpan(t *testing.T) {
Type: "sql",
}, nil)
assert.Equal(t, aggregation{
Name: "name",
Type: "sql",
Resource: "SELECT * FROM table WHERE password='secret'",
Service: "service",
Name: "name",
Type: "sql",
Resource: "SELECT * FROM table WHERE password='secret'",
Service: "service",
IsTraceRoot: 1,
}, aggspan.key)
})
}
Expand Down
23 changes: 17 additions & 6 deletions ddtrace/tracer/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,13 @@ func (c *concentrator) flushAndSend(timenow time.Time, includeCurrent bool) {
// aggregation specifies a uniquely identifiable key under which a certain set
// of stats are grouped inside a bucket.
type aggregation struct {
Name string
Type string
Resource string
Service string
StatusCode uint32
Synthetics bool
Name string
Type string
Resource string
Service string
StatusCode uint32
Synthetics bool
IsTraceRoot trilean
}

type rawBucket struct {
Expand Down Expand Up @@ -278,13 +279,22 @@ func (sb *rawBucket) Export() statsBucket {
return csb
}

type trilean int32

const (
trilean_not_set trilean = iota
trilean_true
trilean_false
Copy link
Member

@felixge felixge Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snake_case? 🙈

Not the end of the world, but I don't think we should let this creep into the code base further, cc @darccio as reviewer.

I submitted #2831 to clean up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixge You are right, I didn't notice it. The trilean concept blinded me. We'll merge to improve this.

)

type rawGroupedStats struct {
hits uint64
topLevelHits uint64
errors uint64
duration uint64
okDistribution *ddsketch.DDSketch
errDistribution *ddsketch.DDSketch
IsTraceRoot trilean
darccio marked this conversation as resolved.
Show resolved Hide resolved
}

func newRawGroupedStats() *rawGroupedStats {
Expand Down Expand Up @@ -335,6 +345,7 @@ func (s *rawGroupedStats) export(k aggregation) (groupedStats, error) {
OkSummary: okSummary,
ErrorSummary: errSummary,
Synthetics: k.Synthetics,
IsTraceRoot: int32(k.IsTraceRoot),
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions ddtrace/tracer/stats_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ type groupedStats struct {
ErrorSummary []byte `json:"errorSummary,omitempty"`
Synthetics bool `json:"synthetics,omitempty"`
TopLevelHits uint64 `json:"topLevelHits,omitempty"`
IsTraceRoot int32 `json:"isTraceRoot,omitempty"`
}
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ services:
TRACE_LANGUAGE: golang
ENABLED_CHECKS: trace_stall,trace_count_header,trace_peer_service,trace_dd_service
PORT: 9126
DD_SUPPRESS_TRACE_PARSE_ERRORS: true
DD_POOL_TRACE_CHECK_FAILURES: true
DD_DISABLE_ERROR_RESPONSES: true
DD_SUPPRESS_TRACE_PARSE_ERRORS: "true"
DD_POOL_TRACE_CHECK_FAILURES: "true"
DD_DISABLE_ERROR_RESPONSES: "true"
ports:
- "127.0.0.1:9126:9126"
mongodb:
Expand Down
Loading