event

package
v2.16.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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.

View Source
const (
	MaxFacetValueLen = 200
	MaxFacetTags     = 50
)

Facet limits: long or numerous values (request ids as tags) would bloat the index without helping a filter.

View Source
const MaxSearchTextLen = 4096

MaxSearchTextLen caps the text indexed for search per event: the index takes a few times the size of its text.

Variables

View Source
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.

View Source
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

func FacetMap(facets []Facet) map[string][]string

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

func IsFacetKey(key string) bool

IsFacetKey reports whether key is a known facet key.

func NormalizeFacetValue added in v2.14.0

func NormalizeFacetValue(key, value string) string

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

func ScalarString(v any) string

ScalarString renders a JSON scalar as text; objects, arrays and null give "".

func TraceIDFromHeaders added in v2.14.0

func TraceIDFromHeaders(get func(name string) string) string

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

func TruncateText(s string, n int) string

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.

func NewEvent

func NewEvent(inc *Incoming) Event

NewEvent creates an Event from an Incoming with a generated timestamp.

type Facet added in v2.14.0

type Facet struct {
	Key   string
	Value string
}

Facet is one filterable value of an event, e.g. {host, web-1}.

type FacetCount added in v2.14.0

type FacetCount struct {
	Value string `json:"value"`
	Count int    `json:"count"`
}

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

type FacetFilter struct {
	Key    string
	Values []string
	Not    bool
}

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) Add added in v2.14.0

func (s *FacetSet) Add(key, value string)

Add adds key=value; empty values are skipped.

func (*FacetSet) AddTag added in v2.14.0

func (s *FacetSet) AddTag(name, value string)

AddTag adds tag name=value as key "tag:name".

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.

func (*FacetSet) List added in v2.14.0

func (s *FacetSet) List() []Facet

List returns the collected facets.

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.

Jump to

Keyboard shortcuts

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