otplugins

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2021 License: MIT Imports: 7 Imported by: 0

README

OpenTracing-Go-Plugins

The plugins of opentracing-go.

Installation

go get -u github.com/yuewokeji/opentracing-go-plugins

Configuration

Initialize a tracer

Create a tracer such as jaeger.

package main

import (
	"github.com/opentracing/opentracing-go"
	"github.com/uber/jaeger-client-go"
	"github.com/uber/jaeger-client-go/transport"
	"io"
)

func initJaeger(service, url string) (opentracing.Tracer, io.Closer) {
	sender := transport.NewHTTPTransport(url)
	reporter := jaeger.NewRemoteReporter(sender, jaeger.ReporterOptions.Logger(jaeger.StdLogger))

	// samples 100% of traces
	tracer, closer := jaeger.NewTracer(service, jaeger.NewConstSampler(true), reporter)
	return tracer, closer
}

Initialize the global tracer

Let's initialize the global tracer, that's because the function opentracing.GlobalTracer() returns a no-op tracer by default.

func initGlobalTracer() io.Closer {
	// the closer can be used in shutdown hooks
	tracer, closer := initJaeger("hello-world", "https://your-reporter-url")

	opentracing.SetGlobalTracer(tracer)
	return closer
}

Plugin Summary

  1. goroutine
  2. gin
  3. goredis
  4. gorm
  5. grpc
  6. http client
  7. omnipotent

Documentation

Index

Constants

View Source
const Version = "v0.0.0"

Variables

This section is empty.

Functions

func Log

func Log(level LogLevel, args ...interface{}) error

func Logf

func Logf(level LogLevel, format string, args ...interface{}) error

func NonNilTracer

func NonNilTracer(t opentracing.Tracer) opentracing.Tracer

func NoneNilChildSpanFromContext

func NoneNilChildSpanFromContext(spanName string, ctx context.Context) opentracing.Span

func NoneNilSpanFromContext

func NoneNilSpanFromContext(ctx context.Context) opentracing.Span

func PropagateContextOnlyValue added in v0.0.1

func PropagateContextOnlyValue(old context.Context, keys ...interface{}) context.Context

func SetGlobalLogger

func SetGlobalLogger(logger Logger, level LogLevel)

func WithLogFieldStack

func WithLogFieldStack(stack string) log.Field

Types

type LogLevel

type LogLevel int
const (
	LogLevelDebug LogLevel = iota
	LogLevelInfo
	LogLevelWarning
	LogLevelError
)

func (LogLevel) String

func (lvl LogLevel) String() string

type Logger

type Logger interface {
	Output(callDepth int, s string) error
}

type NoopSpan

type NoopSpan struct{}

func (NoopSpan) BaggageItem

func (n NoopSpan) BaggageItem(key string) string

func (NoopSpan) Context

func (n NoopSpan) Context() opentracing.SpanContext

NoopSpan:

func (NoopSpan) Finish

func (n NoopSpan) Finish()

func (NoopSpan) FinishWithOptions

func (n NoopSpan) FinishWithOptions(opts opentracing.FinishOptions)

func (NoopSpan) Log

func (n NoopSpan) Log(data opentracing.LogData)

func (NoopSpan) LogEvent

func (n NoopSpan) LogEvent(event string)

func (NoopSpan) LogEventWithPayload

func (n NoopSpan) LogEventWithPayload(event string, payload interface{})

func (NoopSpan) LogFields

func (n NoopSpan) LogFields(fields ...log.Field)

func (NoopSpan) LogKV

func (n NoopSpan) LogKV(keyVals ...interface{})

func (NoopSpan) SetBaggageItem

func (n NoopSpan) SetBaggageItem(key, val string) opentracing.Span

func (NoopSpan) SetOperationName

func (n NoopSpan) SetOperationName(operationName string) opentracing.Span

func (NoopSpan) SetTag

func (n NoopSpan) SetTag(key string, value interface{}) opentracing.Span

func (NoopSpan) Tracer

func (n NoopSpan) Tracer() opentracing.Tracer

type NoopSpanContext

type NoopSpanContext struct{}

func (NoopSpanContext) ForeachBaggageItem

func (n NoopSpanContext) ForeachBaggageItem(handler func(k, v string) bool)

NoopSpanContext:

Directories

Path Synopsis
module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL