Skip to content

Conversation

@aldy505
Copy link
Contributor

@aldy505 aldy505 commented Nov 30, 2025

@aldy505 aldy505 changed the title Feat/sentry metrics feat: Sentry Metrics Nov 30, 2025
Comment on lines +899 to +909
Name: m.Name,
Value: m.Value,
Unit: m.Unit,
Attributes: attrs,
})
if err != nil {
return nil, err
}

return &protocol.EnvelopeItem{
Header: &protocol.EnvelopeItemHeader{
Copy link

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"`
Copy link

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.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sentry Metrics for Go

1 participant