mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-04 01:21:22 +08:00

* feat(FE): dynamic step size of metrics page * chore(tests): migrate to dayjs for generating timestamp * bug: sorting of date is fixed * feat: soring filter is added * chore: typo is fixed * feat(backend): support custom events in span * fix: encode event string to fix parsing at frontend * chore: styles is updated for the not found button * chore: update otel-collector to 0.43.0 * fix: remove encoding * fix: set userId as distinctId if failed to fetch IP * Fe: Feat/trace detail (#764) * feat: new trace detail page flame graph * feat: new trace detail page layout * test: trace detail is wip * chore: trace details in wip * feat: trace detail page timeline component * chore: spantoTree is updated * chore: gantchart is updated * chore: onClick is added * chore: isSpanPresentInSearchString util is added * chore: trace graph is updated * chore: added the hack to work * feat: is span present util is added * chore: in span ms is added * chore: tooltip is updated * WIP: chore: trace details changes are updated * feat: getTraceItem is added * feat: trace detail page is updated * feat: trace detail styling changes * feat: trace detail page is updated * feat: implement span hover, select, focus and reset * feat: reset focus * feat: spanId as query table and unfurling * feat: trace details is updated * chore: remove lodash * chore: remove lodash * feat: trace details is updated * feat: new trace detail page styling changes * feat: new trace detail page styling changes * feat: improved styling * feat: remove horizontal scrolling * feat: new trace detail page modify caret icon * chore styles are updated * Revert "chore: Trace styles" * chore styles are updated * feat: timeline normalisation * chore: remove mock data * chore: sort tree data util is added and selected span component is updated * chore: trace changes are updated * chore: trace changes are updated * chore: trace changes are updated * feat: refactored time units for new trace detail page * chore: remove mockdata * feat: new trace detail page themeing and interval loop fix * chore: error tag is updated * chore: error tag is updated * chore: error tag is updated * chore: error tag is updated * chore: console is removed * fix: error tag expand button * chore: expanded panel is updated * feat: scroll span from gantt chart intoview * chore: trace detail is removed Co-authored-by: Pranshu Chittora <pranshu@signoz.io> * bug: Trace search bug is resolved (#741) * bug: Trace search bug is resolved * bug: Trace search bug is resolved * chore: parseTagsToQuery is updated * chore: parseTagsToQuery is updated * chore: parseTagsToQuery is updated * chore: parseTagsToQuery is updated * chore: ♿️ add hotrod template and install/delete scripts (#801) * chore: ♿️ add hotrod template and scripts Signed-off-by: Prashant Shahi <prashant@signoz.io> * refactor: ✨ conditionally compute image Signed-off-by: Prashant Shahi <prashant@signoz.io> * fix: 🩹 add signoz namespace Signed-off-by: Prashant Shahi <prashant@signoz.io> * chore: 🔨 fix namespace template in scripts Signed-off-by: Prashant Shahi <prashant@signoz.io> * docs(hotrod): 📝 Add README for hotrod k8s Signed-off-by: Prashant Shahi <prashant@signoz.io> Co-authored-by: Ankit Nayan <ankit@signoz.io> * chore(release): 📌 pin SigNoz and OtelCollector versions Signed-off-by: Prashant Shahi <prashant@signoz.io> Co-authored-by: Pranshu Chittora <pranshu@signoz.io> Co-authored-by: Palash gupta <palash@signoz.io> Co-authored-by: makeavish <makeavish786@gmail.com> Co-authored-by: Ankit Nayan <ankit@signoz.io>
162 lines
3.2 KiB
Go
162 lines
3.2 KiB
Go
package telemetry
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
"sync"
|
|
"time"
|
|
|
|
"go.signoz.io/query-service/constants"
|
|
"go.signoz.io/query-service/model"
|
|
"go.signoz.io/query-service/version"
|
|
"gopkg.in/segmentio/analytics-go.v3"
|
|
)
|
|
|
|
const (
|
|
TELEMETRY_EVENT_PATH = "API Call"
|
|
TELEMETRY_EVENT_USER = "User"
|
|
TELEMETRY_EVENT_INPRODUCT_FEEDBACK = "InProduct Feeback Submitted"
|
|
TELEMETRY_EVENT_NUMBER_OF_SERVICES = "Number of Services"
|
|
TELEMETRY_EVENT_HEART_BEAT = "Heart Beat"
|
|
TELEMETRY_EVENT_USER_PREFERENCES = "User Preferences"
|
|
)
|
|
|
|
const api_key = "4Gmoa4ixJAUHx2BpJxsjwA1bEfnwEeRz"
|
|
const IP_NOT_FOUND_PLACEHOLDER = "NA"
|
|
|
|
var telemetry *Telemetry
|
|
var once sync.Once
|
|
|
|
type Telemetry struct {
|
|
operator analytics.Client
|
|
ipAddress string
|
|
isEnabled bool
|
|
isAnonymous bool
|
|
distinctId string
|
|
}
|
|
|
|
func createTelemetry() {
|
|
telemetry = &Telemetry{
|
|
operator: analytics.New(api_key),
|
|
ipAddress: getOutboundIP(),
|
|
}
|
|
|
|
data := map[string]interface{}{}
|
|
|
|
telemetry.SetTelemetryEnabled(constants.IsTelemetryEnabled())
|
|
telemetry.SendEvent(TELEMETRY_EVENT_HEART_BEAT, data)
|
|
ticker := time.NewTicker(6 * time.Hour)
|
|
go func() {
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
telemetry.SendEvent(TELEMETRY_EVENT_HEART_BEAT, data)
|
|
}
|
|
}
|
|
}()
|
|
|
|
}
|
|
|
|
// Get preferred outbound ip of this machine
|
|
func getOutboundIP() string {
|
|
|
|
ip := []byte(IP_NOT_FOUND_PLACEHOLDER)
|
|
resp, err := http.Get("https://api.ipify.org?format=text")
|
|
|
|
if err != nil {
|
|
return string(ip)
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
if err == nil {
|
|
ipBody, err := ioutil.ReadAll(resp.Body)
|
|
if err == nil {
|
|
ip = ipBody
|
|
}
|
|
}
|
|
|
|
return string(ip)
|
|
}
|
|
|
|
func (a *Telemetry) IdentifyUser(user *model.User) {
|
|
if !a.isTelemetryEnabled() || a.isTelemetryAnonymous() {
|
|
return
|
|
}
|
|
|
|
a.operator.Enqueue(analytics.Identify{
|
|
UserId: a.ipAddress,
|
|
Traits: analytics.NewTraits().SetName(user.Name).SetEmail(user.Email).Set("ip", a.ipAddress),
|
|
})
|
|
|
|
}
|
|
func (a *Telemetry) checkEvents(event string) bool {
|
|
sendEvent := true
|
|
if event == TELEMETRY_EVENT_USER && a.isTelemetryAnonymous() {
|
|
sendEvent = false
|
|
}
|
|
return sendEvent
|
|
}
|
|
|
|
func (a *Telemetry) SendEvent(event string, data map[string]interface{}) {
|
|
|
|
if !a.isTelemetryEnabled() {
|
|
return
|
|
}
|
|
|
|
ok := a.checkEvents(event)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
// zap.S().Info(data)
|
|
properties := analytics.NewProperties()
|
|
properties.Set("version", version.GetVersion())
|
|
|
|
for k, v := range data {
|
|
properties.Set(k, v)
|
|
}
|
|
|
|
userId := a.ipAddress
|
|
if a.isTelemetryAnonymous() || userId == IP_NOT_FOUND_PLACEHOLDER {
|
|
userId = a.GetDistinctId()
|
|
}
|
|
|
|
a.operator.Enqueue(analytics.Track{
|
|
Event: event,
|
|
UserId: userId,
|
|
Properties: properties,
|
|
})
|
|
}
|
|
|
|
func (a *Telemetry) GetDistinctId() string {
|
|
return a.distinctId
|
|
}
|
|
func (a *Telemetry) SetDistinctId(distinctId string) {
|
|
a.distinctId = distinctId
|
|
}
|
|
|
|
func (a *Telemetry) isTelemetryAnonymous() bool {
|
|
return a.isAnonymous
|
|
}
|
|
|
|
func (a *Telemetry) SetTelemetryAnonymous(value bool) {
|
|
a.isAnonymous = value
|
|
}
|
|
|
|
func (a *Telemetry) isTelemetryEnabled() bool {
|
|
return a.isEnabled
|
|
}
|
|
|
|
func (a *Telemetry) SetTelemetryEnabled(value bool) {
|
|
a.isEnabled = value
|
|
}
|
|
|
|
func GetInstance() *Telemetry {
|
|
|
|
once.Do(func() {
|
|
createTelemetry()
|
|
})
|
|
|
|
return telemetry
|
|
}
|