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

Function TestHandler_SDKv3_Envelope

modules/sentry/handler_test.go:342–379  ·  view source on GitHub ↗

TestHandler_SDKv3_Envelope tests Sentry PHP SDK v3 with tracing enabled. v3 sends envelope to /api/{project}/envelope with event_id in BOTH envelope header AND item payload.

(t *testing.T)

Source from the content-addressed store, hash-verified

340// TestHandler_SDKv3_Envelope tests Sentry PHP SDK v3 with tracing enabled.
341// v3 sends envelope to /api/{project}/envelope with event_id in BOTH envelope header AND item payload.
342func TestHandler_SDKv3_Envelope(t *testing.T) {
343 h := &handler{}
344
345 // Real payload structure from sentry/sentry 3.22.1 (tracing enabled → envelope to /envelope).
346 envelope := `{"event_id":"3663da0e4e864104a584bf6a053b3ab9","sent_at":"2026-03-31T12:36:30Z","dsn":"http://test@localhost:8000/1","sdk":{"name":"sentry.php","version":"3.22.1"}}
347{"type":"event","content_type":"application/json"}
348{"event_id":"3663da0e4e864104a584bf6a053b3ab9","timestamp":1774960590.323862,"platform":"php","sdk":{"name":"sentry.php","version":"3.22.1"},"level":"error","server_name":"web-01","release":"1.0.0","environment":"production","exception":{"values":[{"type":"RuntimeException","value":"Something went wrong"}]}}`
349
350 r := httptest.NewRequest("POST", "/api/1/envelope/", strings.NewReader(envelope))
351 r.Header.Set("Content-Type", "application/x-sentry-envelope")
352 r.Header.Set("X-Sentry-Auth", "Sentry sentry_version=7, sentry_client=sentry.php/3.22.1, sentry_key=test")
353
354 inc, err := h.Handle(r)
355 if err != nil {
356 t.Fatalf("Handle() error: %v", err)
357 }
358 if inc == nil {
359 t.Fatal("Handle() returned nil, want non-nil incoming event")
360 }
361 if inc.Type != "sentry" {
362 t.Errorf("Type = %q, want %q", inc.Type, "sentry")
363 }
364 if inc.UUID != "3663da0e4e864104a584bf6a053b3ab9" {
365 t.Errorf("UUID = %q, want %q", inc.UUID, "3663da0e4e864104a584bf6a053b3ab9")
366 }
367
368 // Payload must contain event_id so the frontend can identify the event.
369 var parsed map[string]any
370 if err := json.Unmarshal(inc.Payload, &parsed); err != nil {
371 t.Fatalf("failed to parse payload: %v", err)
372 }
373 if parsed["event_id"] != "3663da0e4e864104a584bf6a053b3ab9" {
374 t.Errorf("payload event_id = %v, want %q", parsed["event_id"], "3663da0e4e864104a584bf6a053b3ab9")
375 }
376 if parsed["level"] != "error" {
377 t.Errorf("payload level = %v, want %q", parsed["level"], "error")
378 }
379}
380
381// TestHandler_SDKv4_Envelope tests Sentry PHP SDK v4.
382// v4 ALWAYS sends envelope to /api/{project}/envelope.

Callers

nothing calls this directly

Calls 1

HandleMethod · 0.95

Tested by

no test coverage detected