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. // client side span, populated through opencensus trace package.
if span := trace.FromContext(ctx); span != nil { if span := trace.FromContext(ctx); span != nil {
sc := span.SpanContext() sc := span.SpanContext()
gcploggingEntry.Trace = "projects/" + bml.projectID + "/traces/" + fmt.Sprintf("%x", sc.TraceID) gcploggingEntry.Trace = "projects/" + bml.projectID + "/traces/" + sc.TraceID.String()
gcploggingEntry.SpanID = fmt.Sprintf("%x", sc.SpanID) gcploggingEntry.SpanID = sc.SpanID.String()
} }
} else { } else {
// server side span, populated through stats/opencensus package. // server side span, populated through stats/opencensus package.
if tID, sID, ok := opencensus.GetTraceAndSpanID(ctx); ok { if tID, sID, ok := opencensus.GetTraceAndSpanID(ctx); ok {
gcploggingEntry.Trace = "projects/" + bml.projectID + "/traces/" + fmt.Sprintf("%x", tID) gcploggingEntry.Trace = "projects/" + bml.projectID + "/traces/" + tID.String()
gcploggingEntry.SpanID = fmt.Sprintf("%x", sID) gcploggingEntry.SpanID = sID.String()
} }
} }
return gcploggingEntry return gcploggingEntry

View File

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