Skip to content

Commit

Permalink
refactor(tracer): Starting to add open telemetric metric
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Aug 15, 2023
1 parent 6594553 commit 3729c22
Show file tree
Hide file tree
Showing 21 changed files with 174 additions and 134 deletions.
4 changes: 2 additions & 2 deletions cmd/http/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func newAdapter(config configuration, client client) (adapter, error) {
var output adapter
var err error

output.amqp, err = amqphandler.New(config.amqHandler, client.amqp, client.tracer.GetTracer("amqp_handler"), amqpHandler)
output.amqp, err = amqphandler.New(config.amqHandler, client.amqp, client.telemetry.GetTracer("amqp_handler"), amqpHandler)
if err != nil {
return output, fmt.Errorf("amqphandler: %w", err)
}

output.renderer, err = renderer.New(config.renderer, content, nil, client.tracer.GetTracer("renderer"))
output.renderer, err = renderer.New(config.renderer, content, nil, client.telemetry.GetTracer("renderer"))
if err != nil {
return output, fmt.Errorf("renderer: %w", err)
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/prometheus"
"github.com/ViBiOh/httputils/v4/pkg/redis"
"github.com/ViBiOh/httputils/v4/pkg/request"
"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
)

type client struct {
redis redis.Client
tracer tracer.App
telemetry telemetry.App
amqp *amqp.Client
prometheus *prometheus.App
health *health.App
Expand All @@ -31,24 +31,24 @@ func newClient(ctx context.Context, config configuration) (client, error) {

logger.Init(config.logger)

output.tracer, err = tracer.New(ctx, config.tracer)
output.telemetry, err = telemetry.New(ctx, config.telemetry)
if err != nil {
return output, fmt.Errorf("tracer: %w", err)
return output, fmt.Errorf("telemetry: %w", err)
}

request.AddTracerToDefaultClient(output.tracer.GetProvider())
request.AddTracerToDefaultClient(output.telemetry.GetProvider())

output.prometheus = prometheus.New(config.prometheus)
output.health = health.New(config.health)

prometheusRegisterer := output.prometheus.Registerer()

output.redis, err = redis.New(config.redis, output.tracer.GetProvider())
output.redis, err = redis.New(config.redis, output.telemetry.GetProvider())
if err != nil {
return output, fmt.Errorf("redis: %w", err)
}

output.amqp, err = amqp.New(config.amqp, prometheusRegisterer, output.tracer.GetTracer("amqp"))
output.amqp, err = amqp.New(config.amqp, prometheusRegisterer, output.telemetry.GetTracer("amqp"))
if err != nil && !errors.Is(err, amqp.ErrNoConfig) {
return output, fmt.Errorf("amqp: %w", err)
}
Expand All @@ -62,5 +62,5 @@ func (c client) Close(ctx context.Context) {

c.amqp.Close()
c.redis.Close()
c.tracer.Close(ctx)
c.telemetry.Close(ctx)
}
6 changes: 3 additions & 3 deletions cmd/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/redis"
"github.com/ViBiOh/httputils/v4/pkg/renderer"
"github.com/ViBiOh/httputils/v4/pkg/server"
"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
)

type configuration struct {
Expand All @@ -27,7 +27,7 @@ type configuration struct {
alcotest alcotest.Config
logger logger.Config
prometheus prometheus.Config
tracer tracer.Config
telemetry telemetry.Config
owasp owasp.Config
cors cors.Config
amqp amqp.Config
Expand All @@ -47,7 +47,7 @@ func newConfig() (configuration, error) {
alcotest: alcotest.Flags(fs, ""),
logger: logger.Flags(fs, "logger"),
prometheus: prometheus.Flags(fs, "prometheus"),
tracer: tracer.Flags(fs, "tracer"),
telemetry: telemetry.Flags(fs, "telemetry"),
owasp: owasp.Flags(fs, "", flags.NewOverride("Csp", "default-src 'self'; base-uri 'self'; script-src 'httputils-nonce'")),
cors: cors.Flags(fs, "cors"),
amqp: amqp.Flags(fs, "amqp"),
Expand Down
2 changes: 1 addition & 1 deletion cmd/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func main() {
ctxEnd := client.health.End(ctx)

go promServer.Start(ctxEnd, "prometheus", client.prometheus.Handler())
go appServer.Start(ctxEnd, "http", httputils.Handler(adapter.renderer.Handler(handler.template), client.health, recoverer.Middleware, client.prometheus.Middleware, client.tracer.Middleware, owasp.New(config.owasp).Middleware, cors.New(config.cors).Middleware))
go appServer.Start(ctxEnd, "http", httputils.Handler(adapter.renderer.Handler(handler.template), client.health, recoverer.Middleware, client.prometheus.Middleware, client.telemetry.Middleware, owasp.New(config.owasp).Middleware, cors.New(config.cors).Middleware))

client.health.WaitForTermination(appServer.Done())
server.GracefulWait(appServer.Done(), promServer.Done(), adapter.amqp.Done())
Expand Down
8 changes: 4 additions & 4 deletions cmd/http/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/cache"
"github.com/ViBiOh/httputils/v4/pkg/renderer"
"github.com/ViBiOh/httputils/v4/pkg/request"
"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
"go.opentelemetry.io/otel/trace"
)

Expand All @@ -19,10 +19,10 @@ type port struct {
func newPort(config configuration, client client, adapter adapter) port {
var output port

portTracer := client.tracer.GetTracer("port")
portTracer := client.telemetry.GetTracer("port")

simpleCache := cache.New(client.redis, func(id string) string { return id }, func(ctx context.Context, id string) (string, error) {
_, end := tracer.StartSpan(ctx, portTracer, "onMiss", trace.WithSpanKind(trace.SpanKindInternal))
_, end := telemetry.StartSpan(ctx, portTracer, "onMiss", trace.WithSpanKind(trace.SpanKindInternal))
defer end(nil)

return id, nil
Expand All @@ -31,7 +31,7 @@ func newPort(config configuration, client client, adapter adapter) port {
output.template = func(w http.ResponseWriter, r *http.Request) (renderer.Page, error) {
var err error

ctx, end := tracer.StartSpan(r.Context(), portTracer, "handler", trace.WithSpanKind(trace.SpanKindInternal))
ctx, end := telemetry.StartSpan(r.Context(), portTracer, "handler", trace.WithSpanKind(trace.SpanKindInternal))
defer end(&err)

resp, err := request.Get("https://api.vibioh.fr/dump/").Send(ctx, nil)
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ require (
github.com/zeebo/xxh3 v1.0.2
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.39.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
go.opentelemetry.io/otel/sdk/metric v0.39.0
go.opentelemetry.io/otel/trace v1.16.0
go.uber.org/mock v0.2.0
golang.org/x/crypto v0.12.0
Expand Down Expand Up @@ -45,6 +47,7 @@ require (
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5 // indirect
github.com/tdewolff/parse/v2 v2.6.7 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.39.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s=
go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4=
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 h1:t4ZwRPU+emrcvM2e9DHd0Fsf0JTPVcbfa/BhTDF03d0=
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0/go.mod h1:vLarbg68dH2Wa77g71zmKQqlQ8+8Rq3GRG31uc0WcWI=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.39.0 h1:f6BwB2OACc3FCbYVznctQ9V6KK7Vq6CjmYXJ7DeSs4E=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.39.0/go.mod h1:UqL5mZ3qs6XYhDnZaW1Ps4upD+PX6LipH40AoeuIlwU=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.39.0 h1:rm+Fizi7lTM2UefJ1TO347fSRcwmIsUAaZmYmIGBRAo=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.39.0/go.mod h1:sWFbI3jJ+6JdjOVepA5blpv/TJ20Hw+26561iMbWcwU=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 h1:cbsD4cUcviQGXdw8+bo5x2wazq10SKz8hEbtCRPcU78=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0/go.mod h1:JgXSGah17croqhJfhByOLVY719k1emAXC8MVhCIJlRs=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0 h1:TVQp/bboR4mhZSav+MdgXB8FaRho1RC8UwVn3T0vjVc=
Expand All @@ -105,6 +109,8 @@ go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26
go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4=
go.opentelemetry.io/otel/sdk v1.16.0 h1:Z1Ok1YsijYL0CSJpHt4cS3wDDh7p572grzNrBMiMWgE=
go.opentelemetry.io/otel/sdk v1.16.0/go.mod h1:tMsIuKXuuIWPBAOrH+eHtvhTL+SntFtXF9QD68aP6p4=
go.opentelemetry.io/otel/sdk/metric v0.39.0 h1:Kun8i1eYf48kHH83RucG93ffz0zGV1sh46FAScOTuDI=
go.opentelemetry.io/otel/sdk/metric v0.39.0/go.mod h1:piDIRgjcK7u0HCL5pCA4e74qpK/jk3NiUoAHATVAmiI=
go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs=
go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0=
go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
Expand Down
6 changes: 3 additions & 3 deletions pkg/amqp/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/ViBiOh/flags"
prom "github.com/ViBiOh/httputils/v4/pkg/prometheus"
"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
"github.com/prometheus/client_golang/prometheus"
amqp "github.com/rabbitmq/amqp091-go"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -97,7 +97,7 @@ func NewFromURI(uri string, prefetch int, prometheusRegister prometheus.Register
}

func (c *Client) Publish(ctx context.Context, payload amqp.Publishing, exchange, routingKey string) (err error) {
_, end := tracer.StartSpan(ctx, c.tracer, "publish", trace.WithSpanKind(trace.SpanKindProducer))
_, end := telemetry.StartSpan(ctx, c.tracer, "publish", trace.WithSpanKind(trace.SpanKindProducer))
defer end(&err)

c.mutex.RLock()
Expand All @@ -115,7 +115,7 @@ func (c *Client) Publish(ctx context.Context, payload amqp.Publishing, exchange,
}

func (c *Client) PublishJSON(ctx context.Context, item any, exchange, routingKey string) (err error) {
ctx, end := tracer.StartSpan(ctx, c.tracer, "publish_json", trace.WithSpanKind(trace.SpanKindProducer))
ctx, end := telemetry.StartSpan(ctx, c.tracer, "publish_json", trace.WithSpanKind(trace.SpanKindProducer))
defer end(&err)

payload, err := json.Marshal(item)
Expand Down
4 changes: 2 additions & 2 deletions pkg/amqp/exclusive.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"time"

"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
amqp "github.com/rabbitmq/amqp091-go"
"go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -61,7 +61,7 @@ func (c *Client) shouldCreateExclusiveQueue(name string) (bool, int) {
}

func (c *Client) Exclusive(ctx context.Context, name string, timeout time.Duration, action func(context.Context) error) (acquired bool, err error) {
ctx, end := tracer.StartSpan(ctx, c.tracer, "exclusive", trace.WithSpanKind(trace.SpanKindClient))
ctx, end := telemetry.StartSpan(ctx, c.tracer, "exclusive", trace.WithSpanKind(trace.SpanKindClient))
defer end(&err)

var channel *amqp.Channel
Expand Down
4 changes: 2 additions & 2 deletions pkg/amqphandler/amqphandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/ViBiOh/flags"
amqpclient "github.com/ViBiOh/httputils/v4/pkg/amqp"
"github.com/ViBiOh/httputils/v4/pkg/recoverer"
"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
amqp "github.com/rabbitmq/amqp091-go"
"go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -132,7 +132,7 @@ func (a *App) Start(ctx context.Context) {
func (a *App) handleMessage(ctx context.Context, log *slog.Logger, message amqp.Delivery) {
var err error

ctx, end := tracer.StartSpan(ctx, a.tracer, "handle", trace.WithSpanKind(trace.SpanKindConsumer))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "handle", trace.WithSpanKind(trace.SpanKindConsumer))
defer end(&err)

defer recoverer.Error(&err)
Expand Down
10 changes: 5 additions & 5 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/ViBiOh/httputils/v4/pkg/cntxt"
"github.com/ViBiOh/httputils/v4/pkg/model"
"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
"github.com/redis/go-redis/v9"
"go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -110,7 +110,7 @@ func (a *App[K, V]) Get(ctx context.Context, id K) (V, error) {

var err error

ctx, end := tracer.StartSpan(ctx, a.tracer, "get", trace.WithSpanKind(trace.SpanKindInternal))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "get", trace.WithSpanKind(trace.SpanKindInternal))
defer end(&err)

key := a.toKey(id)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (a *App[K, V]) EvictOnSuccess(ctx context.Context, item K, err error) error
return err
}

ctx, end := tracer.StartSpan(ctx, a.tracer, "evict", trace.WithSpanKind(trace.SpanKindInternal))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "evict", trace.WithSpanKind(trace.SpanKindInternal))
defer end(&err)

key := a.toKey(item)
Expand All @@ -155,7 +155,7 @@ func (a *App[K, V]) EvictOnSuccess(ctx context.Context, item K, err error) error
func (a *App[K, V]) fetch(ctx context.Context, id K) (V, error) {
var err error

ctx, end := tracer.StartSpan(ctx, a.tracer, "fetch", trace.WithSpanKind(trace.SpanKindInternal))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "fetch", trace.WithSpanKind(trace.SpanKindInternal))
defer end(&err)

value, err := a.onMiss(ctx, id)
Expand Down Expand Up @@ -193,7 +193,7 @@ func (a *App[K, V]) extendTTL(ctx context.Context, keys ...string) {
}

func loggerWithTrace(ctx context.Context, key string) *slog.Logger {
return tracer.AddTraceToLogger(trace.SpanFromContext(ctx), slog.Default()).With("key", key)
return telemetry.AddTraceToLogger(trace.SpanFromContext(ctx), slog.Default()).With("key", key)
}

func logUnmarshallError(ctx context.Context, key string, err error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/ViBiOh/httputils/v4/pkg/cntxt"
"github.com/ViBiOh/httputils/v4/pkg/concurrent"
"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
"go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -40,7 +40,7 @@ func (a App[K, V]) List(ctx context.Context, onMissError func(K, error) bool, it
return a.listRawMany(ctx, items)
}

ctx, end := tracer.StartSpan(ctx, a.tracer, "list", trace.WithSpanKind(trace.SpanKindInternal))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "list", trace.WithSpanKind(trace.SpanKindInternal))
defer end(&err)

keys, values := a.getValues(ctx, items)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cache/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
"go.opentelemetry.io/otel/trace"
)

Expand All @@ -20,7 +20,7 @@ func (a App[K, V]) Store(ctx context.Context, id K, value V) error {
}

func (a App[K, V]) store(ctx context.Context, id K, value V) (err error) {
ctx, end := tracer.StartSpan(ctx, a.tracer, "store", trace.WithSpanKind(trace.SpanKindInternal))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "store", trace.WithSpanKind(trace.SpanKindInternal))
defer end(&err)

payload, err := a.serializer.Encode(value)
Expand All @@ -38,7 +38,7 @@ func (a App[K, V]) store(ctx context.Context, id K, value V) (err error) {
func (a App[K, V]) storeMany(ctx context.Context, ids []K, values []V, indexes IndexedItems[K]) error {
var err error

ctx, end := tracer.StartSpan(ctx, a.tracer, "store_many", trace.WithSpanKind(trace.SpanKindInternal))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "store_many", trace.WithSpanKind(trace.SpanKindInternal))
defer end(&err)

pipeline := a.write.Pipeline()
Expand Down
4 changes: 2 additions & 2 deletions pkg/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
"go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -290,7 +290,7 @@ func (c *Cron) Start(ctx context.Context, action func(context.Context) error) {
run := func() {
var err error

ctx, end := tracer.StartSpan(ctx, c.tracer, "cron")
ctx, end := telemetry.StartSpan(ctx, c.tracer, "cron")
defer end(&err)

if c.semaphoreApp == nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/ViBiOh/flags"
"github.com/ViBiOh/httputils/v4/pkg/tracer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
Expand Down Expand Up @@ -139,7 +139,7 @@ func (a App) DoAtomic(ctx context.Context, action func(context.Context) error) (
return errors.New("no action provided")
}

ctx, end := tracer.StartSpan(ctx, a.tracer, "transaction", trace.WithSpanKind(trace.SpanKindClient))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "transaction", trace.WithSpanKind(trace.SpanKindClient))
defer end(&err)

if readTx(ctx) != nil {
Expand All @@ -165,7 +165,7 @@ func (a App) DoAtomic(ctx context.Context, action func(context.Context) error) (
}

func (a App) Query(ctx context.Context, query string, args ...any) (rows pgx.Rows, err error) {
ctx, end := tracer.StartSpan(ctx, a.tracer, "query", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.String("query", query)))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "query", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.String("query", query)))
defer end(&err)

if tx := readTx(ctx); tx != nil {
Expand Down Expand Up @@ -198,7 +198,7 @@ func (a App) List(ctx context.Context, scanner func(pgx.Rows) error, query strin
}

func (a App) QueryRow(ctx context.Context, query string, args ...any) pgx.Row {
ctx, end := tracer.StartSpan(ctx, a.tracer, "query_row", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.String("query", query)))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "query_row", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.String("query", query)))
defer end(nil)

if tx := readTx(ctx); tx != nil {
Expand Down Expand Up @@ -255,7 +255,7 @@ func (a App) One(ctx context.Context, query string, args ...any) error {
}

func (a App) exec(ctx context.Context, query string, args ...any) (command pgconn.CommandTag, err error) {
ctx, end := tracer.StartSpan(ctx, a.tracer, "exec", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.String("query", query)))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "exec", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.String("query", query)))
defer end(&err)

tx := readTx(ctx)
Expand Down Expand Up @@ -288,7 +288,7 @@ func (bc *feeder) Err() error {
}

func (a App) Bulk(ctx context.Context, fetcher func() ([]any, error), schema, table string, columns ...string) (err error) {
ctx, end := tracer.StartSpan(ctx, a.tracer, "bulk", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.String("schema", schema), attribute.String("table", table)))
ctx, end := telemetry.StartSpan(ctx, a.tracer, "bulk", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.String("schema", schema), attribute.String("table", table)))
defer end(&err)

tx := readTx(ctx)
Expand Down
Loading

0 comments on commit 3729c22

Please sign in to comment.