tracing

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: AGPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const TracerName = "coderd"

Variables

View Source
var NoopSpan trace.Span

Functions

func DefaultExporter

func DefaultExporter(ctx context.Context) (*otlptrace.Exporter, error)

func EndHTTPSpan

func EndHTTPSpan(r *http.Request, status int, span trace.Span)

EndHTTPSpan captures request and response data after the handler is done.

func FuncName

func FuncName() string

func FuncNameSkip

func FuncNameSkip(skip int) string

func GetTracerName

func GetTracerName(ctx context.Context) string

GetTracerName returns the tracer name from the context, or TracerName if none is set.

func HoneycombExporter

func HoneycombExporter(ctx context.Context, apiKey string) (*otlptrace.Exporter, error)

func MetadataFromContext

func MetadataFromContext(ctx context.Context) map[string]string

func MetadataToContext

func MetadataToContext(ctx context.Context, metadata map[string]string) context.Context

func Middleware

func Middleware(tracerProvider trace.TracerProvider) func(http.Handler) http.Handler

Middleware adds tracing to http routes.

func PostgresDriver

func PostgresDriver(tp trace.TracerProvider, service string) (string, error)

Postgres driver will register a new tracing sql driver and return the driver name.

func RunWithoutSpan

func RunWithoutSpan(ctx context.Context, fn func(ctx context.Context))

RunWithoutSpan runs the given function with the span stripped from the context and replaced with a no-op span. This is useful for avoiding logs being added to span (to save money).

func SetTracerName

func SetTracerName(ctx context.Context, tracerName string) context.Context

SetTracerName sets the tracer name that will be used by all spans created from the context.

func StartSpan

func StartSpan(ctx context.Context, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartSpan calls StartSpanWithName with the name set to the caller's function name.

func StartSpanWithName

func StartSpanWithName(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartSpanWithName starts a new span with the given name from the context. If a tracer name was set on the context (or one of its parents), it will be used as the tracer name instead of the default TracerName.

func StatusWriterMiddleware

func StatusWriterMiddleware(next http.Handler) http.Handler

func TracerProvider

func TracerProvider(ctx context.Context, service string, opts TracerOpts) (*sdktrace.TracerProvider, func(context.Context) error, error)

TracerProvider creates a grpc otlp exporter and configures a trace provider. Caller is responsible for calling TracerProvider.Shutdown to ensure all data is flushed.

Types

type DRPCConn

type DRPCConn struct {
	drpc.Conn
}

func (*DRPCConn) Invoke

func (c *DRPCConn) Invoke(ctx context.Context, rpc string, enc drpc.Encoding, in drpc.Message, out drpc.Message) (err error)

Invoke implements drpc.Conn's Invoke method with tracing information injected into the context.

func (*DRPCConn) NewStream

func (c *DRPCConn) NewStream(ctx context.Context, rpc string, enc drpc.Encoding) (_ drpc.Stream, err error)

NewStream implements drpc.Conn's NewStream method with tracing information injected into the context.

type DRPCHandler

type DRPCHandler struct {
	Handler drpc.Handler
}

func (*DRPCHandler) HandleRPC

func (t *DRPCHandler) HandleRPC(stream drpc.Stream, rpc string) error

type SlogSink

type SlogSink struct{}

func (SlogSink) LogEntry

func (SlogSink) LogEntry(ctx context.Context, e slog.SinkEntry)

LogEntry implements slog.Sink. All entries are added as events to the span in the context. If no span is present, the entry is dropped.

func (SlogSink) Sync

func (SlogSink) Sync()

Sync implements slog.Sink. No-op as syncing is handled externally by otel.

type StatusWriter

type StatusWriter struct {
	http.ResponseWriter
	Status   int
	Hijacked bool
	// contains filtered or unexported fields
}

StatusWriter intercepts the status of the request and the response body up to maxBodySize if Status >= 400. It is guaranteed to be the ResponseWriter directly downstream from Middleware.

func (*StatusWriter) Flush

func (w *StatusWriter) Flush()

func (*StatusWriter) Hijack

func (w *StatusWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*StatusWriter) ResponseBody

func (w *StatusWriter) ResponseBody() []byte

func (*StatusWriter) Write

func (w *StatusWriter) Write(b []byte) (int, error)

func (*StatusWriter) WriteHeader

func (w *StatusWriter) WriteHeader(status int)

type TracerOpts

type TracerOpts struct {
	// Default exports to a backend configured by environment variables. See:
	// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md
	Default bool
	// DataDog exports traces and profiles to the local DataDog daemon.
	DataDog bool
	// Exports traces to Honeycomb.io with the provided API key.
	Honeycomb string
}

TracerOpts specifies which telemetry exporters should be configured.

Jump to

Keyboard shortcuts

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