Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit153e96f

Browse files
authored
fix: use consistent tracer name (#4117)
1 parent794b88f commit153e96f

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

‎coderd/coderd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ func New(options *Options) *API {
198198

199199
apps:=func(r chi.Router) {
200200
r.Use(
201+
tracing.Middleware(api.TracerProvider),
201202
httpmw.RateLimitPerMinute(options.APIRateLimit),
202-
tracing.HTTPMW(api.TracerProvider),
203203
httpmw.ExtractAPIKey(options.Database,oauthConfigs,true),
204204
httpmw.ExtractUserParam(api.Database),
205205
// Extracts the <workspace.agent> from the url
@@ -227,9 +227,9 @@ func New(options *Options) *API {
227227
})
228228
})
229229
r.Use(
230+
tracing.Middleware(api.TracerProvider),
230231
// Specific routes can specify smaller limits.
231232
httpmw.RateLimitPerMinute(options.APIRateLimit),
232-
tracing.HTTPMW(api.TracerProvider),
233233
)
234234
r.Get("/",func(w http.ResponseWriter,r*http.Request) {
235235
httpapi.Write(w,http.StatusOK, codersdk.Response{

‎coderd/tracing/httpmw.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@ import (
1010
"go.opentelemetry.io/otel/trace"
1111
)
1212

13-
// HTTPMW adds tracing to http routes.
14-
funcHTTPMW(tracerProvider trace.TracerProvider)func(http.Handler) http.Handler {
13+
// Middleware adds tracing to http routes.
14+
funcMiddleware(tracerProvider trace.TracerProvider)func(http.Handler) http.Handler {
15+
vartracer trace.Tracer
16+
iftracerProvider!=nil {
17+
tracer=tracerProvider.Tracer(TracerName)
18+
}
1519
returnfunc(next http.Handler) http.Handler {
1620
returnhttp.HandlerFunc(func(rw http.ResponseWriter,r*http.Request) {
17-
iftracerProvider==nil {
21+
iftracer==nil {
1822
next.ServeHTTP(rw,r)
1923
return
2024
}
2125

2226
// start span with default span name. Span name will be updated to "method route" format once request finishes.
23-
ctx,span:=tracerProvider.Tracer("").Start(r.Context(),fmt.Sprintf("%s %s",r.Method,r.RequestURI))
27+
ctx,span:=tracer.Start(r.Context(),fmt.Sprintf("%s %s",r.Method,r.RequestURI))
2428
deferspan.End()
2529
r=r.WithContext(ctx)
2630

@@ -59,5 +63,5 @@ func EndHTTPSpan(r *http.Request, status int, span trace.Span) {
5963
}
6064

6165
funcStartSpan(ctx context.Context,opts...trace.SpanStartOption) (context.Context, trace.Span) {
62-
returntrace.SpanFromContext(ctx).TracerProvider().Tracer("").Start(ctx,FuncNameSkip(1),opts...)
66+
returntrace.SpanFromContext(ctx).TracerProvider().Tracer(TracerName).Start(ctx,FuncNameSkip(1),opts...)
6367
}

‎coderd/tracing/util.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"strings"
66
)
77

8+
constTracerName="coderd"
9+
810
funcFuncName()string {
911
fnpc,_,_,ok:=runtime.Caller(1)
1012
if!ok {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp