http

package
v3.0.21 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Package http provides helper to propagate monkit traces via HTTP calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TraceHandler

func TraceHandler(c http.Handler, scope *monkit.Scope, allowedBaggage ...string) http.Handler

TraceHandler wraps a HTTPHandler and import trace information from header.

func TraceRequest

func TraceRequest(ctx context.Context, scope *monkit.Scope, cl Client, req *http.Request) (
	resp *http.Response, err error)

TraceRequest will perform an HTTP request, creating a new Span for the HTTP request and sending the Span in the HTTP request headers. Compare to http.Client.Do.

func Wrap

func Wrap(w http.ResponseWriter) (http.ResponseWriter, func() int)

Wrap wraps original writer + provides func to retrieve statusCode, implements http.Flusher if original writer also did it.

Types

type Client

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

Client is an interface that matches a http.Client

type HeaderGetter

type HeaderGetter interface {
	Get(string) string
}

HeaderGetter is an interface that http.Header matches for RequestFromHeader

type HeaderSetter

type HeaderSetter interface {
	Set(string, string)
}

HeaderSetter is an interface that http.Header matches for TraceInfo.SetHeader

type TraceInfo

type TraceInfo struct {
	TraceId  *int64
	ParentId *int64
	Sampled  bool
	Baggage  map[string]string
}

TraceInfo is a structure representing an incoming RPC request. Every field is optional.

func TraceInfoFromHeader

func TraceInfoFromHeader(header HeaderGetter, allowedBaggage ...string) (rv TraceInfo)

TraceInfoFromHeader will create a TraceInfo object given a http.Header or anything that matches the HeaderGetter interface.

func TraceInfoFromSpan

func TraceInfoFromSpan(s *monkit.Span) TraceInfo

func (TraceInfo) SetHeader

func (r TraceInfo) SetHeader(header HeaderSetter)

SetHeader will take a TraceInfo and fill out an http.Header, or anything that matches the HeaderSetter interface.

Jump to

Keyboard shortcuts

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