mirror of
https://github.com/go-micro/go-micro.git
synced 2025-07-12 22:41:07 +02:00
Rename gomu to micro (#2325)
* Rename Gomu to Micro * docs: Remove license reference in CLI's README
This commit is contained in:
47
cmd/micro/debug/trace/jaeger/jaeger.go
Normal file
47
cmd/micro/debug/trace/jaeger/jaeger.go
Normal file
@ -0,0 +1,47 @@
|
||||
package jaeger
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/opentracing/opentracing-go"
|
||||
jaegercfg "github.com/uber/jaeger-client-go/config"
|
||||
)
|
||||
|
||||
// NewTracer returns a new Jaeger tracer based on the current configuration,
|
||||
// using the given options, and a closer func that can be used to flush buffers
|
||||
// before shutdown.
|
||||
func NewTracer(opts ...Option) (opentracing.Tracer, io.Closer, error) {
|
||||
options := newOptions(opts...)
|
||||
|
||||
cfg := &jaegercfg.Configuration{}
|
||||
if options.FromEnv {
|
||||
c, err := jaegercfg.FromEnv()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
cfg = c
|
||||
}
|
||||
|
||||
if options.Name != "" {
|
||||
cfg.ServiceName = options.Name
|
||||
}
|
||||
|
||||
var jOptions []jaegercfg.Option
|
||||
if options.Logger != nil {
|
||||
jOptions = append(jOptions, jaegercfg.Logger(options.Logger))
|
||||
}
|
||||
if options.Metrics != nil {
|
||||
jOptions = append(jOptions, jaegercfg.Metrics(options.Metrics))
|
||||
}
|
||||
|
||||
tracer, closer, err := cfg.NewTracer(jOptions...)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if options.GlobalTracer {
|
||||
opentracing.SetGlobalTracer(tracer)
|
||||
}
|
||||
|
||||
return tracer, closer, nil
|
||||
}
|
76
cmd/micro/debug/trace/jaeger/options.go
Normal file
76
cmd/micro/debug/trace/jaeger/options.go
Normal file
@ -0,0 +1,76 @@
|
||||
package jaeger
|
||||
|
||||
import (
|
||||
"github.com/uber/jaeger-client-go"
|
||||
"github.com/uber/jaeger-lib/metrics"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultLogger is the default Jaeger logger.
|
||||
DefaultLogger = jaeger.StdLogger
|
||||
|
||||
// DefaultMetrics is the default Jaeger metrics factory.
|
||||
DefaultMetrics = metrics.NullFactory
|
||||
)
|
||||
|
||||
// Options represents the options passed to the Jaeger tracer.
|
||||
type Options struct {
|
||||
Name string
|
||||
FromEnv bool
|
||||
GlobalTracer bool
|
||||
Logger jaeger.Logger
|
||||
Metrics metrics.Factory
|
||||
}
|
||||
|
||||
// Option manipulates the passed Options struct.
|
||||
type Option func(o *Options)
|
||||
|
||||
func newOptions(opts ...Option) Options {
|
||||
options := Options{
|
||||
Logger: DefaultLogger,
|
||||
Metrics: DefaultMetrics,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
// Name sets the service name for the Jaeger tracer.
|
||||
func Name(s string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = s
|
||||
}
|
||||
}
|
||||
|
||||
// FromEnv determines whether the Jaeger tracer configuration should use
|
||||
// environment variables.
|
||||
func FromEnv(e bool) Option {
|
||||
return func(o *Options) {
|
||||
o.FromEnv = e
|
||||
}
|
||||
}
|
||||
|
||||
// GlobalTracer determines whether the Jaeger tracer should be set as the
|
||||
// global tracer.
|
||||
func GlobalTracer(e bool) Option {
|
||||
return func(o *Options) {
|
||||
o.GlobalTracer = e
|
||||
}
|
||||
}
|
||||
|
||||
// Logger sets the logger for the Jaeger tracer.
|
||||
func Logger(l jaeger.Logger) Option {
|
||||
return func(o *Options) {
|
||||
o.Logger = l
|
||||
}
|
||||
}
|
||||
|
||||
// Metrics sets the metrics factory for the Jaeger tracer.
|
||||
func Metrics(m metrics.Factory) Option {
|
||||
return func(o *Options) {
|
||||
o.Metrics = m
|
||||
}
|
||||
}
|
20
cmd/micro/debug/trace/trace.go
Normal file
20
cmd/micro/debug/trace/trace.go
Normal file
@ -0,0 +1,20 @@
|
||||
package trace
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
|
||||
"github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// NewSpan accepts a context and returns an OpenTracing span. Can be used to
|
||||
// nest spans.
|
||||
func NewSpan(ctx context.Context) opentracing.Span {
|
||||
pc := make([]uintptr, 10) // at least 1 entry needed
|
||||
runtime.Callers(2, pc)
|
||||
span := opentracing.StartSpan(
|
||||
runtime.FuncForPC(pc[0]).Name(),
|
||||
opentracing.ChildOf(opentracing.SpanFromContext(ctx).Context()),
|
||||
)
|
||||
return span
|
||||
}
|
Reference in New Issue
Block a user