feat: port verified messenger from lab 6
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package telemetry
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
type PostgresTracer struct{}
|
||||
|
||||
type queryFinishKey struct{}
|
||||
|
||||
func (PostgresTracer) TraceQueryStart(ctx context.Context, _ *pgx.Conn, _ pgx.TraceQueryStartData) context.Context {
|
||||
ctx, finish := Operation(ctx, "postgresql query", trace.SpanKindClient)
|
||||
return context.WithValue(ctx, queryFinishKey{}, finish)
|
||||
}
|
||||
|
||||
func (PostgresTracer) TraceQueryEnd(ctx context.Context, _ *pgx.Conn, data pgx.TraceQueryEndData) {
|
||||
if finish, ok := ctx.Value(queryFinishKey{}).(func(error)); ok {
|
||||
finish(data.Err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user