Skip to content

Commit

Permalink
ref(functions): Clean up Kafka message
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops committed Jan 24, 2024
1 parent 2b1498f commit a01970d
Showing 1 changed file with 20 additions and 42 deletions.
62 changes: 20 additions & 42 deletions cmd/vroom/kafka.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"strconv"

"github.com/getsentry/vroom/internal/nodetree"
"github.com/getsentry/vroom/internal/platform"
"github.com/getsentry/vroom/internal/profile"
Expand All @@ -11,22 +9,16 @@ import (
type (
// FunctionsKafkaMessage is representing the struct we send to Kafka to insert functions in ClickHouse.
FunctionsKafkaMessage struct {
Functions []nodetree.CallTreeFunction `json:"functions"`
Environment string `json:"environment,omitempty"`
ID string `json:"profile_id"`
Platform platform.Platform `json:"platform"`
ProjectID uint64 `json:"project_id"`
Received int64 `json:"received"`
Release string `json:"release,omitempty"`
Dist string `json:"dist,omitempty"`
RetentionDays int `json:"retention_days"`
Timestamp int64 `json:"timestamp"`
TransactionName string `json:"transaction_name"`
TransactionOp string `json:"transaction_op"`
TransactionStatus string `json:"transaction_status"`
HTTPMethod string `json:"http_method,omitempty"`
BrowserName string `json:"browser_name,omitempty"`
DeviceClass uint64 `json:"device_class,omitempty"`
Environment string `json:"environment,omitempty"`
Functions []nodetree.CallTreeFunction `json:"functions"`
ID string `json:"profile_id"`
Platform platform.Platform `json:"platform"`
ProjectID uint64 `json:"project_id"`
Received int64 `json:"received"`
Release string `json:"release,omitempty"`
RetentionDays int `json:"retention_days"`
Timestamp int64 `json:"timestamp"`
TransactionName string `json:"transaction_name"`
}

// ProfileKafkaMessage is representing the struct we send to Kafka to insert a profile in ClickHouse.
Expand Down Expand Up @@ -57,31 +49,17 @@ type (
)

func buildFunctionsKafkaMessage(p profile.Profile, functions []nodetree.CallTreeFunction) FunctionsKafkaMessage {
tm := p.TransactionMetadata()
tt := p.TransactionTags()

deviceClass, err := strconv.ParseUint(tt["device.class"], 10, 8)
if err != nil {
deviceClass = 0
}

return FunctionsKafkaMessage{
Functions: functions,
Environment: p.Environment(),
ID: p.ID(),
Platform: p.Platform(),
ProjectID: p.ProjectID(),
Received: p.Received().Unix(),
Release: p.Release(),
Dist: tm.Dist,
RetentionDays: p.RetentionDays(),
Timestamp: p.Timestamp().Unix(),
TransactionName: p.Transaction().Name,
TransactionOp: tm.TransactionOp,
TransactionStatus: tm.TransactionStatus,
HTTPMethod: tm.HTTPMethod,
BrowserName: tt["browser.name"],
DeviceClass: deviceClass,
Environment: p.Environment(),
Functions: functions,
ID: p.ID(),
Platform: p.Platform(),
ProjectID: p.ProjectID(),
Received: p.Received().Unix(),
Release: p.Release(),
RetentionDays: p.RetentionDays(),
Timestamp: p.Timestamp().Unix(),
TransactionName: p.Transaction().Name,
}
}

Expand Down

0 comments on commit a01970d

Please sign in to comment.