Feat: Extending report interaction with static context that can be appended to all interaction events (#88927)
* Extending report interaction with static context that can be appended to all requests
This commit is contained in:
@@ -312,6 +312,9 @@ application_insights_endpoint_url =
|
|||||||
# Controls if the UI contains any links to user feedback forms
|
# Controls if the UI contains any links to user feedback forms
|
||||||
feedback_links_enabled = true
|
feedback_links_enabled = true
|
||||||
|
|
||||||
|
# Static context that is being added to analytics events
|
||||||
|
reporting_static_context =
|
||||||
|
|
||||||
#################################### Security ############################
|
#################################### Security ############################
|
||||||
[security]
|
[security]
|
||||||
# disable creation of admin user on first start of grafana
|
# disable creation of admin user on first start of grafana
|
||||||
|
|||||||
@@ -309,6 +309,9 @@
|
|||||||
# Controls if the UI contains any links to user feedback forms
|
# Controls if the UI contains any links to user feedback forms
|
||||||
;feedback_links_enabled = true
|
;feedback_links_enabled = true
|
||||||
|
|
||||||
|
# Static context that is being added to analytics events
|
||||||
|
;reporting_static_context = grafanaInstance=12, os=linux
|
||||||
|
|
||||||
#################################### Security ####################################
|
#################################### Security ####################################
|
||||||
[security]
|
[security]
|
||||||
# disable creation of admin user on first start of grafana
|
# disable creation of admin user on first start of grafana
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ export interface GrafanaConfig {
|
|||||||
cloudMigrationIsTarget?: boolean;
|
cloudMigrationIsTarget?: boolean;
|
||||||
listDashboardScopesEndpoint?: string;
|
listDashboardScopesEndpoint?: string;
|
||||||
listScopesEndpoint?: string;
|
listScopesEndpoint?: string;
|
||||||
|
reportingStaticContext?: Record<string, string>;
|
||||||
|
|
||||||
// The namespace to use for kubernetes apiserver requests
|
// The namespace to use for kubernetes apiserver requests
|
||||||
namespace: string;
|
namespace: string;
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ export const reportPageview = () => {
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export const reportInteraction = (interactionName: string, properties?: Record<string, unknown>) => {
|
export const reportInteraction = (interactionName: string, properties?: Record<string, unknown>) => {
|
||||||
|
// get static reporting context and append it to properties
|
||||||
|
if (config.reportingStaticContext && config.reportingStaticContext instanceof Object) {
|
||||||
|
properties = { ...properties, ...config.reportingStaticContext };
|
||||||
|
}
|
||||||
getEchoSrv().addEvent<InteractionEchoEvent>({
|
getEchoSrv().addEvent<InteractionEchoEvent>({
|
||||||
type: EchoEventType.Interaction,
|
type: EchoEventType.Interaction,
|
||||||
payload: {
|
payload: {
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
|
|||||||
rootFolderUID: string | undefined;
|
rootFolderUID: string | undefined;
|
||||||
localFileSystemAvailable: boolean | undefined;
|
localFileSystemAvailable: boolean | undefined;
|
||||||
cloudMigrationIsTarget: boolean | undefined;
|
cloudMigrationIsTarget: boolean | undefined;
|
||||||
|
reportingStaticContext?: Record<string, string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Language used in Grafana's UI. This is after the user's preference (or deteceted locale) is resolved to one of
|
* Language used in Grafana's UI. This is after the user's preference (or deteceted locale) is resolved to one of
|
||||||
|
|||||||
@@ -231,6 +231,7 @@ type FrontendSettingsDTO struct {
|
|||||||
SupportBundlesEnabled bool `json:"supportBundlesEnabled"`
|
SupportBundlesEnabled bool `json:"supportBundlesEnabled"`
|
||||||
SnapshotEnabled bool `json:"snapshotEnabled"`
|
SnapshotEnabled bool `json:"snapshotEnabled"`
|
||||||
SecureSocksDSProxyEnabled bool `json:"secureSocksDSProxyEnabled"`
|
SecureSocksDSProxyEnabled bool `json:"secureSocksDSProxyEnabled"`
|
||||||
|
ReportingStaticContext map[string]string `json:"reportingStaticContext"`
|
||||||
|
|
||||||
Azure FrontendSettingsAzureDTO `json:"azure"`
|
Azure FrontendSettingsAzureDTO `json:"azure"`
|
||||||
|
|
||||||
|
|||||||
@@ -226,6 +226,7 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
|||||||
SharedWithMeFolderUID: folder.SharedWithMeFolderUID,
|
SharedWithMeFolderUID: folder.SharedWithMeFolderUID,
|
||||||
RootFolderUID: accesscontrol.GeneralFolderUID,
|
RootFolderUID: accesscontrol.GeneralFolderUID,
|
||||||
LocalFileSystemAvailable: hs.Cfg.LocalFileSystemAvailable,
|
LocalFileSystemAvailable: hs.Cfg.LocalFileSystemAvailable,
|
||||||
|
ReportingStaticContext: hs.Cfg.ReportingStaticContext,
|
||||||
|
|
||||||
BuildInfo: dtos.FrontendSettingsBuildInfoDTO{
|
BuildInfo: dtos.FrontendSettingsBuildInfoDTO{
|
||||||
HideVersion: hideVersion,
|
HideVersion: hideVersion,
|
||||||
|
|||||||
@@ -366,6 +366,7 @@ type Cfg struct {
|
|||||||
ApplicationInsightsConnectionString string
|
ApplicationInsightsConnectionString string
|
||||||
ApplicationInsightsEndpointUrl string
|
ApplicationInsightsEndpointUrl string
|
||||||
FeedbackLinksEnabled bool
|
FeedbackLinksEnabled bool
|
||||||
|
ReportingStaticContext map[string]string
|
||||||
|
|
||||||
// Frontend analytics
|
// Frontend analytics
|
||||||
GoogleAnalyticsID string
|
GoogleAnalyticsID string
|
||||||
@@ -1156,6 +1157,15 @@ func (cfg *Cfg) parseINIFile(iniFile *ini.File) error {
|
|||||||
cfg.ApplicationInsightsEndpointUrl = analytics.Key("application_insights_endpoint_url").String()
|
cfg.ApplicationInsightsEndpointUrl = analytics.Key("application_insights_endpoint_url").String()
|
||||||
cfg.FeedbackLinksEnabled = analytics.Key("feedback_links_enabled").MustBool(true)
|
cfg.FeedbackLinksEnabled = analytics.Key("feedback_links_enabled").MustBool(true)
|
||||||
|
|
||||||
|
// parse reporting static context string of key=value, key=value pairs into an object
|
||||||
|
cfg.ReportingStaticContext = make(map[string]string)
|
||||||
|
for _, pair := range strings.Split(analytics.Key("reporting_static_context").String(), ",") {
|
||||||
|
kv := strings.Split(pair, "=")
|
||||||
|
if len(kv) == 2 {
|
||||||
|
cfg.ReportingStaticContext[strings.TrimSpace("_static_context_"+kv[0])] = strings.TrimSpace(kv[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := cfg.readAlertingSettings(iniFile); err != nil {
|
if err := cfg.readAlertingSettings(iniFile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user