Documentation
¶
Overview ¶
Package client provides a Go SDK for sending events to an eventrelay server.
Index ¶
- type Client
- func (c *Client) Emit(action string, data map[string]any)
- func (c *Client) EmitDebug(action string, data map[string]any)
- func (c *Client) EmitError(action string, data map[string]any)
- func (c *Client) EmitWarn(action string, data map[string]any)
- func (c *Client) EmitWith(evt Event)
- func (c *Client) Flush()
- func (c *Client) Log(level, message string, fields map[string]any)
- func (c *Client) LogDebug(message string, fields map[string]any)
- func (c *Client) LogError(message string, fields map[string]any)
- func (c *Client) LogInfo(message string, fields map[string]any)
- func (c *Client) LogWarn(message string, fields map[string]any)
- func (c *Client) Timed(action string, data map[string]any) func(map[string]any)
- func (c *Client) WithChannel(channel string) *Client
- type Event
- type LogEntry
- type SlogHandler
- type SlogLogHandler
- type SlogLogOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends events to an eventrelay server. All methods are safe for concurrent use. If URL is empty, all operations are no-ops.
func (*Client) Emit ¶
Emit sends an info-level event. Fire-and-forget — non-blocking, errors silently dropped.
func (*Client) Log ¶ added in v1.1.0
Log sends a structured log entry to the /log endpoint. Fire-and-forget.
func (*Client) Timed ¶
Timed is a helper for timing operations. Returns a function that emits the event with duration_ms set when called.
done := client.Timed("db_query", nil)
// ... do work ...
done(map[string]any{"rows": 42})
func (*Client) WithChannel ¶
WithChannel returns a new Client that tags all events with the given channel.
type Event ¶
type Event struct {
Source string `json:"source"`
Channel string `json:"channel,omitempty"`
Action string `json:"action,omitempty"`
Level string `json:"level,omitempty"`
AgentID string `json:"agent_id,omitempty"`
DurationMS *int64 `json:"duration_ms,omitempty"`
Data map[string]any `json:"data,omitempty"`
TS time.Time `json:"ts"`
}
Event is the payload sent to the relay.
type LogEntry ¶ added in v1.1.0
type LogEntry struct {
Level string `json:"level"`
Message string `json:"message"`
Logger string `json:"logger,omitempty"`
Fields map[string]any `json:"fields,omitempty"`
Caller string `json:"caller,omitempty"`
TS time.Time `json:"ts"`
}
LogEntry is the payload sent to the /log endpoint.
type SlogHandler ¶
type SlogHandler struct {
// contains filtered or unexported fields
}
SlogHandler implements slog.Handler, sending structured log records as events. Use with slog.New(eventrelay.NewSlogHandler(client, "logs")) to route all structured logging to the event relay as events on a channel.
func NewSlogHandler ¶
func NewSlogHandler(c *Client, channel string) *SlogHandler
NewSlogHandler creates a slog.Handler that sends log records as events.
type SlogLogHandler ¶ added in v1.1.0
type SlogLogHandler struct {
// contains filtered or unexported fields
}
SlogLogHandler implements slog.Handler, sending records to the /log endpoint as structured log entries (message, level, logger, fields, caller). Use with slog.New(eventrelay.NewSlogLogHandler(client)) for first-class log integration with the eventrelay Logs tab.
func NewSlogLogHandler ¶ added in v1.1.0
func NewSlogLogHandler(c *Client, opts *SlogLogOptions) *SlogLogHandler
NewSlogLogHandler creates a slog.Handler that sends to the /log endpoint. Logger name defaults to the client's source; override with the returned handler's WithLogger method if needed.
type SlogLogOptions ¶ added in v1.1.0
type SlogLogOptions struct {
Logger string // override logger name (default: client source)
AddSource bool // include file:line caller info
}
SlogLogOptions configures the log handler.