summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/extra
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/uptrace/bun/extra')
-rw-r--r--vendor/github.com/uptrace/bun/extra/bunjson/json.go26
-rw-r--r--vendor/github.com/uptrace/bun/extra/bunjson/provider.go43
-rw-r--r--vendor/github.com/uptrace/bun/extra/bunotel/LICENSE24
-rw-r--r--vendor/github.com/uptrace/bun/extra/bunotel/README.md3
-rw-r--r--vendor/github.com/uptrace/bun/extra/bunotel/option.go63
-rw-r--r--vendor/github.com/uptrace/bun/extra/bunotel/otel.go196
6 files changed, 0 insertions, 355 deletions
diff --git a/vendor/github.com/uptrace/bun/extra/bunjson/json.go b/vendor/github.com/uptrace/bun/extra/bunjson/json.go
deleted file mode 100644
index eff9d3f0e..000000000
--- a/vendor/github.com/uptrace/bun/extra/bunjson/json.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package bunjson
-
-import (
- "encoding/json"
- "io"
-)
-
-var _ Provider = (*StdProvider)(nil)
-
-type StdProvider struct{}
-
-func (StdProvider) Marshal(v interface{}) ([]byte, error) {
- return json.Marshal(v)
-}
-
-func (StdProvider) Unmarshal(data []byte, v interface{}) error {
- return json.Unmarshal(data, v)
-}
-
-func (StdProvider) NewEncoder(w io.Writer) Encoder {
- return json.NewEncoder(w)
-}
-
-func (StdProvider) NewDecoder(r io.Reader) Decoder {
- return json.NewDecoder(r)
-}
diff --git a/vendor/github.com/uptrace/bun/extra/bunjson/provider.go b/vendor/github.com/uptrace/bun/extra/bunjson/provider.go
deleted file mode 100644
index 7f810e122..000000000
--- a/vendor/github.com/uptrace/bun/extra/bunjson/provider.go
+++ /dev/null
@@ -1,43 +0,0 @@
-package bunjson
-
-import (
- "io"
-)
-
-var provider Provider = StdProvider{}
-
-func SetProvider(p Provider) {
- provider = p
-}
-
-type Provider interface {
- Marshal(v interface{}) ([]byte, error)
- Unmarshal(data []byte, v interface{}) error
- NewEncoder(w io.Writer) Encoder
- NewDecoder(r io.Reader) Decoder
-}
-
-type Decoder interface {
- Decode(v interface{}) error
- UseNumber()
-}
-
-type Encoder interface {
- Encode(v interface{}) error
-}
-
-func Marshal(v interface{}) ([]byte, error) {
- return provider.Marshal(v)
-}
-
-func Unmarshal(data []byte, v interface{}) error {
- return provider.Unmarshal(data, v)
-}
-
-func NewEncoder(w io.Writer) Encoder {
- return provider.NewEncoder(w)
-}
-
-func NewDecoder(r io.Reader) Decoder {
- return provider.NewDecoder(r)
-}
diff --git a/vendor/github.com/uptrace/bun/extra/bunotel/LICENSE b/vendor/github.com/uptrace/bun/extra/bunotel/LICENSE
deleted file mode 100644
index 7ec81810c..000000000
--- a/vendor/github.com/uptrace/bun/extra/bunotel/LICENSE
+++ /dev/null
@@ -1,24 +0,0 @@
-Copyright (c) 2021 Vladimir Mihailenco. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/uptrace/bun/extra/bunotel/README.md b/vendor/github.com/uptrace/bun/extra/bunotel/README.md
deleted file mode 100644
index 1773ecf02..000000000
--- a/vendor/github.com/uptrace/bun/extra/bunotel/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# OpenTelemetry instrumentation for Bun
-
-See [example](../../example/opentelemetry) for details.
diff --git a/vendor/github.com/uptrace/bun/extra/bunotel/option.go b/vendor/github.com/uptrace/bun/extra/bunotel/option.go
deleted file mode 100644
index 4824f3863..000000000
--- a/vendor/github.com/uptrace/bun/extra/bunotel/option.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package bunotel
-
-import (
- "github.com/uptrace/bun"
- "go.opentelemetry.io/otel/attribute"
- "go.opentelemetry.io/otel/metric"
- semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
- "go.opentelemetry.io/otel/trace"
-)
-
-type Option func(h *QueryHook)
-
-// WithAttributes configures attributes that are used to create a span.
-func WithAttributes(attrs ...attribute.KeyValue) Option {
- return func(h *QueryHook) {
- h.attrs = append(h.attrs, attrs...)
- }
-}
-
-// WithDBName configures a db.name attribute.
-func WithDBName(name string) Option {
- return func(h *QueryHook) {
- h.attrs = append(h.attrs, semconv.DBNameKey.String(name))
- }
-}
-
-// WithFormattedQueries enables formatting of the query that is added
-// as the statement attribute to the trace.
-// This means that all placeholders and arguments will be filled first
-// and the query will contain all information as sent to the database.
-func WithFormattedQueries(format bool) Option {
- return func(h *QueryHook) {
- h.formatQueries = format
- }
-}
-
-// WithSpanNameFormatter takes a function that determines the span name
-// for a given query event.
-func WithSpanNameFormatter(f func(*bun.QueryEvent) string) Option {
- return func(h *QueryHook) {
- h.spanNameFormatter = f
- }
-}
-
-// WithTracerProvider returns an Option to use the TracerProvider when
-// creating a Tracer.
-func WithTracerProvider(tp trace.TracerProvider) Option {
- return func(h *QueryHook) {
- if tp != nil {
- h.tracer = tp.Tracer("github.com/uptrace/bun")
- }
- }
-}
-
-// WithMeterProvider returns an Option to use the MeterProvider when
-// creating a Meter.
-func WithMeterProvider(mp metric.MeterProvider) Option {
- return func(h *QueryHook) {
- if mp != nil {
- h.meter = mp.Meter("github.com/uptrace/bun")
- }
- }
-}
diff --git a/vendor/github.com/uptrace/bun/extra/bunotel/otel.go b/vendor/github.com/uptrace/bun/extra/bunotel/otel.go
deleted file mode 100644
index db098bc6a..000000000
--- a/vendor/github.com/uptrace/bun/extra/bunotel/otel.go
+++ /dev/null
@@ -1,196 +0,0 @@
-package bunotel
-
-import (
- "context"
- "database/sql"
- "runtime"
- "strings"
- "time"
-
- "go.opentelemetry.io/otel"
- "go.opentelemetry.io/otel/attribute"
- "go.opentelemetry.io/otel/codes"
- "go.opentelemetry.io/otel/metric"
- semconv "go.opentelemetry.io/otel/semconv/v1.20.0"
- "go.opentelemetry.io/otel/trace"
-
- "github.com/uptrace/bun"
- "github.com/uptrace/bun/dialect"
- "github.com/uptrace/bun/internal"
- "github.com/uptrace/bun/schema"
- "github.com/uptrace/opentelemetry-go-extra/otelsql"
-)
-
-type QueryHook struct {
- attrs []attribute.KeyValue
- formatQueries bool
- tracer trace.Tracer
- meter metric.Meter
- queryHistogram metric.Int64Histogram
- spanNameFormatter func(*bun.QueryEvent) string
-}
-
-var _ bun.QueryHook = (*QueryHook)(nil)
-
-func NewQueryHook(opts ...Option) *QueryHook {
- h := new(QueryHook)
- for _, opt := range opts {
- opt(h)
- }
- if h.tracer == nil {
- h.tracer = otel.Tracer("github.com/uptrace/bun")
- }
- if h.meter == nil {
- h.meter = otel.Meter("github.com/uptrace/bun")
- }
- h.queryHistogram, _ = h.meter.Int64Histogram(
- "go.sql.query_timing",
- metric.WithDescription("Timing of processed queries"),
- metric.WithUnit("milliseconds"),
- )
- return h
-}
-
-func (h *QueryHook) Init(db *bun.DB) {
- labels := make([]attribute.KeyValue, 0, len(h.attrs)+1)
- labels = append(labels, h.attrs...)
- if sys := dbSystem(db); sys.Valid() {
- labels = append(labels, sys)
- }
-
- otelsql.ReportDBStatsMetrics(db.DB, otelsql.WithAttributes(labels...))
-}
-
-func (h *QueryHook) BeforeQuery(ctx context.Context, event *bun.QueryEvent) context.Context {
- ctx, _ = h.tracer.Start(ctx, "", trace.WithSpanKind(trace.SpanKindClient))
- return ctx
-}
-
-func (h *QueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent) {
- operation := event.Operation()
- dbOperation := semconv.DBOperationKey.String(operation)
-
- labels := make([]attribute.KeyValue, 0, len(h.attrs)+2)
- labels = append(labels, h.attrs...)
- labels = append(labels, dbOperation)
- if event.IQuery != nil {
- if tableName := event.IQuery.GetTableName(); tableName != "" {
- labels = append(labels, semconv.DBSQLTableKey.String(tableName))
- }
- }
-
- dur := time.Since(event.StartTime)
- h.queryHistogram.Record(ctx, dur.Milliseconds(), metric.WithAttributes(labels...))
-
- span := trace.SpanFromContext(ctx)
- if !span.IsRecording() {
- return
- }
-
- name := operation
- if h.spanNameFormatter != nil {
- name = h.spanNameFormatter(event)
- }
- span.SetName(name)
- defer span.End()
-
- query := h.eventQuery(event)
- fn, file, line := funcFileLine("github.com/uptrace/bun")
-
- attrs := make([]attribute.KeyValue, 0, 10)
- attrs = append(attrs, h.attrs...)
- attrs = append(attrs,
- dbOperation,
- semconv.DBStatementKey.String(query),
- semconv.CodeFunctionKey.String(fn),
- semconv.CodeFilepathKey.String(file),
- semconv.CodeLineNumberKey.Int(line),
- )
-
- if sys := dbSystem(event.DB); sys.Valid() {
- attrs = append(attrs, sys)
- }
- if event.Result != nil {
- rows, _ := event.Result.RowsAffected()
- attrs = append(attrs, attribute.Int64("db.rows_affected", rows))
- }
-
- switch event.Err {
- case nil, sql.ErrNoRows, sql.ErrTxDone:
- // ignore
- default:
- span.RecordError(event.Err)
- span.SetStatus(codes.Error, event.Err.Error())
- }
-
- span.SetAttributes(attrs...)
-}
-
-func funcFileLine(pkg string) (string, string, int) {
- const depth = 16
- var pcs [depth]uintptr
- n := runtime.Callers(3, pcs[:])
- ff := runtime.CallersFrames(pcs[:n])
-
- var fn, file string
- var line int
- for {
- f, ok := ff.Next()
- if !ok {
- break
- }
- fn, file, line = f.Function, f.File, f.Line
- if !strings.Contains(fn, pkg) {
- break
- }
- }
-
- if ind := strings.LastIndexByte(fn, '/'); ind != -1 {
- fn = fn[ind+1:]
- }
-
- return fn, file, line
-}
-
-func (h *QueryHook) eventQuery(event *bun.QueryEvent) string {
- const softQueryLimit = 8000
- const hardQueryLimit = 16000
-
- var query string
-
- if h.formatQueries && len(event.Query) <= softQueryLimit {
- query = event.Query
- } else {
- query = unformattedQuery(event)
- }
-
- if len(query) > hardQueryLimit {
- query = query[:hardQueryLimit]
- }
-
- return query
-}
-
-func unformattedQuery(event *bun.QueryEvent) string {
- if event.IQuery != nil {
- if b, err := event.IQuery.AppendQuery(schema.NewNopFormatter(), nil); err == nil {
- return internal.String(b)
- }
- }
- return string(event.QueryTemplate)
-}
-
-func dbSystem(db *bun.DB) attribute.KeyValue {
- switch db.Dialect().Name() {
- case dialect.PG:
- return semconv.DBSystemPostgreSQL
- case dialect.MySQL:
- return semconv.DBSystemMySQL
- case dialect.SQLite:
- return semconv.DBSystemSqlite
- case dialect.MSSQL:
- return semconv.DBSystemMSSQL
- default:
- return attribute.KeyValue{}
- }
-}