opentrace

package
v0.0.0-...-5dad29e Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithSkipSpanCreating

func ContextWithSkipSpanCreating(ctx context.Context) context.Context

ContextWithSkipSpanCreating does not create a new span upon request, does not close the span upon response

func OperationNameFromRequest

func OperationNameFromRequest(request *http.Request) string

OperationNameFromRequest creates an operation name from the request

E.g.:

  • out: [POST] /v1/users
  • out: [GET] /v1/users

For RESTful, you will need to use your own implementation

func SkipSpanCreatingFromContext

func SkipSpanCreatingFromContext(ctx context.Context) bool

SkipSpanCreatingFromContext gets the flag

Types

type CreatorSpanner

type CreatorSpanner struct {
	// CreateRootSpanOnMissingParent creates a "root" span if the parent span is missing
	CreateRootSpanOnMissingParent bool

	// OperationNameFn function creates an operation name for the new span
	OperationNameFn func(r *http.Request) string

	StandardSpanner
}

CreatorSpanner - extended standard spanner with one difference - it creates a new span on each request

func (*CreatorSpanner) OnRequest

func (p *CreatorSpanner) OnRequest(tracer opentracing.Tracer, request *http.Request) opentracing.Span

OnRequest creates a new span and passes it to StandardSpanner

func (*CreatorSpanner) OnResponse

func (p *CreatorSpanner) OnResponse(span opentracing.Span, response *http.Response, clientError error)

OnResponse passes a span to StandardSpanner

func (*CreatorSpanner) WithCreateRootSpanOnMissingParent

func (p *CreatorSpanner) WithCreateRootSpanOnMissingParent(flag bool) *CreatorSpanner

WithCreateRootSpanOnMissingParent creates a "root" span if the parent span is missing

type HTTPHeadersInjector

type HTTPHeadersInjector struct{}

HTTPHeadersInjector used by default, it injects a trace into the HTTP headers

func (HTTPHeadersInjector) Inject

func (HTTPHeadersInjector) Inject(tracer opentracing.Tracer, ctx opentracing.SpanContext, r **http.Request) error

Inject creates a copy of the http.Request and replaces a pointer in the argument

type Injector

type Injector interface {
	Inject(tracer opentracing.Tracer, ctx opentracing.SpanContext, r **http.Request) error
}

Injector knows how to propagate a trace http.Request agrument should be immutable For any modifications, use a copy of the http.Request and replace the pointer

type InjectorFn

type InjectorFn func(tracer opentracing.Tracer, ctx opentracing.SpanContext, r **http.Request) error

InjectorFn a wrapper for the Injector interface

func (InjectorFn) Inject

func (fn InjectorFn) Inject(tracer opentracing.Tracer, ctx opentracing.SpanContext, r **http.Request) error

Inject

type Spanner

type Spanner interface {
	// OnRequest called on an HTTP request
	OnRequest(tracer opentracing.Tracer, request *http.Request) opentracing.Span

	// OnResponse called on an HTTP response
	OnResponse(span opentracing.Span, response *http.Response, clientError error)
}

Spanner injects tags, logs and manages the lifecycle of a span

Tagging and logging specification: https://github.com/opentracing/specification/blob/master/semantic_conventions.md

type StandardSpanner

type StandardSpanner struct{}

StandardSpanner is used by default It only works with the existing span and does not create a new one

func (StandardSpanner) OnRequest

func (StandardSpanner) OnRequest(tracer opentracing.Tracer, request *http.Request) opentracing.Span

OnRequest adds tags to an existing span: span.kind, http.url, http.method

func (StandardSpanner) OnResponse

func (StandardSpanner) OnResponse(span opentracing.Span, response *http.Response, clientError error)

OnResponse adds a "HTTPStatusCode" or "Error" tag to the existing span

type Transport

type Transport struct {
	// InterruptOnError
	// E.g. HTTP request will be interrupted upon a tracer.Inject error
	InterruptOnError bool
	// contains filtered or unexported fields
}

Transport is used for the HTTP Client transport, it implements the RoundTripper interface

func NewTransport

func NewTransport() *Transport

NewTransport returns http.RoundTripper

func (*Transport) RoundTripper

func (o *Transport) RoundTripper(next http.RoundTripper) http.RoundTripper

Transport middleware function

func (*Transport) WithInjector

func (o *Transport) WithInjector(injector Injector) *Transport

WithInjector sets an injector

func (*Transport) WithInterruptOnError

func (o *Transport) WithInterruptOnError(flag bool) *Transport

WithInterruptOnError sets a flag

func (*Transport) WithSpanner

func (o *Transport) WithSpanner(spanner Spanner) *Transport

WithSpanner sets a spanner

func (*Transport) WithTracer

func (o *Transport) WithTracer(tracer opentracing.Tracer) *Transport

WithTracer sets a tracer

Jump to

Keyboard shortcuts

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