gcp/observability: Switch hex encoding to string() method (#6138)

This commit is contained in:
Zach Reyes 2023-03-20 16:32:08 -04:00 committed by GitHub
parent 70c5291509
commit 78099db03f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

@ -327,14 +327,14 @@ func (bml *binaryMethodLogger) buildGCPLoggingEntry(ctx context.Context, c iblog
// client side span, populated through opencensus trace package.
if span := trace.FromContext(ctx); span != nil {
sc := span.SpanContext()
gcploggingEntry.Trace = "projects/" + bml.projectID + "/traces/" + fmt.Sprintf("%x", sc.TraceID)
gcploggingEntry.SpanID = fmt.Sprintf("%x", sc.SpanID)
gcploggingEntry.Trace = "projects/" + bml.projectID + "/traces/" + sc.TraceID.String()
gcploggingEntry.SpanID = sc.SpanID.String()
}
} else {
// server side span, populated through stats/opencensus package.
if tID, sID, ok := opencensus.GetTraceAndSpanID(ctx); ok {
gcploggingEntry.Trace = "projects/" + bml.projectID + "/traces/" + fmt.Sprintf("%x", tID)
gcploggingEntry.SpanID = fmt.Sprintf("%x", sID)
gcploggingEntry.Trace = "projects/" + bml.projectID + "/traces/" + tID.String()
gcploggingEntry.SpanID = sID.String()
}
}
return gcploggingEntry

View File

@ -121,12 +121,11 @@ type traceAndSpanIDString struct {
}
// idsToString is a helper that converts from generated trace and span IDs to
// the string version stored in trace message events. (hex 16 lowercase encoded,
// and extra data attached to trace id).
// the string version stored in trace message events.
func idsToString(tasi traceAndSpanID, projectID string) traceAndSpanIDString {
return traceAndSpanIDString{
traceID: "projects/" + projectID + "/traces/" + fmt.Sprintf("%x", tasi.traceID),
spanID: fmt.Sprintf("%x", tasi.spanID),
traceID: "projects/" + projectID + "/traces/" + tasi.traceID.String(),
spanID: tasi.spanID.String(),
}
}