-
Notifications
You must be signed in to change notification settings - Fork 241
feat: add telemetry scheduler #1107
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: feat/transport-envelope
Are you sure you want to change the base?
Changes from 6 commits
87ce064
3f2b23c
2b718b0
95106d8
6be99a3
e18a54d
37e1bad
9ae389d
c654832
ceef544
b8d15d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ coverage: | |
threshold: 0.5% | ||
ignore: | ||
- "log_fallback.go" | ||
- "internal/testutils" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -476,37 +476,8 @@ func (e *Event) SetException(exception error, maxErrorDepth int) { | |
} | ||
} | ||
|
||
// ToEnvelope converts the Event to a Sentry envelope. | ||
// This includes the event data and any attachments as separate envelope items. | ||
func (e *Event) ToEnvelope(dsn *protocol.Dsn) (*protocol.Envelope, error) { | ||
return e.ToEnvelopeWithTime(dsn, time.Now()) | ||
} | ||
|
||
// ToEnvelopeWithTime converts the Event to a Sentry envelope with a specific sentAt time. | ||
// This is primarily useful for testing with predictable timestamps. | ||
func (e *Event) ToEnvelopeWithTime(dsn *protocol.Dsn, sentAt time.Time) (*protocol.Envelope, error) { | ||
// Create envelope header with trace context | ||
trace := make(map[string]string) | ||
if dsc := e.sdkMetaData.dsc; dsc.HasEntries() { | ||
for k, v := range dsc.Entries { | ||
trace[k] = v | ||
} | ||
} | ||
|
||
header := &protocol.EnvelopeHeader{ | ||
EventID: string(e.EventID), | ||
SentAt: sentAt, | ||
Trace: trace, | ||
} | ||
|
||
if dsn != nil { | ||
header.Dsn = dsn.String() | ||
} | ||
|
||
header.Sdk = &e.Sdk | ||
|
||
envelope := protocol.NewEnvelope(header) | ||
|
||
// ToEnvelopeItem converts the Event to a Sentry envelope item. | ||
func (e *Event) ToEnvelopeItem() (*protocol.EnvelopeItem, error) { | ||
eventBody, err := json.Marshal(e) | ||
if err != nil { | ||
// Try fallback: remove problematic fields and retry | ||
|
@@ -527,25 +498,46 @@ func (e *Event) ToEnvelopeWithTime(dsn *protocol.Dsn, sentAt time.Time) (*protoc | |
DebugLogger.Printf("Event marshaling succeeded with fallback after removing problematic fields") | ||
} | ||
|
||
var mainItem *protocol.EnvelopeItem | ||
// TODO: all event types should be abstracted to implement EnvelopeItemConvertible and convert themselves. | ||
var item *protocol.EnvelopeItem | ||
switch e.Type { | ||
case transactionType: | ||
mainItem = protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeTransaction, eventBody) | ||
item = protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeTransaction, eventBody) | ||
case checkInType: | ||
mainItem = protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeCheckIn, eventBody) | ||
item = protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeCheckIn, eventBody) | ||
case logEvent.Type: | ||
mainItem = protocol.NewLogItem(len(e.Logs), eventBody) | ||
item = protocol.NewLogItem(len(e.Logs), eventBody) | ||
default: | ||
mainItem = protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeEvent, eventBody) | ||
item = protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeEvent, eventBody) | ||
} | ||
|
||
envelope.AddItem(mainItem) | ||
for _, attachment := range e.Attachments { | ||
attachmentItem := protocol.NewAttachmentItem(attachment.Filename, attachment.ContentType, attachment.Payload) | ||
envelope.AddItem(attachmentItem) | ||
} | ||
return item, nil | ||
} | ||
|
||
// GetCategory returns the rate limit category for this event. | ||
func (e *Event) GetCategory() ratelimit.Category { | ||
return e.toCategory() | ||
} | ||
|
||
// GetEventID returns the event ID. | ||
func (e *Event) GetEventID() string { | ||
return string(e.EventID) | ||
} | ||
|
||
// GetSdkInfo returns SDK information for the envelope header. | ||
func (e *Event) GetSdkInfo() *protocol.SdkInfo { | ||
return &e.Sdk | ||
} | ||
|
||
return envelope, nil | ||
// GetDynamicSamplingContext returns trace context for the envelope header. | ||
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, | ||
Comment on lines
+533
to
543
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential bug: When the telemetry buffer is enabled, the new
|
||
|
Uh oh!
There was an error while loading. Please reload this page.