Skip to content

Commit

Permalink
feat: Forward SDK info to Kafka (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops authored Aug 27, 2024
1 parent a2f1ff5 commit 6f2a457
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 12 deletions.
11 changes: 7 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ linters:
disable-all: true
enable:
- bodyclose
- copyloopvar
#- depguard
- dogsled
#- dupl
- errcheck
- exportloopref
- forbidigo
- gochecknoinits
#- goconst
Expand All @@ -16,16 +16,19 @@ linters:
- gofmt
- goimports
#- gosec
- gosimple
- govet
#- gosimple
#- govet
- ineffassign
- misspell
- nakedret
- prealloc
- revive
- staticcheck
#- staticcheck
- typecheck
- unconvert
- unparam
- unused
- whitespace
output:
print-linter-name: true
show-stats: true
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Add optional generation of metrics during flamegraph aggregation ([#494](https://github.com/getsentry/vroom/pull/494))
- Ingest function metrics from profile chunks ([#495](https://github.com/getsentry/vroom/pull/495))
- Annotate flamegraph with profile data ([#501](https://github.com/getsentry/vroom/pull/501)), ([#502](https://github.com/getsentry/vroom/pull/502)), ([#503](https://github.com/getsentry/vroom/pull/503))
- Forward SDK info to Kafka. ([#507](https://github.com/getsentry/vroom/pull/507))

**Bug Fixes**:

Expand Down
13 changes: 10 additions & 3 deletions cmd/vroom/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,28 @@ type (

StartTimestamp float64 `json:"start_timestamp"`
EndTimestamp float64 `json:"end_timestamp"`
DurationMS uint64 `json:"duration_ms"`

Received float64 `json:"received"`
RetentionDays int `json:"retention_days"`

SDKName string `json:"sdk_name"`
SDKVersion string `json:"sdk_version"`
}
)

func buildChunkKafkaMessage(c *chunk.Chunk) *ChunkKafkaMessage {
start, end := c.StartEndTimestamps()
return &ChunkKafkaMessage{
ChunkID: c.ID,
ProjectID: c.ProjectID,
ProfilerID: c.ProfilerID,
StartTimestamp: start,
DurationMS: c.DurationMS(),
EndTimestamp: end,
ProfilerID: c.ProfilerID,
ProjectID: c.ProjectID,
Received: c.Received,
RetentionDays: c.RetentionDays,
SDKName: c.ClientSDK.Name,
SDKVersion: c.ClientSDK.Version,
StartTimestamp: start,
}
}
4 changes: 4 additions & 0 deletions cmd/vroom/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type (
ProjectID uint64 `json:"project_id"`
Received int64 `json:"received"`
RetentionDays int `json:"retention_days"`
SDKName string `json:"sdk_name,omitempty"`
SDKVersion string `json:"sdk_version,omitempty"`
TraceID string `json:"trace_id"`
TransactionID string `json:"transaction_id"`
TransactionName string `json:"transaction_name"`
Expand Down Expand Up @@ -115,6 +117,8 @@ func buildProfileKafkaMessage(p profile.Profile) ProfileKafkaMessage {
ProjectID: p.ProjectID(),
Received: p.Received().Unix(),
RetentionDays: p.RetentionDays(),
SDKName: m.SDKName,
SDKVersion: m.SDKVersion,
TraceID: t.TraceID,
TransactionID: t.ID,
TransactionName: t.Name,
Expand Down
14 changes: 11 additions & 3 deletions internal/chunk/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"errors"
"fmt"
"hash/fnv"
"math"
"sort"

"github.com/getsentry/vroom/internal/clientsdk"
"github.com/getsentry/vroom/internal/debugmeta"
"github.com/getsentry/vroom/internal/frame"
"github.com/getsentry/vroom/internal/nodetree"
Expand All @@ -28,9 +30,10 @@ type (

DebugMeta debugmeta.DebugMeta `json:"debug_meta"`

Environment string `json:"environment"`
Platform platform.Platform `json:"platform"`
Release string `json:"release"`
ClientSDK clientsdk.ClientSDK `json:"client_sdk"`
Environment string `json:"environment"`
Platform platform.Platform `json:"platform"`
Release string `json:"release"`

Version string `json:"version"`

Expand Down Expand Up @@ -89,6 +92,11 @@ func (c *Chunk) Normalize() {
}
}

func (c Chunk) DurationMS() uint64 {
start, end := c.StartEndTimestamps()
return uint64(math.Round((end - start) * 1e3))
}

func StoragePath(OrganizationID uint64, ProjectID uint64, ProfilerID string, ID string) string {
return fmt.Sprintf(
"%d/%d/%s/%s",
Expand Down
6 changes: 6 additions & 0 deletions internal/clientsdk/clientsdk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package clientsdk

type ClientSDK struct {
Name string `json:"name"`
Version string `json:"version"`
}
2 changes: 2 additions & 0 deletions internal/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type Metadata struct {
DeviceOSVersion string `json:"device_os_version"`
ID string `json:"id"`
ProjectID string `json:"project_id"`
SDKName string `json:"sdk_name"`
SDKVersion string `json:"sdk_version"`
Timestamp int64 `json:"timestamp"`
TraceDurationMs float64 `json:"trace_duration_ms"`
TransactionID string `json:"transaction_id"`
Expand Down
8 changes: 6 additions & 2 deletions internal/sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/getsentry/vroom/internal/clientsdk"
"github.com/getsentry/vroom/internal/debugmeta"
"github.com/getsentry/vroom/internal/frame"
"github.com/getsentry/vroom/internal/measurements"
Expand Down Expand Up @@ -79,21 +80,22 @@ type (
}

RawProfile struct {
Sampled bool `json:"sampled"`
ClientSDK clientsdk.ClientSDK `json:"client_sdk"`
DebugMeta debugmeta.DebugMeta `json:"debug_meta"`
Device Device `json:"device"`
Environment string `json:"environment,omitempty"`
EventID string `json:"event_id"`
Measurements map[string]measurements.Measurement `json:"measurements,omitempty"`
OS OS `json:"os"`
OrganizationID uint64 `json:"organization_id"`
Options utils.Options `json:"options,omitempty"`
OrganizationID uint64 `json:"organization_id"`
Platform platform.Platform `json:"platform"`
ProjectID uint64 `json:"project_id"`
Received timeutil.Time `json:"received"`
Release string `json:"release"`
RetentionDays int `json:"retention_days"`
Runtime Runtime `json:"runtime"`
Sampled bool `json:"sampled"`
Timestamp time.Time `json:"timestamp"`
Trace Trace `json:"profile"`
Transaction transaction.Transaction `json:"transaction"`
Expand Down Expand Up @@ -412,6 +414,8 @@ func (p *Profile) Metadata() metadata.Metadata {
DeviceOSBuildNumber: p.OS.BuildNumber,
DeviceOSName: p.OS.Name,
DeviceOSVersion: p.OS.Version,
SDKName: p.ClientSDK.Name,
SDKVersion: p.ClientSDK.Version,
ID: p.EventID,
ProjectID: strconv.FormatUint(p.ProjectID, 10),
Timestamp: p.Timestamp.Unix(),
Expand Down

0 comments on commit 6f2a457

Please sign in to comment.