Skip to content

Commit db104ec

Browse files
authored
PubSub to honour incoming TraceParent (dapr#5950)
Signed-off-by: Bernd Verst <github@bernd.dev>
1 parent da1d01f commit db104ec

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

pkg/runtime/bulk_subscriber.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,12 @@ func (a *DaprRuntime) publishBulkMessageHTTP(ctx context.Context, bulkSubCallDat
358358
n := 0
359359
for _, pubsubMsg := range psm.pubSubMessages {
360360
cloudEvent := pubsubMsg.cloudEvent
361-
if cloudEvent[pubsub.TraceIDField] != nil {
362-
traceID := cloudEvent[pubsub.TraceIDField].(string)
361+
iTraceID := cloudEvent[pubsub.TraceParentField]
362+
if iTraceID == nil {
363+
iTraceID = cloudEvent[pubsub.TraceIDField]
364+
}
365+
if iTraceID != nil {
366+
traceID := iTraceID.(string)
363367
sc, _ := diag.SpanContextFromW3CString(traceID)
364368
var span trace.Span
365369
ctx, span = diag.StartInternalCallbackSpan(ctx, "pubsub/"+psm.topic, sc, a.globalConfig.Spec.TracingSpec)
@@ -570,7 +574,11 @@ func (a *DaprRuntime) publishBulkMessageGRPC(ctx context.Context, bulkSubCallDat
570574
n := 0
571575
for _, pubSubMsg := range psm.pubSubMessages {
572576
cloudEvent := pubSubMsg.cloudEvent
573-
if iTraceID, ok := cloudEvent[pubsub.TraceIDField]; ok {
577+
iTraceID := cloudEvent[pubsub.TraceParentField]
578+
if iTraceID == nil {
579+
iTraceID = cloudEvent[pubsub.TraceIDField]
580+
}
581+
if iTraceID != nil {
574582
if traceID, ok := iTraceID.(string); ok {
575583
sc, _ := diag.SpanContextFromW3CString(traceID)
576584

pkg/runtime/runtime.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,8 +2134,12 @@ func (a *DaprRuntime) publishMessageHTTP(ctx context.Context, msg *pubsubSubscri
21342134
WithCustomHTTPMetadata(msg.metadata)
21352135
defer req.Close()
21362136

2137-
if cloudEvent[pubsub.TraceIDField] != nil {
2138-
traceID := cloudEvent[pubsub.TraceIDField].(string)
2137+
iTraceID := cloudEvent[pubsub.TraceParentField]
2138+
if iTraceID == nil {
2139+
iTraceID = cloudEvent[pubsub.TraceIDField]
2140+
}
2141+
if iTraceID != nil {
2142+
traceID := iTraceID.(string)
21392143
sc, _ := diag.SpanContextFromW3CString(traceID)
21402144
ctx, span = diag.StartInternalCallbackSpan(ctx, "pubsub/"+msg.topic, sc, a.globalConfig.Spec.TracingSpec)
21412145
}
@@ -2254,7 +2258,11 @@ func (a *DaprRuntime) publishMessageGRPC(ctx context.Context, msg *pubsubSubscri
22542258
}
22552259

22562260
var span trace.Span
2257-
if iTraceID, ok := cloudEvent[pubsub.TraceIDField]; ok {
2261+
iTraceID := cloudEvent[pubsub.TraceParentField]
2262+
if iTraceID == nil {
2263+
iTraceID = cloudEvent[pubsub.TraceIDField]
2264+
}
2265+
if iTraceID != nil {
22582266
if traceID, ok := iTraceID.(string); ok {
22592267
sc, _ := diag.SpanContextFromW3CString(traceID)
22602268
spanName := fmt.Sprintf("pubsub/%s", msg.topic)

0 commit comments

Comments
 (0)