ottwirp

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: MIT Imports: 8 Imported by: 0

README

OpenTracing Hooks for Twirp

CI

The ottwirp package creates an OpenTracing Twirp hook to use in your server. Derived from grpc-opentracing.

Installation

go get -u github.com/twirp-ecosystem/twirp-opentracing

Server-side usage example

Where you are instantiating your Twirp server:

var tracer opentracing.Tracer = ...

...

hooks := NewOpenTracingHooks(tracer)
service := haberdasherserver.New()
server := WithTraceContext(haberdasher.NewHaberdasherServer(service, hooks), tracer)
log.Fatal(http.ListenAndServe(":8080", server))

Client-side usage example

When instantiating your Twirp client:

var tracer opentracing.Tracer = ...

...

client := haberdasher.NewHaberdasherProtobufClient(url, NewTraceHTTPClient(http.DefaultClient, tracer))

Documentation

Overview

Package ottwirp provides OpenTracing support for any Twirp server.

Index

Constants

View Source
const (
	RequestReceivedEvent = "request.received"
)

Variables

This section is empty.

Functions

func NewOpenTracingHooks

func NewOpenTracingHooks(tracer ot.Tracer, opts ...TraceOption) *twirp.ServerHooks

NewOpenTracingHooks provides a twirp.ServerHooks struct which records OpenTracing spans.

func WithTraceContext

func WithTraceContext(base http.Handler, tracer ot.Tracer) http.Handler

WithTraceContext wraps the handler and extracts the span context from request headers to attach to the context for connecting client and server calls.

Types

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient as an interface that models *http.Client.

type TraceHTTPClient

type TraceHTTPClient struct {
	// contains filtered or unexported fields
}

TraceHTTPClient wraps a provided http.Client and tracer for instrumenting requests.

func NewTraceHTTPClient

func NewTraceHTTPClient(client HTTPClient, tracer opentracing.Tracer, opts ...TraceOption) *TraceHTTPClient

func (*TraceHTTPClient) Do

func (c *TraceHTTPClient) Do(req *http.Request) (*http.Response, error)

Do injects the tracing headers into the tracer and updates the headers before making the actual request.

type TraceOption added in v0.3.0

type TraceOption func(opts *TraceOptions)

func IncludeClientErrors added in v0.3.0

func IncludeClientErrors(includeClientErrors bool) TraceOption

IncludeClientErrors, if set, will report client errors (4xx) as errors in the server span. If not set, only 5xx status will be reported as erroneous.

func WithContextTags added in v0.4.2

func WithContextTags(fn func(ctx context.Context) []TraceTag) TraceOption

WithContextTags defines a function that returns set of trace tags. This is useful to extract values from the request ctx and return a set of tags that are set on the span. The function is used during the `RequestReceived` server hook.

func WithTags added in v0.4.0

func WithTags(tags ...TraceTag) TraceOption

WithTags defines tags to be added to each outoing span by default. If there is a pre-existing tag set for `key`, it is overwritten.

type TraceOptions added in v0.3.0

type TraceOptions struct {
	// contains filtered or unexported fields
}

type TraceServerHooks added in v0.3.0

type TraceServerHooks struct {
	Tracer ot.Tracer
	// contains filtered or unexported fields
}

func (*TraceServerHooks) TwirpHooks added in v0.3.0

func (t *TraceServerHooks) TwirpHooks() *twirp.ServerHooks

type TraceTag added in v0.4.0

type TraceTag struct {
	// Key defines the span's tag key.
	Key string

	// Value defines the span's tag value. Values can be numeric types, strings, or
	// bools.
	Value interface{}
}

TraceTag represents a single span tag.

Jump to

Keyboard shortcuts

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