Skip to content

Commit

Permalink
fix: block fe analytics if TRACETEST_DEV is present (#2503)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeepc authored and schoren committed Jun 5, 2023
1 parent 1aa3190 commit 1268a6e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions server/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"log"
"net/http"
"os"

"github.com/gorilla/handlers"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -250,7 +251,8 @@ func (app *App) Start(opts ...appOption) error {

registerDataStoreResource(dataStoreRepo, apiRouter, db, provisioner, tracer)

registerSPAHandler(router, app.cfg, configFromDB.IsAnalyticsEnabled(), serverID)
isTracetestDev := os.Getenv("TRACETEST_DEV") != ""
registerSPAHandler(router, app.cfg, configFromDB.IsAnalyticsEnabled(), serverID, isTracetestDev)

if isNewInstall {
provision(provisioner, app.provisioningFile)
Expand All @@ -272,7 +274,7 @@ func (app *App) Start(opts ...appOption) error {
return nil
}

func registerSPAHandler(router *mux.Router, cfg httpServerConfig, analyticsEnabled bool, serverID string) {
func registerSPAHandler(router *mux.Router, cfg httpServerConfig, analyticsEnabled bool, serverID string, isTracetestDev bool) {
router.
PathPrefix(cfg.ServerPathPrefix()).
Handler(
Expand All @@ -282,6 +284,7 @@ func registerSPAHandler(router *mux.Router, cfg httpServerConfig, analyticsEnabl
serverID,
Version,
Env,
isTracetestDev,
),
)
}
Expand Down
3 changes: 2 additions & 1 deletion server/http/spa.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type spaConfig interface {
ExperimentalFeatures() []string
}

func SPAHandler(conf spaConfig, analyticsEnabled bool, serverID, version, env string) http.HandlerFunc {
func SPAHandler(conf spaConfig, analyticsEnabled bool, serverID, version, env string, isTracetestDev bool) http.HandlerFunc {
pathPrefix := conf.ServerPathPrefix()
return spaHandler(
pathPrefix,
Expand All @@ -73,6 +73,7 @@ func SPAHandler(conf spaConfig, analyticsEnabled bool, serverID, version, env st
"DemoEnabled": jsonEscape(conf.DemoEnabled()),
"DemoEndpoints": jsonEscape(conf.DemoEndpoints()),
"ExperimentalFeatures": jsonEscape(conf.ExperimentalFeatures()),
"IsTracetestDev": fmt.Sprintf("%t", isTracetestDev),
},
)
}
1 change: 1 addition & 0 deletions web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
appVersion: getTemplateValue('{{ .AppVersion }}', '', parser.toString),
env: getTemplateValue('{{ .Env }}', '', parser.toString),
experimentalFeatures: getTemplateValue('{{ .ExperimentalFeatures }}', '[]', parser.toArray),
isTracetestDev: getTemplateValue('{{ .IsTracetestDev }}', 'false', parser.toBoolean),
};

var base = document.createElement('base');
Expand Down
2 changes: 1 addition & 1 deletion web/src/services/Analytics/Analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import posthog from 'posthog-js';
import {Categories} from 'constants/Analytics.constants';
import Env from 'utils/Env';

const isAnalyticsEnabled = () => Env.get('analyticsEnabled');
const isAnalyticsEnabled = () => Env.get('analyticsEnabled') && !Env.get('isTracetestDev');
const appVersion = Env.get('appVersion');
const env = Env.get('env');
const serverID = Env.get('serverID');
Expand Down
1 change: 1 addition & 0 deletions web/src/types/Common.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IEnv {
serverID: string;
serverPathPrefix: string;
segmentLoaded: boolean;
isTracetestDev: boolean;
}

export interface IMockFactory<T, R> {
Expand Down
1 change: 1 addition & 0 deletions web/src/utils/Env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const emptyValues: IEnv = {
serverID: '',
serverPathPrefix: '/',
segmentLoaded: false,
isTracetestDev: false,
};

const Env = {
Expand Down

0 comments on commit 1268a6e

Please sign in to comment.