Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: block fe analytics if TRACETEST_DEV is present #2503

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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