Skip to content

Commit 8e5a0ff

Browse files
committed
add comments
1 parent 76c1e13 commit 8e5a0ff

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

modules/gtprof/trace_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff 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
}

modules/web/routing/context.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ type contextKeyType struct{}
1515

1616
var 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".
1821
func StartContextSpan(ctx reqctx.RequestContext, spanName string) (*gtprof.TraceSpan, func()) {
1922
curTraceSpan := gtprof.GetContextSpan(ctx)
2023
_, newTraceSpan := gtprof.GetTracer().Start(ctx, spanName)

0 commit comments

Comments
 (0)