http

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapClient

func WrapClient(c *http.Client, on string) *http.Client

WrapClient wraps http.Client to inject opentracing span to outgoing call if and only if root span exists in request context.

Example
client := WrapClient(&http.Client{}, "span.name")

span := opentracing.StartSpan("test_call")
defer span.Finish()

req, _ := http.NewRequest(http.MethodGet, "http://localhost/test", nil)
opentracing.GlobalTracer().Inject(
	span.Context(),
	opentracing.HTTPHeaders,
	opentracing.HTTPHeadersCarrier(req.Header))

client.Do(req)
Output:

func WrapExternalClient

func WrapExternalClient(c *http.Client, on string) *http.Client

WrapExternalClient wraps http.Client with tracing and creates opentracing span to outgoing calls, if and only if context of request contains root span. default operation name for that span is http.request

Example
client := WrapExternalClient(&http.Client{}, "external_call")

span := opentracing.StartSpan("test_call")
defer span.Finish()

req, _ := http.NewRequest(http.MethodGet, "http://localhost/test", nil)
ctx := opentracing.ContextWithSpan(context.TODO(), span)

client.Do(req.WithContext(ctx))
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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