-
Notifications
You must be signed in to change notification settings - Fork 21
Trace ID not carried forward from parent #39
Description
I'm experiencing an issue when publishing traces that run longer than the publish interval. The first batch of spans is properly sent to X-Ray, but subsequent spans are dropped.
This seems to be happening because a new AmazonTraceID is generated on every publish bundle, regardless of whether the span has a parent or not. Specifically, convertToAmazonTraceID injects a fresh timestamp each time, resulting in a new unique trace ID, even when we want to be carrying forward the existing trace ID.
Included is a small program demonstrating the issue. I added some logging to opencensus-go-exporter-aws (not shown here) so we can see what's getting sent to AWS. The results show two different trace IDs.
{"id":"d4da803036c02aea","name":"/baz","start_time":1583097340.570889,"trace_id":"1-5e5c25fd-2693fa8d418af12b90e0377d","end_time":1583097340.570891,"parent_id":"779447f3308cda9b","type":"subsegment"}
{"id":"779447f3308cda9b","name":"/bar","start_time":1583097340.570889,"trace_id":"1-5e5c25fe-2693fa8d418af12b90e0377d","end_time":1583097342.571168,"parent_id":"1a4e0eb62b588a4d","type":"subsegment"}
{"id":"1a4e0eb62b588a4d","name":"/foo","start_time":1583097340.570887,"trace_id":"1-5e5c25fe-2693fa8d418af12b90e0377d","end_time":1583097342.571286,"service":{"version":"latest"}}
package main
import (
"context"
"fmt"
"log"
"os"
"time"
"contrib.go.opencensus.io/exporter/aws"
"go.opencensus.io/trace"
)
func main() {
if os.Getenv("AWS_ACCESS_KEY_ID") == "" {
log.Fatalln("AWS_ACCESS_KEY_ID must be set")
}
if os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
log.Fatalln("AWS_SECRET_ACCESS_KEY must be set")
}
if os.Getenv("AWS_DEFAULT_REGION") == "" {
log.Fatalln("AWS_DEFAULT_REGION must be set")
}
ctx := context.Background()
{
exporter, err := aws.NewExporter(
aws.WithVersion("latest"),
// one-second publish interval
//aws.WithInterval(time.Second*1),
aws.WithOnExport(func(in aws.OnExport) {
fmt.Println("publishing trace,", in.TraceID)
}),
)
if err != nil {
log.Fatal(err)
}
trace.RegisterExporter(exporter)
// For demoing purposes, always sample.
trace.ApplyConfig(trace.Config{
DefaultSampler: trace.AlwaysSample(),
})
defer exporter.Close()
}
ctx, span := trace.StartSpan(ctx, "/foo")
bar(ctx)
span.End()
}
func bar(ctx context.Context) {
ctx, span := trace.StartSpan(ctx, "/bar")
baz(ctx)
// 2-second long task
time.Sleep(time.Second * 2)
defer span.End()
}
func baz(ctx context.Context) {
ctx, span := trace.StartSpan(ctx, "/baz")
defer span.End()
}
