Skip to content

Commit

Permalink
chore: segment oss (#5910)
Browse files Browse the repository at this point in the history
Co-authored-by: Prashant Shahi <prashant@signoz.io>
  • Loading branch information
makeavish and prashant-shahi committed Sep 10, 2024
1 parent 3c151e3 commit 573d369
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
5 changes: 5 additions & 0 deletions pkg/query-service/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ var ConfigSignozIo = "https://config.signoz.io/api/v1"

var DEFAULT_TELEMETRY_ANONYMOUS = false

func IsOSSTelemetryEnabled() bool {
ossSegmentKey := GetOrDefaultEnv("OSS_TELEMETRY_ENABLED", "true")
return ossSegmentKey == "true"
}

const MaxAllowedPointsInTimeSeries = 300

func IsTelemetryEnabled() bool {
Expand Down
40 changes: 25 additions & 15 deletions pkg/query-service/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,19 @@ func createTelemetry() {
return
}

telemetry = &Telemetry{
ossOperator: analytics.New(api_key),
ipAddress: getOutboundIP(),
rateLimits: make(map[string]int8),
activeUser: make(map[string]int8),
if constants.IsOSSTelemetryEnabled() {
telemetry = &Telemetry{
ossOperator: analytics.New(api_key),
ipAddress: getOutboundIP(),
rateLimits: make(map[string]int8),
activeUser: make(map[string]int8),
}
} else {
telemetry = &Telemetry{
ipAddress: getOutboundIP(),
rateLimits: make(map[string]int8),
activeUser: make(map[string]int8),
}
}
telemetry.minRandInt = 0
telemetry.maxRandInt = int(1 / DEFAULT_SAMPLING)
Expand Down Expand Up @@ -484,16 +492,18 @@ func (a *Telemetry) IdentifyUser(user *model.User) {
})
}

a.ossOperator.Enqueue(analytics.Identify{
UserId: a.ipAddress,
Traits: analytics.NewTraits().SetName(user.Name).SetEmail(user.Email).Set("ip", a.ipAddress),
})
// Updating a groups properties
a.ossOperator.Enqueue(analytics.Group{
UserId: a.ipAddress,
GroupId: a.getCompanyDomain(),
Traits: analytics.NewTraits().Set("company_domain", a.getCompanyDomain()),
})
if a.ossOperator != nil {
a.ossOperator.Enqueue(analytics.Identify{
UserId: a.ipAddress,
Traits: analytics.NewTraits().SetName(user.Name).SetEmail(user.Email).Set("ip", a.ipAddress),
})
// Updating a groups properties
a.ossOperator.Enqueue(analytics.Group{
UserId: a.ipAddress,
GroupId: a.getCompanyDomain(),
Traits: analytics.NewTraits().Set("company_domain", a.getCompanyDomain()),
})
}
}

func (a *Telemetry) SetUserEmail(email string) {
Expand Down

0 comments on commit 573d369

Please sign in to comment.