log

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FieldComponent is the structured logging key used to describe the emitting sub-component.
	FieldComponent = "component"

	// FieldRequestID is the structured logging key for the MCP request identifier. This id assigned by control plane.
	FieldRequestID = "request_id"

	// FieldRpcRequestID is a Request identifier, which is defined by the spec to be a string, integer, or null.
	// https://www.jsonrpc.org/specification#request_object
	FieldRpcRequestID = "rpc_request_id"

	// FieldSessionID is the structured logging key that records the MCP session identifier.
	FieldSessionID = "session_id"

	// FieldControlPlaneCommandRequestID captures the upstream X-Request-Id issued by
	// plugin-service/connectors while they communicate with tunnel-service.
	FieldControlPlaneCommandRequestID = "cmd_request_id"

	// FieldTunnelServiceRequestID captures the X-Request-Id returned when the tunnel-client
	// talks directly to tunnel-service (e.g. poll, post response).
	FieldTunnelServiceRequestID = "tunnel_request_id"

	// FieldTunnelID is the stable structured logging key for the configured tunnel identifier.
	FieldTunnelID = "tunnel_id"

	// FieldClientInstanceID is the process-scoped correlation key shared with tunnel-service.
	FieldClientInstanceID = "client_instance_id"

	ComponentHealth       = "health"
	ComponentDispatcher   = "dispatcher"
	ComponentControlPlane = "controlplane"
	ComponentMcpClient    = "mcpclient"
	ComponentProcess      = "process"
	ComponentCloudflared  = "cloudflared"
	ComponentHarpoon      = "harpoon"
)

Variables

View Source
var Module = fx.Module("logger", fx.Provide(newLevelController, newLogger))

Module exposes the logger as an Fx module that owns the lifecycle of any resources it creates.

Functions

func CloseIfNeeded

func CloseIfNeeded(closer io.Closer)

CloseIfNeeded closes the provided closer if it is non-nil, ignoring already-closed errors.

func ErrorForLog added in v0.0.11

func ErrorForLog(err error) string

ErrorForLog strips URL details from net/url errors while preserving wrapper and joined-error context. Callers remain responsible for not embedding raw URLs in ordinary error strings.

func LoggerWithContextIdentifiers

func LoggerWithContextIdentifiers(ctx context.Context, logger *slog.Logger) *slog.Logger

LoggerWithContextIdentifiers returns a logger annotated with any identifiers stored on ctx.

func NewLogger

func NewLogger(cfg *runtimeconfig.LoggingConfig, defaultWriter io.Writer) (*slog.Logger, io.Closer, error)

NewLogger constructs a slog.Logger configured according to the provided runtimeconfig. It returns the logger along with an optional closer that must be closed by the caller.

func NewLoggerWithLevelController

func NewLoggerWithLevelController(cfg *runtimeconfig.LoggingConfig, defaultWriter io.Writer, controller *LevelController) (*slog.Logger, io.Closer, error)

NewLoggerWithLevelController constructs a slog.Logger backed by the provided level controller.

func NewRoundTripper

func NewRoundTripper(base http.RoundTripper, logger *slog.Logger, cfg *runtimeconfig.LoggingConfig, component string) http.RoundTripper

NewRoundTripper constructs a RoundTripper that logs raw HTTP traffic when the provided logging config enables it. The component name, when non-empty, is attached to the emitted logs via the FieldComponent attribute.

func ParseRuntimeLogLevel

func ParseRuntimeLogLevel(raw string) (slog.Level, error)

func RedactURL added in v0.0.11

func RedactURL(u *url.URL) string

RedactURL returns only the URL origin for logging. URL userinfo, opaque data, path, query, and fragment components can contain credentials or other sensitive values and are intentionally omitted.

func RedactURLString added in v0.0.11

func RedactURLString(raw string) string

RedactURLString parses raw as a URL and returns its origin for logging.

func SupportedRuntimeLogLevels

func SupportedRuntimeLogLevels() []string

Types

type LevelController

type LevelController struct {
	// contains filtered or unexported fields
}

LevelController exposes the live slog level used by tunnel-client handlers.

func NewLevelController

func NewLevelController(cfg *runtimeconfig.LoggingConfig) (*LevelController, error)

NewLevelController initializes a mutable level controller from the startup runtimeconfig.

func (*LevelController) Level

func (c *LevelController) Level() slog.Level

func (*LevelController) LevelString

func (c *LevelController) LevelString() string

func (*LevelController) LevelVar

func (c *LevelController) LevelVar() *slog.LevelVar

func (*LevelController) Set

func (c *LevelController) Set(level slog.Level)

func (*LevelController) SetString

func (c *LevelController) SetString(raw string) (slog.Level, error)

type LoggingRoundTripper

type LoggingRoundTripper struct {
	// contains filtered or unexported fields
}

LoggingRoundTripper wraps a base RoundTripper and emits raw HTTP request and response dumps when enabled.

func (*LoggingRoundTripper) RoundTrip

func (l *LoggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip logs raw request and response dumps surrounding the underlying transport call.

type Sink

type Sink interface {
	Handle(ctx context.Context, record slog.Record)
}

Sink receives a copy of each log record emitted by the tunnel-client logger.

Implementations MUST NOT retain slog.Record beyond the scope of Handle unless they first clone or fully materialize it, since slog.Record may reference transient state.

Jump to

Keyboard shortcuts

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