traceserver

package
v1.20220411.3 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package traceserver is a mocked APM trace server that calls a handler for each spanlists payload it gets.

It can be used as a standalone server (see: sdk/cmd/traces) or in integration tests.

Index

Constants

View Source
const (
	// HeaderTraceCount is a header containing the number of traces in the payload
	HeaderTraceCount  = "X-Datadog-Trace-Count"
	HeaderContainerID = "Datadog-Container-ID"
)

Headers

View Source
const (
	ContentTypeApplicationMessagePack = "application/msgpack"
)

ContentTypes

Variables

This section is empty.

Functions

func FormatContentLength

func FormatContentLength(sizeBytes int) string

FormatContentLength returns a string representation of a file size in bytes.

Types

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter

	StatusCode    int
	ContentLength int
}

ResponseWriter a better response writer

func (*ResponseWriter) Close

func (rw *ResponseWriter) Close() error

Close calls close on the inner response if it supports it.

func (*ResponseWriter) Flush

func (rw *ResponseWriter) Flush()

Flush calls flush on the inner response writer if it is supported.

func (*ResponseWriter) Hijack

func (rw *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack wraps response writer's Hijack function.

func (*ResponseWriter) Write

func (rw *ResponseWriter) Write(b []byte) (int, error)

Write writes the data to the response.

func (*ResponseWriter) WriteHeader

func (rw *ResponseWriter) WriteHeader(code int)

WriteHeader writes the status code (it is a somewhat poorly chosen method name from the standard library).

type Server

type Server struct {
	Addr     string
	Log      *log.Logger
	Listener net.Listener
	Server   *http.Server
	Handler  func(context.Context, ...*Span)
}

Server is a server for handling traces.

func (*Server) ServeHTTP

func (ts *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request)

func (*Server) Start

func (ts *Server) Start() error

Start starts the server.

func (*Server) Stop

func (ts *Server) Stop() error

Stop stops the trace server.

type Span

type Span struct {
	Name     string             `json:"name" msg:"name"`                           // operation name
	Service  string             `json:"service" msg:"service"`                     // service name (i.e. "grpc.server", "http.request")
	Resource string             `json:"resource" msg:"resource"`                   // resource name (i.e. "/user?id=123", "SELECT * FROM users")
	Type     string             `json:"type" msg:"type"`                           // protocol associated with the span (i.e. "web", "db", "cache")
	Start    int64              `json:"start" msg:"start"`                         // span start time expressed in nanoseconds since epoch
	Duration int64              `json:"duration" msg:"duration"`                   // duration of the span expressed in nanoseconds
	Meta     map[string]string  `json:"meta,omitempty" msg:"meta,omitempty"`       // arbitrary map of metadata
	Metrics  map[string]float64 `json:"metrics,omitempty" msg:"metrics,omitempty"` // arbitrary map of numeric metrics
	SpanID   uint64             `json:"span_id" msg:"span_id"`                     // identifier of this span
	TraceID  uint64             `json:"trace_id" msg:"trace_id"`                   // identifier of the root span
	ParentID uint64             `json:"parent_id" msg:"parent_id"`                 // identifier of the span's direct parent
	Error    int32              `json:"error" msg:"error"`                         // error status of the span; 0 means no errors
}

Span represents a computation. Callers must call Finish when a span is complete to ensure it's submitted.

func (*Span) DecodeMsg

func (z *Span) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Span) EncodeMsg

func (z *Span) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Span) Msgsize

func (z *Span) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

type SpanList

type SpanList []*Span

SpanList implements msgp.Encodable on top of a slice of spans.

func (*SpanList) DecodeMsg

func (z *SpanList) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (SpanList) EncodeMsg

func (z SpanList) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (SpanList) Msgsize

func (z SpanList) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

type SpanLists

type SpanLists []SpanList

SpanLists implements msgp.Decodable on top of a slice of spanList. This type is only used in tests.

func (*SpanLists) DecodeMsg

func (z *SpanLists) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (SpanLists) EncodeMsg

func (z SpanLists) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (SpanLists) Msgsize

func (z SpanLists) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

Jump to

Keyboard shortcuts

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