jdsfapi

package
v0.0.0-...-6d33778 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppTraceGlobalConfig

func AppTraceGlobalConfig()

func Middleware

func Middleware(tr opentracing.Tracer, h http.Handler, options ...MWOption) http.Handler

Middleware wraps an http.Handler and traces incoming requests. Additionally, it adds the span to the request's context.

By default, the operation name of the spans is set to "HTTP {method}". This can be overriden with options.

Example:

http.ListenAndServe("localhost:80", nethttp.Middleware(tracer, http.DefaultServeMux))

The options allow fine tuning the behavior of the middleware.

Example:

  mw := nethttp.Middleware(
     tracer,
     http.DefaultServeMux,
     nethttp.OperationNameFunc(func(r *http.Request) string {
	        return "HTTP " + r.Method + ":/api/customers"
     }),
     nethttp.MWSpanObserver(func(sp opentracing.Span, r *http.Request) {
			sp.SetTag("http.uri", r.URL.EscapedPath())
		}),
  )

func MiddlewareFunc

func MiddlewareFunc(tr opentracing.Tracer, h http.HandlerFunc, options ...MWOption) http.HandlerFunc

MiddlewareFunc wraps an http.HandlerFunc and traces incoming requests. It behaves identically to the Middleware function above.

Example:

http.ListenAndServe("localhost:80", nethttp.MiddlewareFunc(tracer, MyHandler))

Types

type AppConfig

type AppConfig struct {
	AppName    string `yaml:"appName"`
	HostIp     string `yaml:"hostIp"`
	ServerPort int32  `yaml:"serverPort"`
}

type ClientOption

type ClientOption func(*clientOptions)

ClientOption contols the behavior of TraceRequest.

func ClientTrace

func ClientTrace(enabled bool) ClientOption

ClientTrace returns a ClientOption that turns on or off extra instrumentation via httptrace.WithClientTrace.

func ComponentName

func ComponentName(componentName string) ClientOption

ComponentName returns a ClientOption that sets the component name for the client-side span.

func OperationName

func OperationName(operationName string) ClientOption

OperationName returns a ClientOption that sets the operation name for the client-side span.

type ConsulConfig

type ConsulConfig struct {
	Scheme   string          `yaml:"scheme"`
	Address  string          `yaml:"address"`
	Port     int32           `yaml:"port"`
	Discover *ConsulDiscover `yaml:"discover"`
}

type ConsulDiscover

type ConsulDiscover struct {
	Enable            bool   `yaml:"enable"`
	ServiceInstanceId string `yaml:"instanceId"`
	CheckUrl          string `yaml:"checkUrl"`
}

type JDSFConfig

type JDSFConfig struct {
	Consul    *ConsulConfig `yaml:"consul"`
	Tracing   *TraceConfig  `yaml:"trace"`
	AppConfig *AppConfig    `yaml:"app"`
}
var (
	JDSFGlobalConfig *JDSFConfig
)

func NewJDSFConfig

func NewJDSFConfig() *JDSFConfig

func (*JDSFConfig) LoadConfig

func (j *JDSFConfig) LoadConfig(configFilePath string) *JDSFConfig

type MWOption

type MWOption func(*mwOptions)

MWOption controls the behavior of the Middleware.

func MWComponentName

func MWComponentName(componentName string) MWOption

MWComponentName returns a MWOption that sets the component name for the server-side span.

func MWSpanFilter

func MWSpanFilter(f func(r *http.Request) bool) MWOption

MWSpanFilter returns a MWOption that filters requests from creating a span for the server-side span. Span won't be created if it returns false.

func MWSpanObserver

func MWSpanObserver(f func(span opentracing.Span, r *http.Request)) MWOption

MWSpanObserver returns a MWOption that observe the span for the server-side span.

func OperationNameFunc

func OperationNameFunc(f func(r *http.Request) string) MWOption

OperationNameFunc returns a MWOption that uses given function f to generate operation name for each server-side span.

type RegistryClient

type RegistryClient struct {
	Address string
	Port    int
	Scheme  string
	Client  *api.Client
}
var (
	JDSFRegistryClient *RegistryClient
)

func NewRegistryClient

func NewRegistryClient() *RegistryClient

func (*RegistryClient) GetConsulClient

func (r *RegistryClient) GetConsulClient() *api.Client

func (*RegistryClient) RegistryService

func (r *RegistryClient) RegistryService()

func (*RegistryClient) ServiceRequestLoadBlance

func (r *RegistryClient) ServiceRequestLoadBlance(rawURL string) string

type TraceConfig

type TraceConfig struct {
	Enable           bool    `yaml:"enable"`
	SimpleType       string  `yaml:"simpleType"`
	SimpleRate       float64 `yaml:"simpleRate"`
	TraceUdpAddress  string  `yaml:"traceUdpAddress"`
	TraceUdpPort     int     `yaml:"traceUdpPort"`
	TraceHttpAddress string  `yaml:"traceHttpAddress"`
	TraceHttpPort    int     `yaml:"traceHttpPort"`
}

type Tracer

type Tracer struct {
	Tracer      opentracing.Tracer
	RootSpan    opentracing.Span
	CurrentSpan opentracing.Span
	Opts        *clientOptions
}

Tracer holds tracing details for one HTTP request.

func TraceRequest

func TraceRequest(tr opentracing.Tracer, req *http.Request, options ...ClientOption) (*http.Request, *Tracer)

TraceRequest adds a ClientTracer to req, tracing the request and all requests caused due to redirects. When tracing requests this way you must also use Transport.

Example:

func AskGoogle(ctx context.Context) error {
	client := &http.Client{Transport: &nethttp.Transport{}}
	req, err := http.NewRequest("GET", "http://google.com", nil)
	if err != nil {
		return err
	}
	req = req.WithContext(ctx) // extend existing trace, if any

	req, ht := nethttp.TraceRequest(tracer, req)
	defer ht.Finish()

	res, err := client.Do(req)
	if err != nil {
		return err
	}
	res.Body.Close()
	return nil
}

func (*Tracer) Finish

func (h *Tracer) Finish()

Finish finishes the span of the traced request.

func (*Tracer) Span

func (h *Tracer) Span() opentracing.Span

Span returns the root span of the traced request. This function should only be called after the request has been executed.

func (*Tracer) Start

func (h *Tracer) Start(req *http.Request) opentracing.Span

type Transport

type Transport struct {
	// The actual RoundTripper to use for the request. A nil
	// RoundTripper defaults to http.DefaultTransport.
	http.RoundTripper
}

Transport wraps a RoundTripper. If a request is being traced with Tracer, Transport will inject the current span into the headers, and set HTTP related tags on the span.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

Jump to

Keyboard shortcuts

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