-
Notifications
You must be signed in to change notification settings - Fork 241
feat: Add Spotlight integration for local development debugging #1085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1085 +/- ##
==========================================
- Coverage 86.98% 86.65% -0.34%
==========================================
Files 55 56 +1
Lines 6070 6167 +97
==========================================
+ Hits 5280 5344 +64
- Misses 645 673 +28
- Partials 145 150 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Thanks for your PR, but we won't merge this anytime soon. We have a big refactor coming in our transport and we can look at this afterwards maybe. |
@cleptric Thanks for the update! I first asked about Spotlight support back in June 2024 and only heard back a year later with "no progress", so I went ahead and built this to give the community something useful and closer to what Python/JS already have (and to help offload some effort since the Sentry team is swamped). I understand holding off until the transport refactor, but is there a public roadmap or place where this is being discussed? It would really help contributors know what’s changing and avoid working on features that might get blocked. Happy to rebase once things stabilize! |
493d2c2
to
7ba9727
Compare
I'm ok merging this now instead of waiting for our refactoring, as the surface area is indeed rather small. |
Add SpotlightTransport that sends events to local Spotlight server for real-time debugging during development. The integration works by wrapping the existing transport and duplicating events to Spotlight. Features: - Spotlight transport decorator supporting custom URL overrides - SENTRY_SPOTLIGHT environment variable for easy enabling - Example program demonstrating usage patterns - README documentation update
7ba9727
to
ae10b0d
Compare
Sorry for missing the lint errors! I've fixed it and re-pushed (trying to keep a clean git history for y'all). Let me know if there's anything else I can do to get this merged! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. Left some small comments. Let's get them fixed and we can merge this.
if !client.options.Spotlight { | ||
if spotlightEnv := os.Getenv("SENTRY_SPOTLIGHT"); spotlightEnv == "true" || spotlightEnv == "1" { | ||
client.options.Spotlight = true | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This option should be on the NewClient
method.
// Send to the underlying transport (Sentry) unless it's noopTransport | ||
if _, isNoop := st.underlying.(noopTransport); !isNoop { | ||
st.underlying.SendEvent(event) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really need the check here. If the user incorrectly set the transport it's helpful to get the debug message from the noopTransport when sending the event.
DebugLogger.Printf("Buffer flushing was canceled or timed out. %d items were not flushed.", itemCount) | ||
} else { | ||
DebugLogger.Println("Buffer flushing was canceled or timed out. No items were pending.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor is right here.
} | ||
|
||
req.Header.Set("Content-Type", "application/x-sentry-envelope") | ||
req.Header.Set("User-Agent", "sentry-go/"+SDKVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We should use the event.Sdk.Name
and event.Sdk.Version
here.
return | ||
} | ||
|
||
req, err := http.NewRequest("POST", st.spotlightURL, envelope) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we should use ctx here.
|
||
if resp.StatusCode < 200 || resp.StatusCode >= 300 { | ||
DebugLogger.Printf("Spotlight returned non-2xx status: %d", resp.StatusCode) | ||
if body, err := io.ReadAll(resp.Body); err == nil && len(body) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to reuse the http connection we should drain the body on every request, not only on failures.
// mockTransport is a simple transport for testing. | ||
type mockTransport struct { | ||
events []*Event | ||
} | ||
|
||
func (m *mockTransport) Configure(ClientOptions) {} | ||
|
||
func (m *mockTransport) SendEvent(event *Event) { | ||
m.events = append(m.events, event) | ||
} | ||
|
||
func (m *mockTransport) Flush(time.Duration) bool { | ||
return true | ||
} | ||
|
||
func (m *mockTransport) FlushWithContext(_ context.Context) bool { | ||
return true | ||
} | ||
|
||
func (m *mockTransport) Close() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have a MockTransport
instance that can be used for tests.
"time" | ||
) | ||
|
||
func TestSpotlightTransport(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we can extend this test to verify that the underlying transport actually flushes and sends the events as well, so that it guards against breaking it.
resolves: #846
Add SpotlightTransport that sends events to local Spotlight server for real-time debugging during development. The integration works by wrapping the existing transport and duplicating events to Spotlight.
Features: