-
Notifications
You must be signed in to change notification settings - Fork 243
feat: Sentry Metrics #1151
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?
feat: Sentry Metrics #1151
Conversation
| Name: m.Name, | ||
| Value: m.Value, | ||
| Unit: m.Unit, | ||
| Attributes: attrs, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &protocol.EnvelopeItem{ | ||
| Header: &protocol.EnvelopeItemHeader{ |
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: trace_metric events are incorrectly serialized as event type in the envelope due to a missing case in ToEnvelopeWithTime and ToEnvelopeItem.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
Events created with type = "trace_metric" are processed by ToEnvelopeWithTime and ToEnvelopeItem methods. Due to a missing case for traceMetricEvent.Type in the switch statement, these events fall through to the default case. This results in protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeEvent, eventBody) being created, incorrectly setting the envelope item type to "event" instead of the expected "trace_metric", which the Sentry backend requires for proper classification and processing.
💡 Suggested Fix
Add a case traceMetricEvent.Type to the switch statements in ToEnvelopeWithTime and ToEnvelopeItem methods to correctly create protocol.NewTraceMetricItem() for trace_metric events.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: interfaces.go#L894-L909
Potential issue: Events created with `type = "trace_metric"` are processed by
`ToEnvelopeWithTime` and `ToEnvelopeItem` methods. Due to a missing `case` for
`traceMetricEvent.Type` in the `switch` statement, these events fall through to the
`default` case. This results in
`protocol.NewEnvelopeItem(protocol.EnvelopeItemTypeEvent, eventBody)` being created,
incorrectly setting the envelope item type to "event" instead of the expected
"trace_metric", which the Sentry backend requires for proper classification and
processing.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 4367403
| } | ||
|
|
||
| wrapper := struct { | ||
| Items [][]byte `json:"items"` |
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: Metrics payload incorrectly base64 encoded
The Items field uses [][]byte instead of []json.RawMessage, causing JSON payloads to be base64-encoded when marshaled rather than embedded as raw JSON. This breaks the metrics envelope format. The log batch implementation correctly uses []json.RawMessage for the same purpose.
Description
Implement metrics based on https://develop.sentry.dev/sdk/telemetry/metrics/ and https://develop.sentry.dev/sdk/data-model/envelope-items/#trace-metric
Issues
CLOSES #1136