mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
improve trace feature for package gdb/gredis; add trace example cases
This commit is contained in:
11
contrib/trace/jaeger/go.mod
Normal file
11
contrib/trace/jaeger/go.mod
Normal file
@ -0,0 +1,11 @@
|
||||
module github.com/gogf/gf/contrib/trace/jaeger/v2
|
||||
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.0.0-rc2
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0
|
||||
go.opentelemetry.io/otel/sdk v1.3.0
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
35
contrib/trace/jaeger/go.sum
Normal file
35
contrib/trace/jaeger/go.sum
Normal file
@ -0,0 +1,35 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.1 h1:DX7uPQ4WgAWfoh+NGGlbJQswnYIVvz0SRlLS3rPZQDA=
|
||||
github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/stdr v1.2.0 h1:j4LrlVXgrbIWO83mmQUnK0Hi+YnbD+vzrE1z/EphbFE=
|
||||
github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI=
|
||||
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y=
|
||||
go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc=
|
||||
go.opentelemetry.io/otel/sdk v1.3.0 h1:3278edCoH89MEJ0Ky8WQXVmDQv3FX4ZJ3Pp+9fJreAI=
|
||||
go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs=
|
||||
go.opentelemetry.io/otel/trace v1.3.0 h1:doy8Hzb1RJ+I3yFhtDmwNc7tIyw1tNMOIsyPzp1NOGY=
|
||||
go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk=
|
||||
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
62
contrib/trace/jaeger/jaeger.go
Normal file
62
contrib/trace/jaeger/jaeger.go
Normal file
@ -0,0 +1,62 @@
|
||||
package jaeger
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/jaeger"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
"go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/semconv/v1.7.0"
|
||||
)
|
||||
|
||||
// Init initializes and registers jaeger to global TracerProvider.
|
||||
//
|
||||
// The output parameter `flush` is used for waiting exported trace spans to be uploaded,
|
||||
// which is useful if your program is ending, and you do not want to lose recent spans.
|
||||
func Init(serviceName, endpoint string) (*trace.TracerProvider, error) {
|
||||
// Create the Jaeger exporter
|
||||
var endpointOption jaeger.EndpointOption
|
||||
if strings.HasPrefix(endpoint, "http") {
|
||||
// HTTP.
|
||||
endpointOption = jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(endpoint))
|
||||
} else {
|
||||
// UDP.
|
||||
match, err := gregex.MatchString(`(.+):(\d+)`, endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(match) < 3 {
|
||||
return nil, gerror.NewCodef(
|
||||
gcode.CodeInvalidParameter, `invalid endpoint "%s"`, endpoint,
|
||||
)
|
||||
}
|
||||
var (
|
||||
host = match[1]
|
||||
port = match[2]
|
||||
)
|
||||
endpointOption = jaeger.WithAgentEndpoint(
|
||||
jaeger.WithAgentHost(host), jaeger.WithAgentPort(port),
|
||||
)
|
||||
}
|
||||
exp, err := jaeger.New(endpointOption)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tp := trace.NewTracerProvider(
|
||||
// Always be sure to batch in production.
|
||||
trace.WithBatcher(exp),
|
||||
// Record information about this application in a Resource.
|
||||
trace.WithResource(resource.NewWithAttributes(
|
||||
semconv.SchemaURL,
|
||||
semconv.ServiceNameKey.String(serviceName),
|
||||
)),
|
||||
)
|
||||
// Register our TracerProvider as the global so any imported
|
||||
// instrumentation in the future will default to using it.
|
||||
otel.SetTracerProvider(tp)
|
||||
return tp, nil
|
||||
}
|
||||
86
database/gdb/gdb_core_trace.go
Normal file
86
database/gdb/gdb_core_trace.go
Normal file
@ -0,0 +1,86 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
//
|
||||
|
||||
package gdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/semconv/v1.4.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
)
|
||||
|
||||
const (
|
||||
traceInstrumentName = "github.com/gogf/gf/v2/database/gdb"
|
||||
traceAttrDbType = "db.type"
|
||||
traceAttrDbHost = "db.host"
|
||||
traceAttrDbPort = "db.port"
|
||||
traceAttrDbName = "db.name"
|
||||
traceAttrDbUser = "db.user"
|
||||
traceAttrDbLink = "db.link"
|
||||
traceAttrDbGroup = "db.group"
|
||||
traceEventDbExecution = "db.execution"
|
||||
traceEventDbExecutionSql = "db.execution.sql"
|
||||
traceEventDbExecutionCost = "db.execution.cost"
|
||||
traceEventDbExecutionRows = "db.execution.rows"
|
||||
traceEventDbExecutionTxID = "db.execution.txid"
|
||||
traceEventDbExecutionType = "db.execution.type"
|
||||
)
|
||||
|
||||
// addSqlToTracing adds sql information to tracer if it's enabled.
|
||||
func (c *Core) traceSpanEnd(ctx context.Context, span trace.Span, sql *Sql) {
|
||||
if gtrace.IsUsingDefaultProvider() || !gtrace.IsTracingInternal() {
|
||||
return
|
||||
}
|
||||
if sql.Error != nil {
|
||||
span.SetStatus(codes.Error, fmt.Sprintf(`%+v`, sql.Error))
|
||||
}
|
||||
labels := make([]attribute.KeyValue, 0)
|
||||
labels = append(labels, gtrace.CommonLabels()...)
|
||||
labels = append(labels,
|
||||
attribute.String(traceAttrDbType, c.db.GetConfig().Type),
|
||||
semconv.DBStatementKey.String(sql.Format),
|
||||
)
|
||||
if c.db.GetConfig().Host != "" {
|
||||
labels = append(labels, attribute.String(traceAttrDbHost, c.db.GetConfig().Host))
|
||||
}
|
||||
if c.db.GetConfig().Port != "" {
|
||||
labels = append(labels, attribute.String(traceAttrDbPort, c.db.GetConfig().Port))
|
||||
}
|
||||
if c.db.GetConfig().Name != "" {
|
||||
labels = append(labels, attribute.String(traceAttrDbName, c.db.GetConfig().Name))
|
||||
}
|
||||
if c.db.GetConfig().User != "" {
|
||||
labels = append(labels, attribute.String(traceAttrDbUser, c.db.GetConfig().User))
|
||||
}
|
||||
if filteredLink := c.db.FilteredLink(); filteredLink != "" {
|
||||
labels = append(labels, attribute.String(traceAttrDbLink, c.db.FilteredLink()))
|
||||
}
|
||||
if group := c.db.GetGroup(); group != "" {
|
||||
labels = append(labels, attribute.String(traceAttrDbGroup, group))
|
||||
}
|
||||
span.SetAttributes(labels...)
|
||||
events := []attribute.KeyValue{
|
||||
attribute.String(traceEventDbExecutionSql, sql.Format),
|
||||
attribute.String(traceEventDbExecutionCost, fmt.Sprintf(`%d ms`, sql.End-sql.Start)),
|
||||
attribute.String(traceEventDbExecutionRows, fmt.Sprintf(`%d`, sql.RowsAffected)),
|
||||
}
|
||||
if sql.IsTransaction {
|
||||
if v := ctx.Value(transactionIdForLoggerCtx); v != nil {
|
||||
events = append(events, attribute.String(
|
||||
traceEventDbExecutionTxID, fmt.Sprintf(`%d`, v.(uint64)),
|
||||
))
|
||||
}
|
||||
}
|
||||
events = append(events, attribute.String(traceEventDbExecutionType, sql.Type))
|
||||
span.AddEvent(traceEventDbExecution, trace.WithAttributes(events...))
|
||||
}
|
||||
@ -1,95 +0,0 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
//
|
||||
|
||||
package gdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
)
|
||||
|
||||
const (
|
||||
tracingInstrumentName = "github.com/gogf/gf/v2/database/gdb"
|
||||
tracingAttrDbType = "db.type"
|
||||
tracingAttrDbHost = "db.host"
|
||||
tracingAttrDbPort = "db.port"
|
||||
tracingAttrDbName = "db.name"
|
||||
tracingAttrDbUser = "db.user"
|
||||
tracingAttrDbLink = "db.link"
|
||||
tracingAttrDbGroup = "db.group"
|
||||
tracingEventDbExecution = "db.execution"
|
||||
tracingEventDbExecutionSql = "db.execution.sql"
|
||||
tracingEventDbExecutionCost = "db.execution.cost"
|
||||
tracingEventDbExecutionRows = "db.execution.rows"
|
||||
tracingEventDbExecutionTxID = "db.execution.txid"
|
||||
tracingEventDbExecutionType = "db.execution.type"
|
||||
)
|
||||
|
||||
// addSqlToTracing adds sql information to tracer if it's enabled.
|
||||
func (c *Core) addSqlToTracing(ctx context.Context, sql *Sql) {
|
||||
if gtrace.IsUsingDefaultProvider() || !gtrace.IsTracingInternal() {
|
||||
return
|
||||
}
|
||||
tr := otel.GetTracerProvider().Tracer(
|
||||
tracingInstrumentName,
|
||||
trace.WithInstrumentationVersion(gf.VERSION),
|
||||
)
|
||||
ctx, span := tr.Start(ctx, sql.Type, trace.WithSpanKind(trace.SpanKindInternal))
|
||||
defer span.End()
|
||||
|
||||
if sql.Error != nil {
|
||||
span.SetStatus(codes.Error, fmt.Sprintf(`%+v`, sql.Error))
|
||||
}
|
||||
labels := make([]attribute.KeyValue, 0)
|
||||
labels = append(labels, gtrace.CommonLabels()...)
|
||||
labels = append(labels,
|
||||
attribute.String(tracingAttrDbType, c.db.GetConfig().Type),
|
||||
semconv.DBStatementKey.String(sql.Format),
|
||||
)
|
||||
if c.db.GetConfig().Host != "" {
|
||||
labels = append(labels, attribute.String(tracingAttrDbHost, c.db.GetConfig().Host))
|
||||
}
|
||||
if c.db.GetConfig().Port != "" {
|
||||
labels = append(labels, attribute.String(tracingAttrDbPort, c.db.GetConfig().Port))
|
||||
}
|
||||
if c.db.GetConfig().Name != "" {
|
||||
labels = append(labels, attribute.String(tracingAttrDbName, c.db.GetConfig().Name))
|
||||
}
|
||||
if c.db.GetConfig().User != "" {
|
||||
labels = append(labels, attribute.String(tracingAttrDbUser, c.db.GetConfig().User))
|
||||
}
|
||||
if filteredLink := c.db.FilteredLink(); filteredLink != "" {
|
||||
labels = append(labels, attribute.String(tracingAttrDbLink, c.db.FilteredLink()))
|
||||
}
|
||||
if group := c.db.GetGroup(); group != "" {
|
||||
labels = append(labels, attribute.String(tracingAttrDbGroup, group))
|
||||
}
|
||||
span.SetAttributes(labels...)
|
||||
events := []attribute.KeyValue{
|
||||
attribute.String(tracingEventDbExecutionSql, sql.Format),
|
||||
attribute.String(tracingEventDbExecutionCost, fmt.Sprintf(`%d ms`, sql.End-sql.Start)),
|
||||
attribute.String(tracingEventDbExecutionRows, fmt.Sprintf(`%d`, sql.RowsAffected)),
|
||||
}
|
||||
if sql.IsTransaction {
|
||||
if v := ctx.Value(transactionIdForLoggerCtx); v != nil {
|
||||
events = append(events, attribute.String(
|
||||
tracingEventDbExecutionTxID, fmt.Sprintf(`%d`, v.(uint64)),
|
||||
))
|
||||
}
|
||||
}
|
||||
events = append(events, attribute.String(tracingEventDbExecutionType, sql.Type))
|
||||
span.AddEvent(tracingEventDbExecution, trace.WithAttributes(events...))
|
||||
}
|
||||
@ -11,12 +11,15 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// Query commits one query SQL to underlying driver and returns the execution result.
|
||||
@ -137,6 +140,12 @@ func (c *Core) DoCommit(ctx context.Context, in DoCommitInput) (out DoCommitOutp
|
||||
cancelFuncForTimeout context.CancelFunc
|
||||
timestampMilli1 = gtime.TimestampMilli()
|
||||
)
|
||||
|
||||
// Trace span start.
|
||||
tr := otel.GetTracerProvider().Tracer(traceInstrumentName, trace.WithInstrumentationVersion(gf.VERSION))
|
||||
ctx, span := tr.Start(ctx, in.Type, trace.WithSpanKind(trace.SpanKindInternal))
|
||||
defer span.End()
|
||||
|
||||
// Execution cased by type.
|
||||
switch in.Type {
|
||||
case SqlTypeBegin:
|
||||
@ -232,8 +241,11 @@ func (c *Core) DoCommit(ctx context.Context, in DoCommitInput) (out DoCommitOutp
|
||||
IsTransaction: in.IsTransaction,
|
||||
}
|
||||
)
|
||||
// Tracing and logging.
|
||||
c.addSqlToTracing(ctx, sqlObj)
|
||||
|
||||
// Tracing.
|
||||
c.traceSpanEnd(ctx, span, sqlObj)
|
||||
|
||||
// Logging.
|
||||
if c.db.GetDebug() {
|
||||
c.writeSqlToLogger(ctx, sqlObj)
|
||||
}
|
||||
|
||||
@ -10,10 +10,13 @@ import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// RedisConn is a connection of redis client.
|
||||
@ -25,6 +28,9 @@ type RedisConn struct {
|
||||
// Do send a command to the server and returns the received reply.
|
||||
// It uses json.Marshal for struct/slice/map type values before committing them to redis.
|
||||
func (c *RedisConn) Do(ctx context.Context, command string, args ...interface{}) (reply *gvar.Var, err error) {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
for k, v := range args {
|
||||
var (
|
||||
reflectInfo = utils.OriginTypeAndKind(v)
|
||||
@ -43,12 +49,18 @@ func (c *RedisConn) Do(ctx context.Context, command string, args ...interface{})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Trace span start.
|
||||
tr := otel.GetTracerProvider().Tracer(traceInstrumentName, trace.WithInstrumentationVersion(gf.VERSION))
|
||||
_, span := tr.Start(ctx, "Redis."+command, trace.WithSpanKind(trace.SpanKindInternal))
|
||||
defer span.End()
|
||||
|
||||
timestampMilli1 := gtime.TimestampMilli()
|
||||
reply, err = c.conn.Do(ctx, command, args...)
|
||||
timestampMilli2 := gtime.TimestampMilli()
|
||||
|
||||
// Tracing.
|
||||
c.addTracingItem(ctx, &tracingItem{
|
||||
// Trace span end.
|
||||
c.traceSpanEnd(ctx, span, &traceItem{
|
||||
err: err,
|
||||
command: command,
|
||||
args: args,
|
||||
|
||||
66
database/gredis/gredis_redis_trace.go
Normal file
66
database/gredis/gredis_redis_trace.go
Normal file
@ -0,0 +1,66 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package gredis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
)
|
||||
|
||||
// traceItem holds the information for redis trace.
|
||||
type traceItem struct {
|
||||
err error
|
||||
command string
|
||||
args []interface{}
|
||||
costMilli int64
|
||||
}
|
||||
|
||||
const (
|
||||
traceInstrumentName = "github.com/gogf/gf/v2/database/gredis"
|
||||
traceAttrRedisAddress = "redis.address"
|
||||
traceAttrRedisDb = "redis.db"
|
||||
traceEventRedisExecution = "redis.execution"
|
||||
traceEventRedisExecutionCommand = "redis.execution.command"
|
||||
traceEventRedisExecutionCost = "redis.execution.cost"
|
||||
traceEventRedisExecutionArguments = "redis.execution.arguments"
|
||||
)
|
||||
|
||||
// traceSpanEnd checks and adds redis trace information to OpenTelemetry.
|
||||
func (c *RedisConn) traceSpanEnd(ctx context.Context, span trace.Span, item *traceItem) {
|
||||
if gtrace.IsUsingDefaultProvider() || !gtrace.IsTracingInternal() {
|
||||
return
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
if item.err != nil {
|
||||
span.SetStatus(codes.Error, fmt.Sprintf(`%+v`, item.err))
|
||||
}
|
||||
|
||||
span.SetAttributes(gtrace.CommonLabels()...)
|
||||
|
||||
if adapter, ok := c.redis.GetAdapter().(*AdapterGoRedis); ok {
|
||||
span.SetAttributes(
|
||||
attribute.String(traceAttrRedisAddress, adapter.config.Address),
|
||||
attribute.Int(traceAttrRedisDb, adapter.config.Db),
|
||||
)
|
||||
}
|
||||
|
||||
jsonBytes, _ := json.Marshal(item.args)
|
||||
span.AddEvent(traceEventRedisExecution, trace.WithAttributes(
|
||||
attribute.String(traceEventRedisExecutionCommand, item.command),
|
||||
attribute.String(traceEventRedisExecutionCost, fmt.Sprintf(`%d ms`, item.costMilli)),
|
||||
attribute.String(traceEventRedisExecutionArguments, string(jsonBytes)),
|
||||
))
|
||||
}
|
||||
@ -1,74 +0,0 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package gredis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
)
|
||||
|
||||
// tracingItem holds the information for redis tracing.
|
||||
type tracingItem struct {
|
||||
err error
|
||||
command string
|
||||
args []interface{}
|
||||
costMilli int64
|
||||
}
|
||||
|
||||
const (
|
||||
tracingInstrumentName = "github.com/gogf/gf/v2/database/gredis"
|
||||
tracingAttrRedisAddress = "redis.address"
|
||||
tracingAttrRedisDb = "redis.db"
|
||||
tracingEventRedisExecution = "redis.execution"
|
||||
tracingEventRedisExecutionCommand = "redis.execution.command"
|
||||
tracingEventRedisExecutionCost = "redis.execution.cost"
|
||||
tracingEventRedisExecutionArguments = "redis.execution.arguments"
|
||||
)
|
||||
|
||||
// addTracingItem checks and adds redis tracing information to OpenTelemetry.
|
||||
func (c *RedisConn) addTracingItem(ctx context.Context, item *tracingItem) {
|
||||
if gtrace.IsUsingDefaultProvider() || !gtrace.IsTracingInternal() {
|
||||
return
|
||||
}
|
||||
tr := otel.GetTracerProvider().Tracer(
|
||||
tracingInstrumentName,
|
||||
trace.WithInstrumentationVersion(gf.VERSION),
|
||||
)
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
_, span := tr.Start(ctx, "Redis."+item.command, trace.WithSpanKind(trace.SpanKindInternal))
|
||||
defer span.End()
|
||||
if item.err != nil {
|
||||
span.SetStatus(codes.Error, fmt.Sprintf(`%+v`, item.err))
|
||||
}
|
||||
|
||||
span.SetAttributes(gtrace.CommonLabels()...)
|
||||
|
||||
if adapter, ok := c.redis.GetAdapter().(*AdapterGoRedis); ok {
|
||||
span.SetAttributes(
|
||||
attribute.String(tracingAttrRedisAddress, adapter.config.Address),
|
||||
attribute.Int(tracingAttrRedisDb, adapter.config.Db),
|
||||
)
|
||||
}
|
||||
|
||||
jsonBytes, _ := json.Marshal(item.args)
|
||||
span.AddEvent(tracingEventRedisExecution, trace.WithAttributes(
|
||||
attribute.String(tracingEventRedisExecutionCommand, item.command),
|
||||
attribute.String(tracingEventRedisExecutionCost, fmt.Sprintf(`%d ms`, item.costMilli)),
|
||||
attribute.String(tracingEventRedisExecutionArguments, string(jsonBytes)),
|
||||
))
|
||||
}
|
||||
@ -4,10 +4,16 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/registry/etcd/v2 v2.0.0-rc2
|
||||
github.com/gogf/gf/v2 v2.0.0-rc2
|
||||
github.com/gogf/gf/contrib/trace/jaeger/v2 v2.0.0-rc2
|
||||
github.com/gogf/gf/v2 v2.0.0-rc2.0.20220128082344-48b5f3789470
|
||||
github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/golang/protobuf v1.5.2
|
||||
google.golang.org/grpc v1.44.0
|
||||
)
|
||||
|
||||
replace (
|
||||
github.com/gogf/gf/contrib/registry/etcd/v2 => ../contrib/registry/etcd/
|
||||
github.com/gogf/gf/contrib/trace/jaeger/v2 => ../contrib/trace/jaeger/
|
||||
github.com/gogf/gf/v2 => ../
|
||||
)
|
||||
|
||||
@ -1,18 +1,24 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
|
||||
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
|
||||
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
@ -21,6 +27,11 @@ github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
|
||||
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
|
||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
|
||||
@ -34,7 +45,10 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
|
||||
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
@ -50,10 +64,12 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.1 h1:DX7uPQ4WgAWfoh+NGGlbJQswnYIVvz0SRlLS3rPZQDA=
|
||||
github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/stdr v1.2.0 h1:j4LrlVXgrbIWO83mmQUnK0Hi+YnbD+vzrE1z/EphbFE=
|
||||
github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg=
|
||||
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
@ -61,6 +77,10 @@ github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LB
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gogf/katyusha v0.3.0/go.mod h1:AknlfKGS7HjZfLiz74Nd/eL2uq7bg+9aucZgfvXw8vQ=
|
||||
github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29 h1:s28bNu6QekQG3XFFB3G6YV3AGvQz8Uj4lBu/WXIeF28=
|
||||
github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29/go.mod h1:vb72az4+b2cn1gHfJ5n2sESbfQ0jM7iO55DNt2RQ7mc=
|
||||
github.com/gogf/katyusha/example v0.0.0-20220128090236-a633147589ae/go.mod h1:DSPRXlHUWIRpXa2v8eKpVh0eGwdCiqXBng3wnn8B62g=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
@ -115,13 +135,15 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
|
||||
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
@ -163,11 +185,15 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
@ -187,16 +213,24 @@ go.etcd.io/etcd/client/v3 v3.5.1 h1:oImGuV5LGKjCqXdjkMHCyWa5OO1gYKCnC/1sgdfj1Uk=
|
||||
go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q=
|
||||
go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y=
|
||||
go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc=
|
||||
go.opentelemetry.io/otel/sdk v1.3.0 h1:3278edCoH89MEJ0Ky8WQXVmDQv3FX4ZJ3Pp+9fJreAI=
|
||||
go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs=
|
||||
go.opentelemetry.io/otel/trace v1.3.0 h1:doy8Hzb1RJ+I3yFhtDmwNc7tIyw1tNMOIsyPzp1NOGY=
|
||||
go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U=
|
||||
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
|
||||
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
|
||||
go.uber.org/zap v1.20.0 h1:N4oPlghZwYG55MlU6LXk/Zp00FVNE9X9wrYO8CEs4lc=
|
||||
go.uber.org/zap v1.20.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
@ -205,10 +239,13 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@ -228,8 +265,9 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@ -267,15 +305,21 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
|
||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y=
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@ -289,6 +333,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=
|
||||
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@ -301,15 +347,19 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c h1:wtujag7C+4D6KMoulW9YauvK2lgdvCMS260jsqqBXr0=
|
||||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
|
||||
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 h1:YxHp5zqIcAShDEvRr5/0rVESVS+njYF68PSdazrNLJo=
|
||||
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
|
||||
google.golang.org/grpc v1.44.0 h1:weqSxi/TMs1SqFRMHCtBgXRs8k3X39QIDEZ0pRcttUg=
|
||||
google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
@ -320,10 +370,12 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
|
||||
6
example/trace/grpc_with_db/client/config.yaml
Normal file
6
example/trace/grpc_with_db/client/config.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
registry:
|
||||
endpoints: ["127.0.0.1:2379"]
|
||||
|
||||
|
||||
|
||||
78
example/trace/grpc_with_db/client/main.go
Normal file
78
example/trace/grpc_with_db/client/main.go
Normal file
@ -0,0 +1,78 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/example/trace/grpc_with_db/protobuf/user"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
const (
|
||||
ServiceName = "grpc-client-with-db"
|
||||
JaegerUdpEndpoint = "localhost:6831"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var ctx = gctx.New()
|
||||
tp, err := jaeger.Init(ServiceName, JaegerUdpEndpoint)
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
defer tp.Shutdown(ctx)
|
||||
|
||||
StartRequests()
|
||||
}
|
||||
|
||||
func StartRequests() {
|
||||
ctx, span := gtrace.NewSpan(gctx.New(), "StartRequests")
|
||||
defer span.End()
|
||||
|
||||
var client, err = user.NewClient()
|
||||
if err != nil {
|
||||
g.Log().Fatalf(ctx, `%+v`, err)
|
||||
}
|
||||
|
||||
// Baggage.
|
||||
ctx = gtrace.SetBaggageValue(ctx, "uid", 100)
|
||||
|
||||
// Insert.
|
||||
insertRes, err := client.User().Insert(ctx, &user.InsertReq{
|
||||
Name: "john",
|
||||
})
|
||||
if err != nil {
|
||||
g.Log().Fatalf(ctx, `%+v`, err)
|
||||
}
|
||||
g.Log().Info(ctx, "insert id:", insertRes.Id)
|
||||
|
||||
// Query.
|
||||
queryRes, err := client.User().Query(ctx, &user.QueryReq{
|
||||
Id: insertRes.Id,
|
||||
})
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, `%+v`, err)
|
||||
return
|
||||
}
|
||||
g.Log().Info(ctx, "query result:", queryRes)
|
||||
|
||||
// Delete.
|
||||
_, err = client.User().Delete(ctx, &user.DeleteReq{
|
||||
Id: insertRes.Id,
|
||||
})
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, `%+v`, err)
|
||||
return
|
||||
}
|
||||
g.Log().Info(ctx, "delete id:", insertRes.Id)
|
||||
|
||||
// Delete with error.
|
||||
_, err = client.User().Delete(ctx, &user.DeleteReq{
|
||||
Id: -1,
|
||||
})
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, `%+v`, err)
|
||||
return
|
||||
}
|
||||
g.Log().Info(ctx, "delete id:", -1)
|
||||
|
||||
}
|
||||
27
example/trace/grpc_with_db/protobuf/user/client.go
Normal file
27
example/trace/grpc_with_db/protobuf/user/client.go
Normal file
@ -0,0 +1,27 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/gogf/katyusha/krpc"
|
||||
)
|
||||
|
||||
const (
|
||||
AppID = "demo"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
conn *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewClient(options ...grpc.DialOption) (*Client, error) {
|
||||
conn, err := krpc.Client.NewGrpcClientConn(AppID, options...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Client{conn: conn}, nil
|
||||
}
|
||||
|
||||
func (c *Client) User() UserClient {
|
||||
return NewUserClient(c.conn)
|
||||
}
|
||||
1335
example/trace/grpc_with_db/protobuf/user/user.pb.go
Normal file
1335
example/trace/grpc_with_db/protobuf/user/user.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
38
example/trace/grpc_with_db/protocol/user/user.proto
Normal file
38
example/trace/grpc_with_db/protocol/user/user.proto
Normal file
@ -0,0 +1,38 @@
|
||||
// protoc --gofast_out=plugins=grpc:. protocol/user/*.proto -I/Users/john/Workspace/Go/GOPATH/src -I/Users/john/Workspace/Go/GOPATH/src/gitee.com/johng/katyusha/.examples/tracing
|
||||
syntax = "proto3";
|
||||
|
||||
package user;
|
||||
|
||||
option go_package = "protobuf/user";
|
||||
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
// User service for tracing demo.
|
||||
service User {
|
||||
rpc Insert(InsertReq) returns (InsertRes) {}
|
||||
rpc Query(QueryReq) returns (QueryRes) {}
|
||||
rpc Delete(DeleteReq) returns (DeleteRes) {}
|
||||
}
|
||||
|
||||
message InsertReq {
|
||||
string Name = 1 [(gogoproto.moretags) = 'v:"required#Please input user name."'];
|
||||
}
|
||||
|
||||
message InsertRes {
|
||||
int32 Id = 1;
|
||||
}
|
||||
|
||||
message QueryReq {
|
||||
int32 Id = 1 [(gogoproto.moretags) = 'v:"min:1#User id is required for querying."'];
|
||||
}
|
||||
|
||||
message QueryRes {
|
||||
int32 Id = 1;
|
||||
string Name = 2;
|
||||
}
|
||||
|
||||
message DeleteReq {
|
||||
int32 Id = 1 [(gogoproto.moretags) = 'v:"min:1#User id is required for deleting."'];
|
||||
}
|
||||
|
||||
message DeleteRes {}
|
||||
33
example/trace/grpc_with_db/server/config.yaml
Normal file
33
example/trace/grpc_with_db/server/config.yaml
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
registry:
|
||||
endpoints: ["127.0.0.1:2379"]
|
||||
|
||||
grpcserver:
|
||||
name: "demo"
|
||||
logStdout: true
|
||||
errorLogEnabled: true
|
||||
accessLogEnabled: true
|
||||
errorStack: true
|
||||
|
||||
# MySQL.
|
||||
database:
|
||||
logger:
|
||||
level: "all"
|
||||
stdout: true
|
||||
default:
|
||||
link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
|
||||
debug: true
|
||||
|
||||
# Redis.
|
||||
redis:
|
||||
default:
|
||||
address: 127.0.0.1:6379
|
||||
db: 0
|
||||
cache:
|
||||
address: 127.0.0.1:6379
|
||||
db: 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
81
example/trace/grpc_with_db/server/main.go
Normal file
81
example/trace/grpc_with_db/server/main.go
Normal file
@ -0,0 +1,81 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/example/trace/grpc_with_db/protobuf/user"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/katyusha/krpc"
|
||||
)
|
||||
|
||||
type server struct{}
|
||||
|
||||
const (
|
||||
ServiceName = "grpc-server-with-db"
|
||||
JaegerUdpEndpoint = "localhost:6831"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var ctx = gctx.New()
|
||||
tp, err := jaeger.Init(ServiceName, JaegerUdpEndpoint)
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
defer tp.Shutdown(ctx)
|
||||
|
||||
// Set ORM cache adapter with redis.
|
||||
g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(g.Redis()))
|
||||
|
||||
s := krpc.Server.NewGrpcServer()
|
||||
user.RegisterUserServer(s.Server, &server{})
|
||||
s.Run()
|
||||
}
|
||||
|
||||
// Insert is a route handler for inserting user info into database.
|
||||
func (s *server) Insert(ctx context.Context, req *user.InsertReq) (res *user.InsertRes, err error) {
|
||||
result, err := g.Model("user").Ctx(ctx).Insert(g.Map{
|
||||
"name": req.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id, _ := result.LastInsertId()
|
||||
res = &user.InsertRes{
|
||||
Id: int32(id),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Query is a route handler for querying user info. It firstly retrieves the info from redis,
|
||||
// if there's nothing in the redis, it then does db select.
|
||||
func (s *server) Query(ctx context.Context, req *user.QueryReq) (res *user.QueryRes, err error) {
|
||||
err = g.Model("user").Ctx(ctx).Cache(gdb.CacheOption{
|
||||
Duration: 5 * time.Second,
|
||||
Name: s.userCacheKey(req.Id),
|
||||
Force: false,
|
||||
}).WherePri(req.Id).Scan(&res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Delete is a route handler for deleting specified user info.
|
||||
func (s *server) Delete(ctx context.Context, req *user.DeleteReq) (res *user.DeleteRes, err error) {
|
||||
err = g.Model("user").Ctx(ctx).Cache(gdb.CacheOption{
|
||||
Duration: -1,
|
||||
Name: s.userCacheKey(req.Id),
|
||||
Force: false,
|
||||
}).WherePri(req.Id).Scan(&res)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *server) userCacheKey(id int32) string {
|
||||
return fmt.Sprintf(`userInfo:%d`, id)
|
||||
}
|
||||
6
example/trace/grpc_with_db/sql.sql
Normal file
6
example/trace/grpc_with_db/sql.sql
Normal file
@ -0,0 +1,6 @@
|
||||
DROP TABLE IF EXISTS `user`;
|
||||
CREATE TABLE `user` (
|
||||
`uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(45) NOT NULL,
|
||||
PRIMARY KEY (`uid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
34
example/trace/http/client/main.go
Normal file
34
example/trace/http/client/main.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
const (
|
||||
ServiceName = "http-client"
|
||||
JaegerUdpEndpoint = "localhost:6831"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var ctx = gctx.New()
|
||||
tp, err := jaeger.Init(ServiceName, JaegerUdpEndpoint)
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
defer tp.Shutdown(ctx)
|
||||
|
||||
StartRequests()
|
||||
}
|
||||
|
||||
func StartRequests() {
|
||||
ctx, span := gtrace.NewSpan(gctx.New(), "StartRequests")
|
||||
defer span.End()
|
||||
|
||||
ctx = gtrace.SetBaggageValue(ctx, "name", "john")
|
||||
|
||||
content := g.Client().GetContent(ctx, "http://127.0.0.1:8199/hello")
|
||||
g.Log().Print(ctx, content)
|
||||
}
|
||||
39
example/trace/http/server/main.go
Normal file
39
example/trace/http/server/main.go
Normal file
@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
const (
|
||||
ServiceName = "http-server"
|
||||
JaegerUdpEndpoint = "localhost:6831"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var ctx = gctx.New()
|
||||
tp, err := jaeger.Init(ServiceName, JaegerUdpEndpoint)
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
defer tp.Shutdown(ctx)
|
||||
|
||||
s := g.Server()
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.GET("/hello", HelloHandler)
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
}
|
||||
|
||||
func HelloHandler(r *ghttp.Request) {
|
||||
ctx, span := gtrace.NewSpan(r.Context(), "HelloHandler")
|
||||
defer span.End()
|
||||
|
||||
value := gtrace.GetBaggageVar(ctx, "name").String()
|
||||
|
||||
r.Response.Write("hello:", value)
|
||||
}
|
||||
77
example/trace/http_with_db/client/main.go
Normal file
77
example/trace/http_with_db/client/main.go
Normal file
@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
const (
|
||||
ServiceName = "http-client-with-db"
|
||||
JaegerUdpEndpoint = "localhost:6831"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var ctx = gctx.New()
|
||||
tp, err := jaeger.Init(ServiceName, JaegerUdpEndpoint)
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
defer tp.Shutdown(ctx)
|
||||
|
||||
StartRequests()
|
||||
}
|
||||
|
||||
func StartRequests() {
|
||||
ctx, span := gtrace.NewSpan(gctx.New(), "StartRequests")
|
||||
defer span.End()
|
||||
|
||||
var (
|
||||
err error
|
||||
client = g.Client()
|
||||
)
|
||||
// Add user info.
|
||||
var insertRes = struct {
|
||||
ghttp.DefaultHandlerResponse
|
||||
Data struct{ Id int64 } `json:"data"`
|
||||
}{}
|
||||
err = client.PostVar(ctx, "http://127.0.0.1:8199/user/insert", g.Map{
|
||||
"name": "john",
|
||||
}).Scan(&insertRes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
g.Log().Info(ctx, "insert result:", insertRes)
|
||||
if insertRes.Data.Id == 0 {
|
||||
g.Log().Error(ctx, "retrieve empty id string")
|
||||
return
|
||||
}
|
||||
|
||||
// Query user info.
|
||||
var queryRes = struct {
|
||||
ghttp.DefaultHandlerResponse
|
||||
Data struct{ User gdb.Record } `json:"data"`
|
||||
}{}
|
||||
err = client.GetVar(ctx, "http://127.0.0.1:8199/user/query", g.Map{
|
||||
"id": insertRes.Data.Id,
|
||||
}).Scan(&queryRes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
g.Log().Info(ctx, "query result:", queryRes)
|
||||
|
||||
// Delete user info.
|
||||
var deleteRes = struct {
|
||||
ghttp.DefaultHandlerResponse
|
||||
}{}
|
||||
err = client.PostVar(ctx, "http://127.0.0.1:8199/user/delete", g.Map{
|
||||
"id": insertRes.Data.Id,
|
||||
}).Scan(&deleteRes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
g.Log().Info(ctx, "delete result:", deleteRes)
|
||||
}
|
||||
23
example/trace/http_with_db/server/config.yaml
Normal file
23
example/trace/http_with_db/server/config.yaml
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
# MySQL.
|
||||
database:
|
||||
logger:
|
||||
level: "all"
|
||||
stdout: true
|
||||
default:
|
||||
link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
|
||||
debug: true
|
||||
|
||||
# Redis.
|
||||
redis:
|
||||
default:
|
||||
address: 127.0.0.1:6379
|
||||
db: 0
|
||||
cache:
|
||||
address: 127.0.0.1:6379
|
||||
db: 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
108
example/trace/http_with_db/server/main.go
Normal file
108
example/trace/http_with_db/server/main.go
Normal file
@ -0,0 +1,108 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
type cTrace struct{}
|
||||
|
||||
const (
|
||||
ServiceName = "http-server-with-db"
|
||||
JaegerUdpEndpoint = "localhost:6831"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var ctx = gctx.New()
|
||||
tp, err := jaeger.Init(ServiceName, JaegerUdpEndpoint)
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
defer tp.Shutdown(ctx)
|
||||
|
||||
// Set ORM cache adapter with redis.
|
||||
g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(g.Redis()))
|
||||
|
||||
// Start HTTP server.
|
||||
s := g.Server()
|
||||
s.Use(ghttp.MiddlewareHandlerResponse)
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.ALL("/user", new(cTrace))
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
}
|
||||
|
||||
type InsertReq struct {
|
||||
Name string `v:"required#Please input user name."`
|
||||
}
|
||||
type InsertRes struct {
|
||||
Id int64
|
||||
}
|
||||
|
||||
// Insert is a route handler for inserting user info into database.
|
||||
func (c *cTrace) Insert(ctx context.Context, req *InsertReq) (res *InsertRes, err error) {
|
||||
result, err := g.Model("user").Ctx(ctx).Insert(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id, _ := result.LastInsertId()
|
||||
res = &InsertRes{
|
||||
Id: id,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type QueryReq struct {
|
||||
Id int `v:"min:1#User id is required for querying"`
|
||||
}
|
||||
type QueryRes struct {
|
||||
User gdb.Record
|
||||
}
|
||||
|
||||
// Query is a route handler for querying user info. It firstly retrieves the info from redis,
|
||||
// if there's nothing in the redis, it then does db select.
|
||||
func (c *cTrace) Query(ctx context.Context, req *QueryReq) (res *QueryRes, err error) {
|
||||
one, err := g.Model("user").Ctx(ctx).Cache(gdb.CacheOption{
|
||||
Duration: 5 * time.Second,
|
||||
Name: c.userCacheKey(req.Id),
|
||||
Force: false,
|
||||
}).WherePri(req.Id).One()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = &QueryRes{
|
||||
User: one,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type DeleteReq struct {
|
||||
Id int `v:"min:1#User id is required for deleting."`
|
||||
}
|
||||
type DeleteRes struct{}
|
||||
|
||||
// Delete is a route handler for deleting specified user info.
|
||||
func (c *cTrace) Delete(ctx context.Context, req *DeleteReq) (res *DeleteRes, err error) {
|
||||
_, err = g.Model("user").Ctx(ctx).Cache(gdb.CacheOption{
|
||||
Duration: -1,
|
||||
Name: c.userCacheKey(req.Id),
|
||||
Force: false,
|
||||
}).WherePri(req.Id).Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *cTrace) userCacheKey(id int) string {
|
||||
return fmt.Sprintf(`userInfo:%d`, id)
|
||||
}
|
||||
6
example/trace/http_with_db/sql.sql
Normal file
6
example/trace/http_with_db/sql.sql
Normal file
@ -0,0 +1,6 @@
|
||||
DROP TABLE IF EXISTS `user`;
|
||||
CREATE TABLE `user` (
|
||||
`uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(45) NOT NULL,
|
||||
PRIMARY KEY (`uid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
91
example/trace/inprocess/main.go
Normal file
91
example/trace/inprocess/main.go
Normal file
@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
)
|
||||
|
||||
const (
|
||||
ServiceName = "inprocess"
|
||||
JaegerUdpEndpoint = "localhost:6831"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var ctx = gctx.New()
|
||||
tp, err := jaeger.Init(ServiceName, JaegerUdpEndpoint)
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
defer tp.Shutdown(ctx)
|
||||
|
||||
ctx, span := gtrace.NewSpan(ctx, "main")
|
||||
defer span.End()
|
||||
|
||||
// Trace 1.
|
||||
user1 := GetUser(ctx, 1)
|
||||
g.Dump(user1)
|
||||
|
||||
// Trace 2.
|
||||
user100 := GetUser(ctx, 100)
|
||||
g.Dump(user100)
|
||||
}
|
||||
|
||||
// GetUser retrieves and returns hard coded user data for demonstration.
|
||||
func GetUser(ctx context.Context, id int) g.Map {
|
||||
ctx, span := gtrace.NewSpan(ctx, "GetUser")
|
||||
defer span.End()
|
||||
m := g.Map{}
|
||||
gutil.MapMerge(
|
||||
m,
|
||||
GetInfo(ctx, id),
|
||||
GetDetail(ctx, id),
|
||||
GetScores(ctx, id),
|
||||
)
|
||||
return m
|
||||
}
|
||||
|
||||
// GetInfo retrieves and returns hard coded user info for demonstration.
|
||||
func GetInfo(ctx context.Context, id int) g.Map {
|
||||
ctx, span := gtrace.NewSpan(ctx, "GetInfo")
|
||||
defer span.End()
|
||||
if id == 100 {
|
||||
return g.Map{
|
||||
"id": 100,
|
||||
"name": "john",
|
||||
"gender": 1,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDetail retrieves and returns hard coded user detail for demonstration.
|
||||
func GetDetail(ctx context.Context, id int) g.Map {
|
||||
ctx, span := gtrace.NewSpan(ctx, "GetDetail")
|
||||
defer span.End()
|
||||
if id == 100 {
|
||||
return g.Map{
|
||||
"site": "https://goframe.org",
|
||||
"email": "john@goframe.org",
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetScores retrieves and returns hard coded user scores for demonstration.
|
||||
func GetScores(ctx context.Context, id int) g.Map {
|
||||
ctx, span := gtrace.NewSpan(ctx, "GetScores")
|
||||
defer span.End()
|
||||
if id == 100 {
|
||||
return g.Map{
|
||||
"math": 100,
|
||||
"english": 60,
|
||||
"chinese": 50,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -25,8 +25,11 @@ func New() context.Context {
|
||||
|
||||
// WithCtx creates and returns a context containing context id upon given parent context `ctx`.
|
||||
func WithCtx(ctx context.Context) context.Context {
|
||||
ctx, span := gtrace.NewSpan(ctx, "gctx.WithCtx")
|
||||
defer span.End()
|
||||
if gtrace.IsUsingDefaultProvider() {
|
||||
var span *gtrace.Span
|
||||
ctx, span = gtrace.NewSpan(ctx, "gctx.WithCtx")
|
||||
defer span.End()
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user