trarelic

package module
v0.0.0-...-3f88b95 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

GO-trarelic

Prerequisites

Opentracing tracer must be instantiated and achievable via opentracing.GlobalTracer() or passed directly via option trarelic.WithTracer().

Description

Trarelic creates opentracing span with some tags needed in pulsometer:

  • is_external
  • type
  • caller

You must instrument your code by wrapping the http transport used in external requests.

E.g.:

Wrap existing transport

client := &http.Client{
	Timeout: 10 * time.Second,
	Transport: trarelic.NewRoundTripper(
		&http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		},
	),
}

http.DefaultTransport will be used by default if nil is passed

client := &http.Client{
	Transport: trarelic.NewRoundTripper(nil),
}

With functional options

client := &http.Client{
	Transport: trarelic.NewRoundTripper(
		nil,
		trarelic.WithTracer(opentracing.GlobalTracer()),
		trarelic.WithNewSpan(true),
		trarelic.WithType("background"),
		trarelic.WithCaller("bin/i_am_bin"),
		trarelic.WithPostfix("additional info about the call"),
	),
}

See godoc for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRoundTripper

func NewRoundTripper(original http.RoundTripper, opts ...TrarelicOption) http.RoundTripper

NewRoundTripper creates http.RoundTripper to instrument external requests. The RoundTripper returned creates an external span with tags (or use existed one) before delegating to the original RoundTripper provided (or http.DefaultTransport if none is provided).

Types

type Trarelic

type Trarelic struct {
	Tracer  opentracing.Tracer
	NewSpan bool
	Type    string
	Caller  string
	Postfix string
}

func NewTrarelic

func NewTrarelic(opts ...TrarelicOption) *Trarelic

NewTrarelic is a constructor function for *Trarelic.

func (*Trarelic) GetSpanFromRequest

func (t *Trarelic) GetSpanFromRequest(req *http.Request) opentracing.Span

GetSpanFromRequest returns span to witch trarelic's tags will be applied.

type TrarelicOption

type TrarelicOption func(*Trarelic)

func WithCaller

func WithCaller(caller string) TrarelicOption

WithCaller defines caller of the external request, defaults to path of binary executable.

func WithNewSpan

func WithNewSpan(new bool) TrarelicOption

WithNewSpan defines whether new span for external request is needed, defaults to true.

func WithPostfix

func WithPostfix(postfix string) TrarelicOption

WithPostfix redefines new span name to custom one by adding postfix to external url host. Can be useful in two cases: 1. we need to segregate external requests within one external host, e.g. payout / payout status, etc. 2. external host is not human-readable and custom name is more preferable, e.g. ip

func WithTracer

func WithTracer(tracer opentracing.Tracer) TrarelicOption

WithTracer defines certain tracer implementation, if needed, defaults to opentracing.GlobalTracer().

func WithType

func WithType(tp string) TrarelicOption

WithType is a newrelic style segmentation by type (background / web), defaults to background.

Jump to

Keyboard shortcuts

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