File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -55,17 +55,17 @@ func TestTraceStarter(t *testing.T) {
5555 ctx , span := GetTracer ().Start (ctx , "span1" )
5656 defer span .End ()
5757 func (ctx context.Context ) {
58- ctx , span := GetTracer ().Start (ctx , "spanA" )
58+ _ , span := GetTracer ().Start (ctx , "spanA" )
5959 defer span .End ()
6060 }(ctx )
6161 func (ctx context.Context ) {
62- ctx , span := GetTracer ().Start (ctx , "spanB" )
62+ _ , span := GetTracer ().Start (ctx , "spanB" )
6363 defer span .End ()
6464 }(ctx )
6565 }(ctx )
6666
6767 func (ctx context.Context ) {
68- ctx , span := GetTracer ().Start (ctx , "span2" )
68+ _ , span := GetTracer ().Start (ctx , "span2" )
6969 defer span .End ()
7070 }(ctx )
7171
@@ -79,11 +79,11 @@ func TestTraceStarter(t *testing.T) {
7979 }
8080 }
8181 collectSpanNames ("" , span .internalSpans [0 ].(* testTraceSpan ).vendorSpan )
82- assert .Equal (t , []string ([] string {
82+ assert .Equal (t , []string {
8383 "/root" ,
8484 "/root/span1" ,
8585 "/root/span1/spanA" ,
8686 "/root/span1/spanB" ,
8787 "/root/span2" ,
88- }) , spanFullNames )
88+ }, spanFullNames )
8989}
Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ type contextKeyType struct{}
1515
1616var contextKey contextKeyType
1717
18+ // StartContextSpan starts a trace span in Gitea's web request context
19+ // Due to the design limitation of Gitea's web framework, it can't use `context.WithValue` to bind a new span into a new context.
20+ // So here we use our "reqctx" framework to achieve the same result: web request context could always see the latest "span".
1821func StartContextSpan (ctx reqctx.RequestContext , spanName string ) (* gtprof.TraceSpan , func ()) {
1922 curTraceSpan := gtprof .GetContextSpan (ctx )
2023 _ , newTraceSpan := gtprof .GetTracer ().Start (ctx , spanName )
You can’t perform that action at this time.
0 commit comments