tracing

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 5 Imported by: 2

README

Tracing package

Package tracing provides functions for reporting traces to a service.

Code
import (
  "context"

  "github.com/deixis/spine/tracing"
  "github.com/deixis/storage/kvdb"
  opentracing "github.com/opentracing/opentracing-go"
  olog "github.com/opentracing/opentracing-go/log"
)


func (c *store) ReadTransact(
	ctx context.Context,
	f func(kvdb.ReadTransaction) (interface{}, error),
) (interface{}, error) {
	var span opentracing.Span
	span, ctx = tracing.StartSpanFromContext(ctx, "storage.kvdb.readTx")
	defer span.Finish()
	span.LogFields(
		olog.String("type", "storage.kv"),
	)

	return c.s.ReadTransact(ctx, func(t kvdb.ReadTransaction) (interface{}, error) {
		return f(&readTransaction{t: t, ctx: ctx})
	})
}
Config
[tracing.jaeger]
  service_name = "liquidator"

[tracing.jaeger.sampler]
  type = "probabilistic"
  param = 1.0

[tracing.jaeger.reporter]
  log_span = true

[tracing.jaeger.tags]
  node = "$HOSTNAME"
  version = "$VERSION"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithSpan

func ContextWithSpan(ctx context.Context, span opentracing.Span) context.Context

ContextWithSpan returns a new `context.Context` that holds a reference to `span`'s SpanContext.

func Extract

func Extract(
	ctx context.Context, format interface{}, carrier interface{},
) (opentracing.SpanContext, error)

Extract returns a SpanContext instance given `format` and `carrier`.

Extract calls `Extract` on the context `Tracer`

func Inject

func Inject(
	ctx context.Context, sm opentracing.SpanContext, format interface{}, carrier interface{},
) error

Inject takes the `sm` SpanContext instance and injects it for propagation within `carrier`. The actual type of `carrier` depends on the value of `format`.

Inject calls `Inject` on the context `Tracer`

func SpanFromContext

func SpanFromContext(ctx context.Context) opentracing.Span

SpanFromContext returns the `Span` previously associated with `ctx`, or `nil` if no such `Span` could be found.

NOTE: context.Context != SpanContext: the former is Go's intra-process context propagation mechanism, and the latter houses OpenTracing's per-Span identity and baggage information.

func StartSpan

func StartSpan(
	ctx context.Context, operationName string, opts ...opentracing.StartSpanOption,
) (span opentracing.Span)

StartSpan creates, starts, and returns a new Span with the given `operationName` and incorporate the given StartSpanOption `opts`.

StartSpan calls `StartSpan` on the context `Tracer`

func StartSpanFromContext

func StartSpanFromContext(
	ctx context.Context, operationName string, opts ...opentracing.StartSpanOption,
) (opentracing.Span, context.Context)

StartSpanFromContext starts and returns a Span with `operationName`, using any Span found within `ctx` as a ChildOfRef. If no such parent could be found, StartSpanFromContext creates a root (parentless) Span.

The second return value is a context.Context object built around the returned Span.

Example usage:

SomeFunction(ctx context.Context, ...) {
    sp, ctx := tracing.StartSpanFromContext(ctx, "SomeFunction")
    defer sp.Finish()
    ...
}

func WithContext

func WithContext(ctx context.Context, t Tracer) context.Context

WithContext returns a copy of parent in which the `Tracer` is stored

Types

type Tracer

type Tracer opentracing.Tracer

Tracer follows the opentracing standard https://opentracing.io

func FromContext

func FromContext(ctx contextutil.ValueContext) Tracer

FromContext returns a `Tracer` instance associated with `ctx`, or the `opentracing.GlobalTracer` if no `Tracer` instance could be found.

type TracerOption

type TracerOption func(*TracerOptions)

TracerOption configures how we set up a job

func WithLogger

func WithLogger(l log.Logger) TracerOption

WithLogger injects a `Logger` to `Tracer`

func WithStats

func WithStats(s stats.Stats) TracerOption

WithStats injects a `Stats` to `Tracer`

type TracerOptions

type TracerOptions struct {
	Logger log.Logger
	Stats  stats.Stats
}

TracerOptions configure a Tracer.

Directories

Path Synopsis
jaeger
Package jaeger wraps the Jaeger tracer
Package jaeger wraps the Jaeger tracer

Jump to

Keyboard shortcuts

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