Documentation
¶
Index ¶
- Constants
- Variables
- func ClientSessionID(r *http.Request) string
- func DefaultExporter(ctx context.Context) (*otlptrace.Exporter, error)
- func EndHTTPSpan(r *http.Request, status int, span trace.Span, serverName string)
- func FuncName() string
- func FuncNameSkip(skip int) string
- func GetTracerName(ctx context.Context) string
- func HoneycombExporter(ctx context.Context, apiKey string) (*otlptrace.Exporter, error)
- func MetadataFromContext(ctx context.Context) map[string]string
- func MetadataToContext(ctx context.Context, metadata map[string]string) context.Context
- func Middleware(tracerProvider trace.TracerProvider, routePatterns []string, serverName string) func(http.Handler) http.Handler
- func NewSessionID() (string, error)
- func PostgresDriver(tp trace.TracerProvider, service string) (string, error)
- func RunWithoutSpan(ctx context.Context, fn func(ctx context.Context))
- func StartHTTPSpan(tracer trace.Tracer, rw http.ResponseWriter, r *http.Request, name string) (*http.Request, trace.Span)
- func StartSpan(ctx context.Context, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func StartSpanWithName(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func StatusWriterMiddleware(next http.Handler) http.Handler
- func TracerProvider(ctx context.Context, service string, opts TracerOpts) (*sdktrace.TracerProvider, func(context.Context) error, error)
- func ValidSessionID(s string) bool
- type DRPCConn
- type DRPCHandler
- type SlogSink
- type StatusWriter
- type TracerOpts
Constants ¶
const SessionIDBaggageKey = "client_session_id"
SessionIDBaggageKey is the W3C baggage key clients use to propagate their per-session correlation ID. The value is a 16-byte identifier encoded as a 32-character hexadecimal string.
const TracerName = "coderd"
Variables ¶
var DefaultRoutePatterns = []string{
"/api",
"/api/**",
"/@*/*/apps/**",
"/%40*/*/apps/**",
"/external-auth/*/callback",
}
DefaultRoutePatterns are the route patterns coderd and wsproxy trace. The middleware runs high in the stack so it can capture the entire request, but only acts on these patterns.
var NoopSpan trace.Span
Functions ¶
func ClientSessionID ¶
ClientSessionID returns the client session ID tracing middleware handler.
func EndHTTPSpan ¶
EndHTTPSpan captures request and response data after the handler is done. serverName labels the span's server request attributes.
func FuncNameSkip ¶
func GetTracerName ¶
GetTracerName returns the tracer name from the context, or TracerName if none is set.
func HoneycombExporter ¶
func MetadataToContext ¶
func Middleware ¶
func Middleware( tracerProvider trace.TracerProvider, routePatterns []string, serverName string, ) func(http.Handler) http.Handler
Middleware adds tracing to http routes. It only acts on requests matching routePatterns, and labels emitted spans with serverName. A nil tracerProvider disables span creation, leaving the middleware to enrich the log context with client_session_id only (as the agent uses it).
func NewSessionID ¶
NewSessionID generates a new client session ID: 16 random bytes encoded as a 32-character lowercase hexadecimal string, to match OpenTelemetry's identifiers.
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 ¶
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 StartHTTPSpan ¶ added in v2.36.0
func StartHTTPSpan(tracer trace.Tracer, rw http.ResponseWriter, r *http.Request, name string) (*http.Request, trace.Span)
StartHTTPSpan starts a span, propagating inbound trace context and writing X-Trace-ID/X-Span-ID response headers. The caller must end the span.
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 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.
func ValidSessionID ¶
ValidSessionID reports whether s is a 32-character lowercase hexadecimal string (a 16-byte value). Only lowercase is accepted so that case-sensitive searches correlate reliably. Validating also guards against logging arbitrary client-controlled baggage values.
Types ¶
type DRPCConn ¶
type DRPCHandler ¶
type SlogSink ¶
type SlogSink struct{}
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) Unwrap ¶ added in v2.32.0
func (w *StatusWriter) Unwrap() http.ResponseWriter
Unwrap returns the underlying ResponseWriter, allowing http.ResponseController to reach it for SetWriteDeadline, etc.
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.