Skip to content

Commit ce859f8

Browse files
committed
sql: add goroutine IDs to text trace output in logs
when outputting a transaction trace in text format into the logs, we will now include the goroutine ID in the line with the operation like this: ``` === operation:foo gid:123 <other tags> ``` Epic: None Release note: None
1 parent 9de4d01 commit ce859f8

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

pkg/util/tracing/span_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,14 @@ func parseLine(s string) (traceLine, error) {
145145
if match == nil {
146146
return traceLine{}, errors.Newf("line doesn't match: %s", s)
147147
}
148+
text := match[3]
149+
// Strip goroutine IDs from the text for test consistency
150+
gidRe := regexp.MustCompile(` gid:\d+`)
151+
text = string(gidRe.ReplaceAll([]byte(text), nil))
148152
return traceLine{
149153
timeSinceTraceStart: match[1],
150154
timeSincePrev: match[2],
151-
text: match[3],
155+
text: text,
152156
}, nil
153157
}
154158

pkg/util/tracing/test_utils.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,22 @@ func checkRecordingWithRedact(t T, rec tracingpb.Recording, expected string, red
196196
// After | [operation]
197197
re = regexp.MustCompile(`: .*]`)
198198
rec = string(re.ReplaceAll([]byte(rec), []byte("]")))
199-
// 5. Change all tabs to four spaces.
199+
// 5. Strip out goroutine IDs from operation lines.
200+
//
201+
// Before | "=== operation:foo gid:123 _verbose:‹1›"
202+
// After | "=== operation:foo _verbose:‹1›"
203+
re = regexp.MustCompile(` gid:\d+`)
204+
rec = string(re.ReplaceAll([]byte(rec), nil))
205+
// 6. Change all tabs to four spaces.
200206
rec = strings.ReplaceAll(rec, "\t", " ")
201-
// 6. Compute the outermost indentation.
207+
// 7. Compute the outermost indentation.
202208
indent := strings.Repeat(" ", len(rec)-len(strings.TrimLeft(rec, " ")))
203-
// 7. Outdent each line by that amount.
209+
// 8. Outdent each line by that amount.
204210
var lines []string
205211
for _, line := range strings.Split(rec, "\n") {
206212
lines = append(lines, strings.TrimPrefix(line, indent))
207213
}
208-
// 8. Stitch everything together.
214+
// 9. Stitch everything together.
209215
return strings.Join(lines, "\n")
210216
}
211217

pkg/util/tracing/tracingpb/recording.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ func (r Recording) visitSpan(sp RecordedSpan, depth int) []traceLogData {
259259
sb.SafeString("=== operation:")
260260
sb.SafeString(redact.SafeString(sp.Operation))
261261

262+
if sp.GoroutineID != 0 {
263+
sb.Printf(" gid:%d", sp.GoroutineID)
264+
}
265+
262266
for _, tg := range sp.TagGroups {
263267
var prefix redact.RedactableString
264268
if tg.Name != AnonymousTagGroupName {

0 commit comments

Comments
 (0)