From b7af573a0c43a09b979f139f716a5931d492380a Mon Sep 17 00:00:00 2001 From: David Janowski Date: Mon, 26 Aug 2024 16:44:50 +0200 Subject: [PATCH] feat: Assign new context with span context to address gRPC closure issue --- pkg/plug/grpc.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/plug/grpc.go b/pkg/plug/grpc.go index 715d6d2..d8f15bb 100644 --- a/pkg/plug/grpc.go +++ b/pkg/plug/grpc.go @@ -60,6 +60,8 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation) // gRPC closes the context after the call ended. So the whole scrapping stopped without waiting // by using this method we assign a new context to each new request we get. // This can be used for example to close the context with the given id + ctx = trace.ContextWithSpanContext(context.Background(), trace.NewSpanContext(trace.SpanContextConfig{TraceID: span.SpanContext().TraceID()})) + taskCtx, cancel := context.WithCancel(ctx) s.ctx[id] = cancel span.AddEvent("Created new context for task", trace.WithAttributes(attribute.String("task_id", id)))