trace

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: ISC Imports: 8 Imported by: 0

README

trace

This is a helper package for creating a Jaeger tracer that creates traces in OpenTracing format.

Quick Start

For creating a tracer with default configurations (constant sampler and agent reporter):

package main

import (
  "github.com/moorara/observe/trace"
  "github.com/opentracing/opentracing-go/ext"
  "github.com/opentracing/opentracing-go/log"
)

func main() {
  tracer, closer, _ := trace.NewTracer(trace.Options{Name: "service-name"})
  defer closer.Close()

  span := tracer.StartSpan("hello-world")
  defer span.Finish()

  // https://github.com/opentracing/specification/blob/master/semantic_conventions.md
  span.SetTag("protocol", "HTTP")
  ext.HTTPMethod.Set(span, "GET")
  ext.HTTPStatusCode.Set(span, 200)
  span.LogFields(
    log.String("environment", "prodcution"),
    log.String("region", "us-east-1"),
  )
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAgentReporter

func NewAgentReporter(agentAddr string, logSpans bool) *jconfig.ReporterConfig

NewAgentReporter creates a Jaeger reporter reporting to jaeger-agent.

agentAddr is the address of Jaeger agent.
logSpans true will log all spans.

func NewCollectorReporter

func NewCollectorReporter(collectorAddr string, logSpans bool) *jconfig.ReporterConfig

NewCollectorReporter creates a Jaeger reporter reporting to jaeger-collector.

collectorAddr is the address of Jaeger collector.
logSpans true will log all spans.

func NewConstSampler

func NewConstSampler(enabled bool) *jconfig.SamplerConfig

NewConstSampler creates a constant Jaeger sampler.

enabled true will report all traces.
enabled false will skip all traces.

func NewProbabilisticSampler

func NewProbabilisticSampler(probability float64) *jconfig.SamplerConfig

NewProbabilisticSampler creates a probabilistic Jaeger sampler.

probability is between 0 and 1.

func NewRateLimitingSampler

func NewRateLimitingSampler(rate float64) *jconfig.SamplerConfig

NewRateLimitingSampler creates a rate limited Jaeger sampler.

rate is the number of spans per second.

func NewRemoteSampler

func NewRemoteSampler(probability float64, serverURL string, interval time.Duration) *jconfig.SamplerConfig

NewRemoteSampler creates a Jaeger sampler pulling remote sampling strategies.

probability is the initial probability between 0 and 1 before a remote sampling strategy is recieved.
serverURL is the address of sampling server.
interval specifies the rate of polling remote sampling strategies.

func NewTracer

func NewTracer(opts Options) (opentracing.Tracer, io.Closer, error)

NewTracer creates a new tracer.

Types

type Options

type Options struct {
	Name     string
	Sampler  *jconfig.SamplerConfig
	Reporter *jconfig.ReporterConfig
	Logger   *log.Logger
	PromReg  prometheus.Registerer
}

Options contains optional options for Tracer.

Jump to

Keyboard shortcuts

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