mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-20 12:39:13 +08:00
chore: analytics
This commit is contained in:
parent
90d1a87027
commit
1374444f36
@ -2999,6 +2999,40 @@ func (r *ClickHouseReader) GetLogsInfoInLastHeartBeatInterval(ctx context.Contex
|
|||||||
return totalLogLines, nil
|
return totalLogLines, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *ClickHouseReader) GetTagsInfoInLastHeartBeatInterval(ctx context.Context) (*model.TagsInfo, error) {
|
||||||
|
|
||||||
|
queryStr := fmt.Sprintf("select tagMap['service.name'] as serviceName, tagMap['deployment.environment'] as env, tagMap['telemetry.sdk.language'] as language from %s.%s where timestamp > toUnixTimestamp(now()-toIntervalMinute(%d));", r.traceDB, r.indexTable, 1)
|
||||||
|
|
||||||
|
tagTelemetryDataList := []model.TagTelemetryData{}
|
||||||
|
err := r.db.Select(ctx, &tagTelemetryDataList, queryStr)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
zap.S().Info(queryStr)
|
||||||
|
zap.S().Debug("Error in processing sql query: ", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tagsInfo := model.TagsInfo{
|
||||||
|
Languages: make(map[string]interface{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tagTelemetryData := range tagTelemetryDataList {
|
||||||
|
|
||||||
|
if len(tagTelemetryData.ServiceName) != 0 && strings.Contains(tagTelemetryData.ServiceName, "prod") {
|
||||||
|
tagsInfo.Env = tagTelemetryData.ServiceName
|
||||||
|
}
|
||||||
|
if len(tagTelemetryData.Env) != 0 && strings.Contains(tagTelemetryData.Env, "prod") {
|
||||||
|
tagsInfo.Env = tagTelemetryData.Env
|
||||||
|
}
|
||||||
|
if len(tagTelemetryData.Language) != 0 {
|
||||||
|
tagsInfo.Languages[tagTelemetryData.Language] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return &tagsInfo, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *ClickHouseReader) GetLogFields(ctx context.Context) (*model.GetFieldsResponse, *model.ApiError) {
|
func (r *ClickHouseReader) GetLogFields(ctx context.Context) (*model.GetFieldsResponse, *model.ApiError) {
|
||||||
// response will contain top level fields from the otel log model
|
// response will contain top level fields from the otel log model
|
||||||
response := model.GetFieldsResponse{
|
response := model.GetFieldsResponse{
|
||||||
|
@ -22,4 +22,4 @@ rule_files:
|
|||||||
scrape_configs: []
|
scrape_configs: []
|
||||||
|
|
||||||
remote_read:
|
remote_read:
|
||||||
- url: tcp://localhost:9000/?database=signoz_metrics
|
- url: tcp://stagingapp.signoz.io:9000/?database=signoz_metrics
|
||||||
|
@ -61,7 +61,7 @@ type Reader interface {
|
|||||||
GetTimeSeriesInfo(ctx context.Context) (map[string]interface{}, error)
|
GetTimeSeriesInfo(ctx context.Context) (map[string]interface{}, error)
|
||||||
GetSamplesInfoInLastHeartBeatInterval(ctx context.Context) (uint64, error)
|
GetSamplesInfoInLastHeartBeatInterval(ctx context.Context) (uint64, error)
|
||||||
GetLogsInfoInLastHeartBeatInterval(ctx context.Context) (uint64, error)
|
GetLogsInfoInLastHeartBeatInterval(ctx context.Context) (uint64, error)
|
||||||
|
GetTagsInfoInLastHeartBeatInterval(ctx context.Context) (*model.TagsInfo, error)
|
||||||
// Logs
|
// Logs
|
||||||
GetLogFields(ctx context.Context) (*model.GetFieldsResponse, *model.ApiError)
|
GetLogFields(ctx context.Context) (*model.GetFieldsResponse, *model.ApiError)
|
||||||
UpdateLogField(ctx context.Context, field *model.UpdateField) *model.ApiError
|
UpdateLogField(ctx context.Context, field *model.UpdateField) *model.ApiError
|
||||||
|
@ -542,3 +542,14 @@ func (s *ServiceItem) MarshalJSON() ([]byte, error) {
|
|||||||
type DashboardVar struct {
|
type DashboardVar struct {
|
||||||
VariableValues []interface{} `json:"variableValues"`
|
VariableValues []interface{} `json:"variableValues"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TagsInfo struct {
|
||||||
|
Languages map[string]interface{} `json:"languages"`
|
||||||
|
Env string `json:"env"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TagTelemetryData struct {
|
||||||
|
ServiceName string `json:"serviceName" ch:"serviceName"`
|
||||||
|
Env string `json:"env" ch:"env"`
|
||||||
|
Language string `json:"language" ch:"language"`
|
||||||
|
}
|
||||||
|
@ -30,6 +30,8 @@ const (
|
|||||||
TELEMETRY_LICENSE_CHECK_FAILED = "License Check Failed"
|
TELEMETRY_LICENSE_CHECK_FAILED = "License Check Failed"
|
||||||
TELEMETRY_LICENSE_UPDATED = "License Updated"
|
TELEMETRY_LICENSE_UPDATED = "License Updated"
|
||||||
TELEMETRY_LICENSE_ACT_FAILED = "License Activation Failed"
|
TELEMETRY_LICENSE_ACT_FAILED = "License Activation Failed"
|
||||||
|
TELEMETRY_EVENT_ENVIRONMENT = "Environment"
|
||||||
|
TELEMETRY_EVENT_LANGUAGE = "Language"
|
||||||
)
|
)
|
||||||
|
|
||||||
const api_key = "4Gmoa4ixJAUHx2BpJxsjwA1bEfnwEeRz"
|
const api_key = "4Gmoa4ixJAUHx2BpJxsjwA1bEfnwEeRz"
|
||||||
@ -70,6 +72,7 @@ type Telemetry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createTelemetry() {
|
func createTelemetry() {
|
||||||
|
|
||||||
telemetry = &Telemetry{
|
telemetry = &Telemetry{
|
||||||
operator: analytics.New(api_key),
|
operator: analytics.New(api_key),
|
||||||
phOperator: ph.New(ph_api_key),
|
phOperator: ph.New(ph_api_key),
|
||||||
@ -89,6 +92,16 @@ func createTelemetry() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
tagsInfo, _ := telemetry.reader.GetTagsInfoInLastHeartBeatInterval(context.Background())
|
||||||
|
|
||||||
|
if len(tagsInfo.Env) != 0 {
|
||||||
|
telemetry.SendEvent(TELEMETRY_EVENT_ENVIRONMENT, map[string]interface{}{"value": tagsInfo.Env})
|
||||||
|
}
|
||||||
|
|
||||||
|
for language, _ := range tagsInfo.Languages {
|
||||||
|
telemetry.SendEvent(TELEMETRY_EVENT_LANGUAGE, map[string]interface{}{"language": language})
|
||||||
|
}
|
||||||
|
|
||||||
totalSpans, _ := telemetry.reader.GetTotalSpans(context.Background())
|
totalSpans, _ := telemetry.reader.GetTotalSpans(context.Background())
|
||||||
spansInLastHeartBeatInterval, _ := telemetry.reader.GetSpansInLastHeartBeatInterval(context.Background())
|
spansInLastHeartBeatInterval, _ := telemetry.reader.GetSpansInLastHeartBeatInterval(context.Background())
|
||||||
getSamplesInfoInLastHeartBeatInterval, _ := telemetry.reader.GetSamplesInfoInLastHeartBeatInterval(context.Background())
|
getSamplesInfoInLastHeartBeatInterval, _ := telemetry.reader.GetSamplesInfoInLastHeartBeatInterval(context.Background())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user