-
Notifications
You must be signed in to change notification settings - Fork 242
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
Open
giortzisg
wants to merge
51
commits into
master
Choose a base branch
from
feat/telemetry-scheduler
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
8a50583
add ring buffer implementation
giortzisg 0c154b8
add new transport
giortzisg 2ccb148
fix race
giortzisg de5b70a
fix lint
giortzisg fc93d2c
fix lint
giortzisg 3c7498e
fix tests
giortzisg 0a406ba
modify envelope serialization and tests
giortzisg 6f9c638
change transport opts
giortzisg bf26d59
remove transport.Configure
giortzisg c7205ca
add proper await on queue flush
giortzisg 8c8a4bd
add test for marshall fallback
giortzisg 4228142
fix tests
giortzisg 803349d
add sendEvent
giortzisg 51f0373
fix dsn exporting
giortzisg 58a7b02
enhance transport test suite
giortzisg 1ed184b
change backpressure test
giortzisg 2d66573
merge categories
giortzisg 7a2f452
Merge branch 'master' into feat/transport-envelope
giortzisg a146a1e
specify min tls version
giortzisg 871ade0
use global debuglog
giortzisg 4c15f3a
chore: amend debug output and func comments
giortzisg b2c7dc4
chore: refactor tests
giortzisg 9d368d4
chore: fix overflow test
giortzisg d2b2a6f
chore: move overflow policy
giortzisg a357417
add noopTransport
giortzisg 992feaf
add internalTransport wrapper
giortzisg bc5d4b8
chore: make internalTransportAdapter private
giortzisg f89d05d
chore: fix race
giortzisg ec10979
chore: reexport internal wrapper
giortzisg 17d1a15
change RequestHeaders receiver
giortzisg d206afe
modify internal transport adapters
giortzisg 06fd3f8
add batchsize & timeout to buffers
giortzisg 193c8ad
Merge branch 'master' into feat/transport-buffers
giortzisg 87ce064
Merge branch 'origin/feat/transport-buffers'
giortzisg 3f2b23c
Merge branch 'origin/feat/transport-envelope'
giortzisg 2b718b0
feat: add scheduler
giortzisg 95106d8
Merge branch 'feat/transport-envelope' into feat/telemetry-scheduler
lcian d61df59
Merge branch 'feat/transport-buffers' into feat/transport-envelope
giortzisg 6be99a3
Merge branch 'feat/transport-envelope' into feat/telemetry-scheduler
giortzisg e18a54d
properly batch logs
giortzisg 37e1bad
chore: add debug statements for transport flush
giortzisg 9ae389d
chore: fix buffer double flush
giortzisg c654832
fix: correctly batch log items
giortzisg ceef544
add debug log if buffer missing
giortzisg b8d15d6
fix client
giortzisg 43b7812
add buffer interface
giortzisg 7c87bb6
chore: rename logItem
giortzisg b1bfe59
chore: fix lint
giortzisg e0478a2
chore: fix processItems
giortzisg ea10ecb
Merge branch 'master' into feat/telemetry-scheduler
giortzisg cda84db
add buffer wrapper
giortzisg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,4 @@ coverage: | |
| threshold: 0.5% | ||
| ignore: | ||
| - "log_fallback.go" | ||
| - "internal/testutils" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -493,6 +493,70 @@ func (e *Event) ToEnvelopeWithTime(dsn *protocol.Dsn, sentAt time.Time) (*protoc | |
| return envelope, nil | ||
| } | ||
|
|
||
| // 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 | ||
| e.Breadcrumbs = nil | ||
| e.Contexts = nil | ||
| e.Extra = map[string]interface{}{ | ||
| "info": fmt.Sprintf("Could not encode original event as JSON. "+ | ||
| "Succeeded by removing Breadcrumbs, Contexts and Extra. "+ | ||
| "Please verify the data you attach to the scope. "+ | ||
| "Error: %s", err), | ||
| } | ||
|
|
||
| eventBody, err = json.Marshal(e) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("event could not be marshaled even with fallback: %w", err) | ||
| } | ||
|
|
||
| DebugLogger.Printf("Event marshaling succeeded with fallback after removing problematic fields") | ||
| } | ||
|
|
||
| // TODO: all event types should be abstracted to implement EnvelopeItemConvertible and convert themselves. | ||
| var item *protocol.EnvelopeItem | ||
| switch e.Type { | ||
| case transactionType: | ||
| item = protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeTransaction, eventBody) | ||
| case checkInType: | ||
| item = protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeCheckIn, eventBody) | ||
| case logEvent.Type: | ||
| item = protocol.NewLogItem(len(e.Logs), eventBody) | ||
| default: | ||
| item = protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeEvent, eventBody) | ||
| } | ||
|
|
||
| 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 | ||
| } | ||
|
|
||
| // 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, | ||
| // to prevent accidentally storing T when we mean *T. | ||
| // For example, the TraceContext must be stored as *TraceContext to pick up the | ||
|
|
@@ -667,6 +731,69 @@ type Log struct { | |
| Attributes map[string]Attribute `json:"attributes,omitempty"` | ||
| } | ||
|
|
||
| // ToEnvelopeItem converts the Log to a Sentry envelope item for batching. | ||
| func (l *Log) ToEnvelopeItem() (*protocol.EnvelopeItem, error) { | ||
| type logJSON struct { | ||
| Timestamp *float64 `json:"timestamp,omitempty"` | ||
| TraceID string `json:"trace_id,omitempty"` | ||
| Level string `json:"level"` | ||
| Severity int `json:"severity_number,omitempty"` | ||
| Body string `json:"body,omitempty"` | ||
| Attributes map[string]protocol.LogAttribute `json:"attributes,omitempty"` | ||
| } | ||
|
Comment on lines
+736
to
+743
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. Hmm I see the reason why we need this type now, e.g. |
||
|
|
||
| // Convert time.Time to seconds float if set | ||
| var ts *float64 | ||
| if !l.Timestamp.IsZero() { | ||
| sec := float64(l.Timestamp.UnixNano()) / 1e9 | ||
| ts = &sec | ||
| } | ||
|
|
||
| attrs := make(map[string]protocol.LogAttribute, len(l.Attributes)) | ||
| for k, v := range l.Attributes { | ||
| attrs[k] = protocol.LogAttribute{Value: v.Value, Type: string(v.Type)} | ||
| } | ||
|
|
||
| logData, err := json.Marshal(logJSON{ | ||
| Timestamp: ts, | ||
| TraceID: l.TraceID.String(), | ||
| Level: string(l.Level), | ||
| Severity: l.Severity, | ||
| Body: l.Body, | ||
| Attributes: attrs, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &protocol.EnvelopeItem{ | ||
| Header: &protocol.EnvelopeItemHeader{ | ||
| Type: protocol.EnvelopeItemTypeLog, | ||
| }, | ||
| Payload: logData, | ||
| }, nil | ||
| } | ||
|
|
||
| // GetCategory returns the rate limit category for logs. | ||
| func (l *Log) GetCategory() ratelimit.Category { | ||
| return ratelimit.CategoryLog | ||
| } | ||
|
|
||
| // GetEventID returns empty string (event ID set when batching). | ||
| func (l *Log) GetEventID() string { | ||
| return "" | ||
| } | ||
|
|
||
| // GetSdkInfo returns nil (SDK info set when batching). | ||
| func (l *Log) GetSdkInfo() *protocol.SdkInfo { | ||
| return nil | ||
| } | ||
|
|
||
| // GetDynamicSamplingContext returns nil (trace context set when batching). | ||
| func (l *Log) GetDynamicSamplingContext() map[string]string { | ||
| return nil | ||
| } | ||
lcian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| type AttrType string | ||
|
|
||
| const ( | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Bug: Event Mutation During JSON Fallback
The
ToEnvelopeItemmethod mutates the originalEventobject during its JSON marshaling fallback. This modification, affectingBreadcrumbs,Contexts, andExtra, can cause data loss or unexpected behavior if theEventis reused.