Dry up adding distributed trace headers.
@@ -30,13 +30,7 @@ func startExternal(ctx context.Context, procedure, host string) (context.Context
Library: "Micro",
Host: host,
}
- payload := txn.CreateDistributedTracePayload()
- if txt := payload.Text(); "" != txt {
- md, _ := metadata.FromContext(ctx)
- md = metadata.Copy(md)
- md[newrelic.DistributedTracePayloadHeader] = txt
- ctx = metadata.NewContext(ctx, md)
- }
+ ctx = addDTPayloadToContext(ctx, txn)
}
return ctx, seg
}
@@ -50,6 +44,12 @@ func startMessage(ctx context.Context, topic string) (context.Context, *newrelic
DestinationType: newrelic.MessageTopic,
DestinationName: topic,
}
+ ctx = addDTPayloadToContext(ctx, txn)
+ }
+ return ctx, seg
+}
+
+func addDTPayloadToContext(ctx context.Context, txn newrelic.Transaction) context.Context {
payload := txn.CreateDistributedTracePayload()
if txt := payload.Text(); "" != txt {
md, _ := metadata.FromContext(ctx)
@@ -57,8 +57,7 @@ func startMessage(ctx context.Context, topic string) (context.Context, *newrelic
md[newrelic.DistributedTracePayloadHeader] = txt
ctx = metadata.NewContext(ctx, md)
}
- }
- return ctx, seg
+ return ctx
}
func extractHost(addr string) string {
