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

Commitcc5e0b0

Browse files
committed
Add span formatter
1 parent2005d4c commitcc5e0b0

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎coderd/tracing/postgres.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package tracing
22

33
import (
4+
"context"
5+
"fmt"
6+
"strings"
7+
48
"github.com/nhatthm/otelsql"
5-
semconv"go.opentelemetry.io/otel/semconv/v1.4.0"
9+
semconv"go.opentelemetry.io/otel/semconv/v1.7.0"
610
"go.opentelemetry.io/otel/trace"
711
"golang.org/x/xerrors"
812
)
@@ -17,10 +21,22 @@ func PostgresDriver(tp trace.TracerProvider, service string) (string, error) {
1721
otelsql.TraceQueryWithoutArgs(),
1822
otelsql.WithSystem(semconv.DBSystemPostgreSQL),
1923
otelsql.WithTracerProvider(tp),
24+
otelsql.WithSpanNameFormatter(formatPostgresSpan),
2025
)
2126
iferr!=nil {
2227
return"",xerrors.Errorf("registering postgres tracing driver: %w",err)
2328
}
2429

2530
returndriverName,nil
2631
}
32+
33+
funcformatPostgresSpan(ctx context.Context,opstring)string {
34+
constqPrefix="-- name: "
35+
q:=otelsql.QueryFromContext(ctx)
36+
ifq==""||!strings.HasPrefix(q,qPrefix) {
37+
returnstrings.ToUpper(op)
38+
}
39+
40+
s:=strings.Split(strings.TrimPrefix(q,qPrefix)," ")[0]
41+
returnfmt.Sprintf("%s %s",strings.ToUpper(op),s)
42+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp