I have a parent span starting whenever I make my gRPC call, the code snippet goes like this.
type spanctxkey struct{} // pushing span in context to fetch it from anywhere
func StartSpan(ctx context.Context, operationName string) (context.Context, Span) {
parentSpan := sentry.StartSpan(ctx, operationName, sentry.TransactionName(operationName))
return context.WithValue(originalSpan.Context(), spanctxkey{}, &span), Span{
originalSpan,
}
}
Now, I am trying to get the current running span, from another package, so that I can start a child Span, the code for that is.
func getCurrentSpan(ctx context.Context) *Span {
if span, ok := ctx.Value(spanctxkey{}).(*Span); ok {
return span
}
return nil
}
childSpan := getCurrentSpan(ctx)
fmt.Println(childSpan)
When I try to print it, it prints nil
, I am confused on to why the span is getting closed.
Now the question can be that the parent span might be getting closed before the child span , but no, I added some print statements to verify that as well.
--starting span before making a grpc call---
-- starting span before querying the db ---
--closing span after querying the db---
--closing span after making a grpc call---