Skip to content

The only tool you need to know what is happening and how to fix it.

fix: traceId + feat: app version

dduxa6abe82e0dfe
diff --git a/backend/app/controllers/otelcontrollers/helpers.go b/backend/app/controllers/otelcontrollers/helpers.go
index 7aa67f3c..9636ec79 100644
--- a/backend/app/controllers/otelcontrollers/helpers.go
+++ b/backend/app/controllers/otelcontrollers/helpers.go
@@ -1,6 +1,7 @@
package otelcontrollers
import (
+ "encoding/hex"
"strconv"
"time"
@@ -18,6 +19,16 @@ func otelTraceIDToUUID(traceID []byte) uuid.UUID {
return u
}
+func rayIDToUUID(rayID string) uuid.UUID {
+ b, err := hex.DecodeString(rayID)
+ if err != nil || len(b) == 0 {
+ return uuid.New()
+ }
+ var u uuid.UUID
+ copy(u[16-len(b):], b)
+ return u
+}
+
// otelSpanIDToUUID converts an 8-byte OTEL span ID to a UUID by zero-padding the first 8 bytes.
func otelSpanIDToUUID(spanID []byte) uuid.UUID {
if len(spanID) != 8 {
diff --git a/backend/app/controllers/otelcontrollers/trace_converter.go b/backend/app/controllers/otelcontrollers/trace_converter.go
index 2cb25d71..00e11a4f 100644
--- a/backend/app/controllers/otelcontrollers/trace_converter.go
+++ b/backend/app/controllers/otelcontrollers/trace_converter.go
@@ -4,6 +4,7 @@ import (
"backend/app/controllers/clientcontrollers"
"backend/app/models"
"fmt"
+ "strings"
"time"
"github.com/google/uuid"
@@ -22,16 +23,36 @@ func convertTraces(projectId uuid.UUID, req *coltracepb.ExportTraceServiceReques
resourceAttrs := rs.GetResource().GetAttributes()
serverName := getStringAttribute(resourceAttrs, "service.name")
appVersion := getStringAttribute(resourceAttrs, "service.version")
+ if appVersion == "" {
+ if scriptVersionId := getStringAttribute(resourceAttrs, "cloudflare.script_version.id"); scriptVersionId != "" {
+ if idx := strings.LastIndex(scriptVersionId, "-"); idx != -1 {
+ appVersion = scriptVersionId[idx+1:]
+ }
+ }
+ }
for _, ss := range rs.ScopeSpans {
for _, span := range ss.Spans {
+ spanAttrs := span.Attributes
+ allAttrs := extractAttributes(spanAttrs)
+
traceId := otelTraceIDToUUID(span.TraceId)
+ if traceId == uuid.Nil {
+ rayId := getStringAttribute(spanAttrs, "cloudflare.ray_id")
+ if rayId == "" {
+ rayId = getStringAttribute(resourceAttrs, "cloudflare.ray_id")
+ }
+ if rayId != "" {
+ traceId = rayIDToUUID(rayId)
+ } else {
+ traceId = uuid.New()
+ }
+ }
+
spanId := otelSpanIDToUUID(span.SpanId)
startTime := nanoToTime(span.StartTimeUnixNano)
endTime := nanoToTime(span.EndTimeUnixNano)
duration := endTime.Sub(startTime)
- spanAttrs := span.Attributes
- allAttrs := extractAttributes(spanAttrs)
isRoot := len(span.ParentSpanId) == 0
if isRoot {