telemetry.go
telemetry.go - Overview
This file contains the implementation for collecting and sending telemetry data from the SigNoz query service. It handles initializing the telemetry client, sending events, identifying users, and scheduling periodic data collection tasks.
Detailed Documentation
Constants
TELEMETRY_*
: Constants defining various telemetry event names, such as API calls, user actions, and system metrics.DEFAULT_SAMPLING
: The default sampling rate for telemetry data (0.1).api_key
: The API key used for telemetry.IP_NOT_FOUND_PLACEHOLDER
: Placeholder string used when the outbound IP address cannot be determined.DEFAULT_NUMBER_OF_SERVICES
: Default number of services.SCHEDULE_START_TIME
: Schedule Start Time.RATE_LIMIT_CHECK_DURATION
: The duration to check rate limit in telemetry.RATE_LIMIT_VALUE
: Rate Limit Value.SAAS_EVENTS_LIST
: A map of events to be sent to the SaaS telemetry endpoint.OSS_EVENTS_LIST
: A map of events to be sent to the OSS telemetry endpoint.
QueryInfoResult
- Purpose: Struct to store query information collected for telemetry purposes.
- Fields:
LogsUsed
(bool): Indicates if logs data source was used.MetricsUsed
(bool): Indicates if metrics data source was used.TracesUsed
(bool): Indicates if traces data source was used.FilterApplied
(bool): Indicates if any filter was applied.GroupByApplied
(bool): Indicates if group by was applied.AggregateOperator
(v3.AggregateOperator): Aggregate operator used in the query.AggregateAttributeKey
(string): Aggregate attribute key used in the query.QueryType
(v3.QueryType): Type of the query.PanelType
(v3.PanelType): Type of panel used.NumberOfQueries
(int): Number of queries in the composite query.
(*Telemetry) IsSampled
- Purpose: Determines whether the current telemetry event should be sampled based on the configured sampling rate.
- Returns:
bool
: True if the event should be sampled, false otherwise.
(*Telemetry) CheckQueryInfo
- Purpose: Analyzes a
QueryRangeParamsV3
object to extract relevant information about the query, such as data sources used, filters applied, and aggregation details. - Parameters:
postData
(*v3.QueryRangeParamsV3): The query parameters.
- Returns:
QueryInfoResult
: A struct containing information about the query.
(*Telemetry) AddActiveTracesUser
- Purpose: Increments active traces user.
- Returns: None
(*Telemetry) AddActiveMetricsUser
- Purpose: Increments active metrics user.
- Returns: None
(*Telemetry) AddActiveLogsUser
- Purpose: Increments active logs user.
- Returns: None
Telemetry
- Purpose: The main struct for managing telemetry data collection and sending.
- Fields:
ossOperator
(analytics.Client): The Segment.io analytics client for OSS telemetry.saasOperator
(analytics.Client): The Segment.io analytics client for SaaS telemetry.ipAddress
(string): The outbound IP address of the server.userEmail
(string): The email address of the current user.isEnabled
(bool): Indicates whether telemetry is enabled.isAnonymous
(bool): Indicates whether telemetry is anonymized.distinctId
(string): Distinct user ID.reader
(interfaces.Reader): Interface for reading telemetry data.companyDomain
(string): The domain of the company associated with the user.minRandInt
(int): Minimum random integer for sampling.maxRandInt
(int): Maximum random integer for sampling.rateLimits
(map[string]int8): Rate limits for different event types.activeUser
(map[string]int8): Tracks active user counts for traces, metrics, and logs.patTokenUser
(bool): Indicates that PAT token is used.mutex
(sync.RWMutex): A mutex to protect concurrent access to shared resources.alertsInfoCallback
(func(ctx context.Context) (*model.AlertsInfo, error)): Callback function to fetch alerts info.userCountCallback
(func(ctx context.Context) (int, error)): Callback function to fetch user count.userRoleCallback
(func(ctx context.Context, groupId string) (string, error)): Callback function to fetch user role.getUsersCallback
(func(ctx context.Context) ([]types.GettableUser, *model.ApiError)): Callback function to fetch list of users.dashboardsInfoCallback
(func(ctx context.Context) (*model.DashboardsInfo, error)): Callback function to fetch dashboards info.savedViewsInfoCallback
(func(ctx context.Context) (*model.SavedViewsInfo, error)): Callback function to fetch saved views info.
(*Telemetry) SetAlertsInfoCallback
- Purpose: Sets the callback function for fetching alerts information.
- Parameters:
callback
(func(ctx context.Context) (*model.AlertsInfo, error)): The callback function.
(*Telemetry) SetUserCountCallback
- Purpose: Sets the callback function for fetching the user count.
- Parameters:
callback
(func(ctx context.Context) (int, error)): The callback function.
(*Telemetry) SetUserRoleCallback
- Purpose: Sets the callback function for fetching the user role.
- Parameters:
callback
(func(ctx context.Context, groupId string) (string, error)): The callback function.
(*Telemetry) SetGetUsersCallback
- Purpose: Sets the callback function for fetching the list of users.
- Parameters:
callback
(func(ctx context.Context) ([]types.GettableUser, *model.ApiError)): The callback function.
(*Telemetry) SetSavedViewsInfoCallback
- Purpose: Sets the callback function for fetching saved views information.
- Parameters:
callback
(func(ctx context.Context) (*model.SavedViewsInfo, error)): The callback function.
(*Telemetry) SetDashboardsInfoCallback
- Purpose: Sets the callback function for fetching dashboards information.
- Parameters:
callback
(func(ctx context.Context) (*model.DashboardsInfo, error)): The callback function.
createTelemetry
- Purpose: Initializes the telemetry client and sets up periodic data collection tasks.
- Returns: None
getOutboundIP
- Purpose: Retrieves the preferred outbound IP address of the machine.
- Returns:
string
: The outbound IP address or "NA" if it cannot be determined.
(*Telemetry) IdentifyUser
- Purpose: Sends an identify event to the telemetry service, associating a user with their traits (name, email, role).
- Parameters:
user
(*types.User): The user object.
- Returns: None
(*Telemetry) SendIdentifyEvent
- Purpose: Sends an identify event with custom data to the telemetry service.
- Parameters:
data
(map[string]interface{}): The data to include in the identify event.userEmail
(string): The user email.
- Returns: None
(*Telemetry) SendGroupEvent
- Purpose: Sends an group event with custom data to the telemetry service.
- Parameters:
data
(map[string]interface{}): The data to include in the group event.userEmail
(string): The user email.
- Returns: None
(*Telemetry) SetUserEmail
- Purpose: Sets the email address of the current user.
- Parameters:
email
(string): The user's email address.
- Returns: None
(*Telemetry) SetPatTokenUser
- Purpose: Sets that PAT token is used.
- Parameters: None
- Returns: None
(*Telemetry) GetUserEmail
- Purpose: Gets the email address of the current user.
- Parameters: None
- Returns: The user's email address.
(*Telemetry) SetSaasOperator
- Purpose: Sets the saas operator client.
- Parameters:
saasOperatorKey
(string): The saas operator key.
- Returns: None
(*Telemetry) SetCompanyDomain
- Purpose: Sets the company domain based on the user's email address.
- Parameters:
email
(string): The user's email address.
- Returns: None
(*Telemetry) getCompanyDomain
- Purpose: Retrieves the company domain.
- Returns:
string
: The company domain.
(*Telemetry) checkEvents
- Purpose: Checks if the events are to be sent or not based on certain flags.
- Parameters:
event
(string): The event name.
- Returns:
bool
: The status if an event is enabled or not.
(*Telemetry) SendEvent
- Purpose: Sends a telemetry event with the given name and data.
- Parameters:
event
(string): The name of the event.data
(map[string]interface{}): The data associated with the event.userEmail
(string): The user email.rateLimitFlag
(bool): Whether to rate limit the event.viaEventsAPI
(bool): Whether the event is sent via events API.
- Returns: None
(*Telemetry) GetDistinctId
- Purpose: Retrieves the distinct ID.
- Returns:
string
: The distinct user ID.
(*Telemetry) SetDistinctId
- Purpose: Sets the distinct ID.
- Parameters:
distinctId
(string): The distinct user ID.
- Returns: None
(*Telemetry) isTelemetryAnonymous
- Purpose: Checks whether telemetry is anonymized.
- Returns:
bool
: True if telemetry is anonymized, false otherwise.
(*Telemetry) SetTelemetryAnonymous
- Purpose: Sets whether telemetry is anonymized.
- Parameters:
value
(bool): True to anonymize telemetry, false otherwise.
- Returns: None
(*Telemetry) isTelemetryEnabled
- Purpose: Checks whether telemetry is enabled.
- Returns:
bool
: True if telemetry is enabled, false otherwise.
(*Telemetry) SetTelemetryEnabled
- Purpose: Sets whether telemetry is enabled.
- Parameters:
value
(bool): True to enable telemetry, false otherwise.
- Returns: None
(*Telemetry) SetReader
- Purpose: Sets the telemetry reader interface.
- Parameters:
reader
(interfaces.Reader): The telemetry reader.
- Returns: None
GetInstance
- Purpose: Returns the singleton instance of the
Telemetry
struct. - Returns:
*Telemetry
: The telemetry instance.
getDeploymentType
- Purpose: Retrieves the deployment type from the environment variable
DEPLOYMENT_TYPE
. - Returns:
string
: The deployment type or "unknown" if the environment variable is not set.
Code Examples
None
Include in Getting Started: NO