MCPcopy Create free account
hub / github.com/buggregator/server / handleEnvelope

Method handleEnvelope

modules/sentry/handler.go:104–183  ·  view source on GitHub ↗

handleEnvelope parses Sentry envelope format and routes each item to the appropriate storage function.

(body []byte, project string)

Source from the content-addressed store, hash-verified

102// handleEnvelope parses Sentry envelope format and routes each item
103// to the appropriate storage function.
104func (h *handler) handleEnvelope(body []byte, project string) (*event.Incoming, error) {
105 envHeader, items, err := parseEnvelopeItems(body)
106 if err != nil {
107 return nil, err
108 }
109
110 // Track the primary item for the canonical event.
111 var primaryUUID string
112 var primaryPayload json.RawMessage
113 var primaryType string
114
115 if envHeader.EventID != "" {
116 primaryUUID = envHeader.EventID
117 }
118
119 for _, item := range items {
120 switch item.Type {
121 case "event":
122 uuid, payload := h.handleEventItem(item, envHeader.EventID, project)
123 if uuid != "" {
124 primaryUUID = uuid
125 }
126 if payload != nil {
127 primaryPayload = payload
128 primaryType = "sentry"
129 }
130
131 case "transaction":
132 // Transactions are stored in structured tables (sentry_transactions, sentry_spans)
133 // but should NOT appear in the global event feed as empty sentry cards.
134 h.handleTransactionItem(item)
135
136 case "spans":
137 h.handleSpansItem(item)
138
139 case "log":
140 h.handleLogItem(item)
141
142 case "session", "sessions", "client_report", "metric_buckets", "check_in",
143 "user_report", "attachment", "replay_event", "replay_recording", "statsd":
144 // Silently discard known non-essential item types.
145
146 default:
147 slog.Debug("sentry: ignoring unknown envelope item type", "type", item.Type)
148 }
149 }
150
151 // Validate the primary payload is valid JSON; if not, discard it.
152 if primaryPayload != nil && !json.Valid(primaryPayload) {
153 primaryPayload = nil
154 }
155
156 // If no primary payload was extracted, fall back to envelope wrapping.
157 // Skip transaction/spans/log items — they are stored in structured tables only.
158 if primaryPayload == nil {
159 primaryType = "sentry"
160 for _, item := range items {
161 if item.Type == "transaction" || item.Type == "spans" || item.Type == "log" {

Callers 4

HandleMethod · 0.95
TestSessionItemDiscardedFunction · 0.95
TestHandlerWithDBFunction · 0.95
TestHandleEnvelopeFunction · 0.95

Calls 5

handleEventItemMethod · 0.95
handleTransactionItemMethod · 0.95
handleSpansItemMethod · 0.95
handleLogItemMethod · 0.95
parseEnvelopeItemsFunction · 0.85

Tested by 3

TestSessionItemDiscardedFunction · 0.76
TestHandlerWithDBFunction · 0.76
TestHandleEnvelopeFunction · 0.76