Skip to content

Conversation

DAcodedBEAT
Copy link
Contributor

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:

  • Spotlight transport decorator supporting custom URL overrides
  • SENTRY_SPOTLIGHT environment variable for easy enabling
  • Example program demonstrating usage patterns
  • README documentation update

Copy link

codecov bot commented Sep 15, 2025

Codecov Report

❌ Patch coverage is 63.54167% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.65%. Comparing base (4763853) to head (ae10b0d).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
transport.go 52.05% 29 Missing and 6 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cleptric cleptric marked this pull request as draft September 15, 2025 19:56
@cleptric
Copy link
Member

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.

@DAcodedBEAT
Copy link
Contributor Author

@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!

@cleptric cleptric marked this pull request as ready for review October 1, 2025 01:10
@cleptric
Copy link
Member

cleptric commented Oct 1, 2025

I'm ok merging this now instead of waiting for our refactoring, as the surface area is indeed rather small.
If you could address the lint issue, we can review it and write docs prior the release.

cursor[bot]

This comment was marked as outdated.

@cleptric cleptric requested a review from BYK October 1, 2025 18:59
@cleptric cleptric added the Feature Issue type label Oct 1, 2025
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
@DAcodedBEAT
Copy link
Contributor Author

I'm ok merging this now instead of waiting for our refactoring, as the surface area is indeed rather small. If you could address the lint issue, we can review it and write docs prior the release.

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!

Copy link
Contributor

@giortzisg giortzisg left a 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.

Comment on lines +380 to +385
if !client.options.Spotlight {
if spotlightEnv := os.Getenv("SENTRY_SPOTLIGHT"); spotlightEnv == "true" || spotlightEnv == "1" {
client.options.Spotlight = true
}
}

Copy link
Contributor

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.

Comment on lines +776 to +779
// Send to the underlying transport (Sentry) unless it's noopTransport
if _, isNoop := st.underlying.(noopTransport); !isNoop {
st.underlying.SendEvent(event)
}
Copy link
Contributor

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.")
}
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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.

Comment on lines +151 to +170
// 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() {}
Copy link
Contributor

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) {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Spotlight

3 participants