Documentation
¶
Index ¶
- Constants
- Variables
- func FacetMap(facets []Facet) map[string][]string
- func FlattenJSON(raw json.RawMessage) string
- func GenerateUUID() string
- func IsFacetKey(key string) bool
- func NormalizeFacetValue(key, value string) string
- func Object(raw json.RawMessage) map[string]any
- func ScalarString(v any) string
- func TraceIDFromHeaders(get func(name string) string) string
- func TruncateText(s string, n int) string
- type DeleteOptions
- type Event
- type Facet
- type FacetCount
- type FacetExtractor
- type FacetFilter
- type FacetSet
- type FindOptions
- type Incoming
- type Preview
- type PreviewMapper
- type PreviewRegistry
- func (r *PreviewRegistry) BuildPreview(ev Event) Preview
- func (r *PreviewRegistry) Facets(eventType string, payload json.RawMessage) []Facet
- func (r *PreviewRegistry) Get(eventType string) PreviewMapper
- func (r *PreviewRegistry) Register(eventType string, mapper PreviewMapper)
- func (r *PreviewRegistry) SearchText(eventType string, payload json.RawMessage) string
- type SearchTextExtractor
- type Store
Constants ¶
const ( FacetHost = "host" FacetEnv = "env" FacetUser = "user" FacetChannel = "channel" FacetLevel = "level" FacetRelease = "release" // FacetTrace is the trace id of the request an event belongs to: links // logs, dumps and mails to its Sentry trace. FacetTrace = "trace" FacetTagPrefix = "tag:" )
Facet keys a feed can be filtered by. Tags use FacetTagPrefix + tag name.
const ( MaxFacetValueLen = 200 MaxFacetTags = 50 )
Facet limits: long or numerous values (request ids as tags) would bloat the index without helping a filter.
const MaxSearchTextLen = 4096
MaxSearchTextLen caps the text indexed for search per event: the index takes a few times the size of its text.
Variables ¶
var ErrMergeLimit = errors.New("event is full")
ErrMergeLimit: a Merge refuses a follow-up because the stored event is full; the follow-up is dropped.
var ErrNotFound = errors.New("event not found")
ErrNotFound: the event is not stored (e.g. deleted meanwhile).
Functions ¶
func FacetMap ¶ added in v2.14.0
FacetMap groups facets by key for the preview: {"host": ["web-1"]}.
func FlattenJSON ¶ added in v2.14.0
func FlattenJSON(raw json.RawMessage) string
FlattenJSON writes the keys and scalar values of a JSON document as space-separated text ("user_id 42 email a@b.c"), keys in sorted order.
func GenerateUUID ¶
func GenerateUUID() string
func IsFacetKey ¶ added in v2.14.0
IsFacetKey reports whether key is a known facet key.
func NormalizeFacetValue ¶ added in v2.14.0
NormalizeFacetValue brings a value to its stored form: levels are lower case, so Monolog's "WARNING" and Sentry's "warning" are one value.
func Object ¶ added in v2.14.0
func Object(raw json.RawMessage) map[string]any
Object decodes raw as a JSON object; anything else (PHP sends an empty object as [], or null) gives nil, so one odd field never loses the rest.
func ScalarString ¶ added in v2.14.0
ScalarString renders a JSON scalar as text; objects, arrays and null give "".
func TraceIDFromHeaders ¶ added in v2.14.0
TraceIDFromHeaders finds the trace id of the request that sent a message (a mail, an HTTP call) in its headers. get returns a header value by its canonical name. It reads, in order:
- sentry-trace: "<trace id>-<span id>[-<sampled>]", which Sentry SDKs add to outgoing HTTP calls;
- traceparent (W3C): "00-<trace id>-<span id>-<flags>", from OTel and current Sentry SDKs;
- X-Trace-Id: the trace id alone, for apps that set it on mails.
The id is returned in lower case, or "" when no header holds a valid one.
func TruncateText ¶ added in v2.14.0
TruncateText cuts s to at most n bytes on a rune boundary.
Types ¶
type DeleteOptions ¶
type DeleteOptions struct {
Type string
Project string
UUIDs []string
// KeepPinned leaves pinned events in place.
KeepPinned bool
}
DeleteOptions configures batch deletion.
type Event ¶
type Event struct {
UUID string `json:"uuid"`
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
Timestamp float64 `json:"timestamp"`
Project string `json:"project,omitempty"`
IsPinned bool `json:"is_pinned"`
}
Event represents a stored debugging event.
type FacetCount ¶ added in v2.14.0
FacetCount is one value of a facet key with the number of events having it.
type FacetExtractor ¶ added in v2.14.0
type FacetExtractor interface {
Facets(payload json.RawMessage) []Facet
}
FacetExtractor is implemented by a PreviewMapper whose payloads carry filterable values (machine, environment, user, channel, tags).
type FacetFilter ¶ added in v2.14.0
FacetFilter selects events by one facet key: an event matches when it has any of Values for Key (OR within a key); Not inverts it. Filters on different keys combine with AND.
type FacetSet ¶ added in v2.14.0
type FacetSet struct {
// contains filtered or unexported fields
}
FacetSet collects facets with trimming, length cap, tag cap and de-duplication. The zero value is ready to use.
func (*FacetSet) AddTags ¶ added in v2.14.0
func (s *FacetSet) AddTags(raw json.RawMessage)
AddTags adds tags given as a JSON object {"k":"v"} or a list [["k","v"]] (both shapes are sent by Sentry SDKs). Non-string scalars are stringified.
type FindOptions ¶
type FindOptions struct {
Type string
Project string
Limit int
Offset int
// From and To bound the selection by event time (unix seconds with a
// fraction, same as Event.Timestamp). Zero means "no bound".
From float64
To float64
// PinnedFirst puts pinned events before the rest, so a limit never
// pushes a pinned event out of the list.
PinnedFirst bool
// Filters select events by their facets (machine, environment, tags…).
Filters []FacetFilter
// Search selects events whose indexed text (SearchTextExtractor)
// contains every word of it, case-insensitive. Empty: no search.
Search string
}
FindOptions configures event listing queries.
type Incoming ¶
type Incoming struct {
UUID string
Type string
Payload json.RawMessage
Project string
// Merge, when set, folds this payload into a stored event with the same
// UUID and type instead of storing a new one (Ray sends follow-ups such
// as trace or color under the uuid of the first payload). It gets the
// stored payload and returns the merged one.
Merge func(stored json.RawMessage) (json.RawMessage, error)
// Respond, when set, writes the HTTP answer after the event is stored,
// instead of the default acknowledgement (a provider API the client
// expects to answer in its own shape, e.g. Twilio's 201 with a sid).
Respond func(w http.ResponseWriter)
// NoEvent: the handler already stored what it needed (e.g. OTLP spans
// and logs in their own tables) and wants no events row; the pipeline
// only answers, with Respond when set.
NoEvent bool
}
Incoming is what an ingestion handler produces before storage.
type Preview ¶
type Preview struct {
UUID string `json:"uuid"`
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
Timestamp float64 `json:"timestamp"`
Project string `json:"project,omitempty"`
SearchableText string `json:"searchable_text"`
IsPinned bool `json:"is_pinned"`
// Facets are the event's filterable values ({"host": ["web-1"]}), so
// the UI can filter live events the same way the API does.
Facets map[string][]string `json:"facets,omitempty"`
}
Preview is the compact representation sent to the UI list and WebSocket.
type PreviewMapper ¶
type PreviewMapper interface {
ToPreview(payload json.RawMessage) (json.RawMessage, error)
ToSearchableText(payload json.RawMessage) string
}
PreviewMapper transforms full event payloads into preview/searchable form.
type PreviewRegistry ¶
type PreviewRegistry struct {
// contains filtered or unexported fields
}
PreviewRegistry maps event types to their PreviewMapper.
func NewPreviewRegistry ¶
func NewPreviewRegistry() *PreviewRegistry
func (*PreviewRegistry) BuildPreview ¶
func (r *PreviewRegistry) BuildPreview(ev Event) Preview
BuildPreview creates a Preview from an Event using the registered mapper.
func (*PreviewRegistry) Facets ¶ added in v2.14.0
func (r *PreviewRegistry) Facets(eventType string, payload json.RawMessage) []Facet
Facets returns the filterable values of a payload of eventType, or nil when its mapper extracts none.
func (*PreviewRegistry) Get ¶
func (r *PreviewRegistry) Get(eventType string) PreviewMapper
func (*PreviewRegistry) Register ¶
func (r *PreviewRegistry) Register(eventType string, mapper PreviewMapper)
func (*PreviewRegistry) SearchText ¶ added in v2.14.0
func (r *PreviewRegistry) SearchText(eventType string, payload json.RawMessage) string
SearchText returns the text to index for a payload of eventType, or "" when its mapper indexes none.
type SearchTextExtractor ¶ added in v2.14.0
type SearchTextExtractor interface {
SearchText(payload json.RawMessage) string
}
SearchTextExtractor is implemented by a PreviewMapper whose events can be found by full-text search (GET /api/events?q=).
type Store ¶
type Store interface {
Store(ctx context.Context, ev Event) error
FindByUUID(ctx context.Context, uuid string) (*Event, error)
FindAll(ctx context.Context, opts FindOptions) ([]Event, error)
Delete(ctx context.Context, uuid string) error
DeleteAll(ctx context.Context, opts DeleteOptions) error
// UpdatePayload replaces the payload of a stored event; ErrNotFound when
// there is none.
UpdatePayload(ctx context.Context, uuid string, payload json.RawMessage) error
Pin(ctx context.Context, uuid string) error
Unpin(ctx context.Context, uuid string) error
}
Store persists and retrieves events.