Skip to content

Conversation

giortzisg
Copy link
Contributor

@giortzisg giortzisg commented Oct 7, 2025

Description

Add telemetry scheduler implementation and integrate with the client. The current PR also includes changes on the transport and envelope layer.

The proper solution for batching under the scheduler is to abstract each event type, so that it knows how to convert itself to an envelope item (noted as EnvelopeItemConvertible in the PR), and then the scheduler would just create envelopes using []EnvelopeItemConvertible. This partially fixes the issue, since currently everything is anchored around the Event type. We should also abstract all event types to implement EnvelopeItemConvertible in the future.

Notes

  • As discussed above, we need to change the EnvelopeConvertible to EnvelopeItemConvertible introduced in feat: add new envelope transport #1094. For the sake of clarity I added the changes here and not on the other PR. Same applies with ToEnvelope
  • Not 100% sure on how to approach metadata required on the EnvelopeHeader. Left some comments on the implementation.

Issues

Copy link

linear bot commented Oct 7, 2025

@giortzisg giortzisg changed the base branch from master to feat/transport-envelope October 7, 2025 12:37
Copy link

codecov bot commented Oct 7, 2025

Codecov Report

❌ Patch coverage is 61.60458% with 134 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.03%. Comparing base (d61df59) to head (ceef544).

Files with missing lines Patch % Lines
client.go 10.52% 47 Missing and 4 partials ⚠️
interfaces.go 35.89% 24 Missing and 1 partial ⚠️
internal/telemetry/scheduler.go 86.07% 16 Missing and 6 partials ⚠️
transport.go 6.25% 11 Missing and 4 partials ⚠️
internal/protocol/envelope.go 72.72% 6 Missing and 3 partials ⚠️
log.go 46.15% 6 Missing and 1 partial ⚠️
internal/http/transport.go 78.26% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@                     Coverage Diff                     @@
##           feat/transport-envelope    #1107      +/-   ##
===========================================================
- Coverage                    86.64%   86.03%   -0.61%     
===========================================================
  Files                           60       58       -2     
  Lines                         6894     7080     +186     
===========================================================
+ Hits                          5973     6091     +118     
- Misses                         739      795      +56     
- Partials                       182      194      +12     

☔ 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.

@giortzisg giortzisg force-pushed the feat/telemetry-scheduler branch 4 times, most recently from 1ecf9c6 to d998585 Compare October 9, 2025 14:07
@giortzisg giortzisg changed the base branch from feat/transport-envelope to master October 10, 2025 08:23
@giortzisg giortzisg changed the base branch from master to feat/transport-envelope October 10, 2025 08:24
@giortzisg giortzisg force-pushed the feat/telemetry-scheduler branch from 6557a90 to 2b718b0 Compare October 10, 2025 09:03
@giortzisg giortzisg changed the base branch from feat/transport-envelope to master October 10, 2025 09:06
@giortzisg giortzisg changed the base branch from master to feat/transport-envelope October 10, 2025 09:08
Comment on lines 223 to 229
firstItem := items[0]

header := &EnvelopeHeader{
EventID: firstItem.GetEventID(),
SentAt: time.Now(),
Trace: firstItem.GetDynamicSamplingContext(),
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this works would work in the future for batching spans. For logs it's ok, since we get the trace id from each log item.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we would send the DSC as span attributes then you would be able to batch spans in any way you want, not necessarily group them by trace id always.
@cleptric is this planned?

Copy link
Member

@cleptric cleptric Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No plans at the moment. The main reason we batch spans by trace id is to enforce a certain traffic pattern in the ingestion segment buffer when it comes to insertion performance.

@giortzisg giortzisg marked this pull request as ready for review October 10, 2025 10:12
@giortzisg giortzisg requested review from cleptric and lcian October 10, 2025 10:13
cursor[bot]

This comment was marked as outdated.

Comment on lines +533 to 543
func (e *Event) GetDynamicSamplingContext() map[string]string {
trace := make(map[string]string)
if dsc := e.sdkMetaData.dsc; dsc.HasEntries() {
for k, v := range dsc.Entries {
trace[k] = v
}
}
return trace
}

// TODO: Event.Contexts map[string]interface{} => map[string]EventContext,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential bug: When the telemetry buffer is enabled, the new Event.ToEnvelopeItem() method fails to include attachments from event.Attachments, causing them to be dropped from the final envelope.
  • Description: When the telemetry buffer feature is enabled, event attachments are silently lost. The new Event.ToEnvelopeItem() method, which is called when processing buffered items, only converts the event itself into an envelope item and neglects to process the event.Attachments field. This is a regression from the previous Event.ToEnvelope() implementation, which explicitly iterated over attachments and added them to the envelope. This results in silent data loss for any events that have attachments, both in the main scheduler path and the fallback path.

  • Suggested fix: Modify Event.ToEnvelopeItem() to handle attachments. It should create and return protocol.NewAttachmentItem for each attachment found in the event.Attachments slice, adding them to the envelope alongside the event item. This restores the functionality of the removed Event.ToEnvelope() method.
    severity: 0.85, confidence: 0.98

Did we get this right? 👍 / 👎 to inform future reviews.

firstItem := items[0]

header := &EnvelopeHeader{
EventID: firstItem.GetEventID(),
Copy link
Member

@lcian lcian Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how it happens but when we send logs this is empty string so we get 400 from Relay, please fix it.

Copy link
Member

@lcian lcian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will continue the review on Monday.

Please add more debug logs to the transport as well (other PR I guess but here is also fine).
When testing manually I expect to see logs like

[Sentry] 2025/10/10 16:42:10 Sending info event [599f87ae22b848d7997cad821eb0fa8c] to o<x>.ingest.us.sentry.io project: <project>
[Sentry] 2025/10/10 16:42:10 Buffer flushed successfully.

and with the new transport + buffer I don't see anything and think stuff is not working.
Now it seems useless but when you get bug reports this is very useful info to have.

cursor[bot]

This comment was marked as outdated.

Copy link

linear bot commented Oct 13, 2025

@cleptric cleptric added the Feature Issue type label Oct 13, 2025
@cleptric cleptric requested review from cleptric and removed request for cleptric October 13, 2025 09:11
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

event.Logs = logs
l.client.CaptureEvent(event, nil, nil)
l.client.Transport.SendEvent(event)
//l.client.CaptureEvent(event, nil, nil)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Event Processing Bypassed in Debug Code

The processEvent function now calls l.client.Transport.SendEvent(event), bypassing the full event processing pipeline (event processors, sampling, BeforeSend callbacks, and scope application). The commented CaptureEvent line suggests this was debug code accidentally committed.

Fix in Cursor Fix in Web

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.

Create envelope scheduler

3 participants