chore(server): remove sentry and only apply mixpanel middleware if enabled (#2732)

- remove sentry as we are no longer using it
- only enable mixpanel middleware if mixpanel is enabled
This commit is contained in:
Iain Sproat
2024-08-23 16:56:54 +01:00
committed by GitHub
parent a22a2fe52f
commit 26b0ecb55d
17 changed files with 23 additions and 257 deletions
+2 -11
View File
@@ -123,15 +123,6 @@ OIDC_DISCOVERY_URL="http://127.0.0.1:8090/realms/speckle/.well-known/openid-conf
OIDC_CLIENT_ID="account"
OIDC_CLIENT_SECRET="gLb9IEutYQ0npyvA8iHxPsObY3duGB0w"
############################################################
# Tracing & co.
# Note: all data is anonymous, and it helps us deliver
# better software. Disabling this makes Speckle sad!
############################################################
# SENTRY_DSN="-> FILL IN <-"
# DISABLE_TRACING=""
# DISABLE_TRACKING=""
############################################################
# Local dev environments
# If your frontend is served in dev from somewhere else,
@@ -142,8 +133,8 @@ OIDC_CLIENT_SECRET="gLb9IEutYQ0npyvA8iHxPsObY3duGB0w"
############################################################
# Speckle automate related variables
# the env var is only needed if you are running the server and
# the execution engine locally
# the env var is only needed if you are running the server and
# the execution engine locally
# FF_AUTOMATE_MODULE_ENABLED='true'
# SPECKLE_AUTOMATE_URL="http://127.0.0.1:3030"
#
+3 -5
View File
@@ -11,7 +11,6 @@ import compression from 'compression'
import cookieParser from 'cookie-parser'
import { createTerminus } from '@godaddy/terminus'
import * as Sentry from '@sentry/node'
import Logging from '@/logging'
import { startupLogger, shutdownLogger } from '@/logging/logging'
import {
@@ -45,7 +44,8 @@ import {
isDevEnv,
isTestEnv,
useNewFrontend,
isApolloMonitoringEnabled
isApolloMonitoringEnabled,
enableMixpanel
} from '@/modules/shared/helpers/envHelper'
import * as ModulesSetup from '@/modules'
import { GraphQLContext, Optional } from '@/modules/shared/helpers/typeHelper'
@@ -345,9 +345,7 @@ export async function init() {
next()
}
)
app.use(mixpanelTrackerHelperMiddleware)
app.use(Sentry.Handlers.errorHandler())
if (enableMixpanel()) app.use(mixpanelTrackerHelperMiddleware)
// Initialize default modules, including rest api handlers
await ModulesSetup.init(app)
+15 -24
View File
@@ -1,6 +1,5 @@
/* eslint-disable camelcase */
/* istanbul ignore file */
const Sentry = require('@sentry/node')
const { ApolloError } = require('apollo-server-express')
const prometheusClient = require('prom-client')
const { graphqlLogger } = require('@/logging/logging')
@@ -39,21 +38,23 @@ module.exports = {
userId
})
const transaction = Sentry.startTransaction({
const transaction = {
start: apolloRequestStart,
op,
name
})
name,
finish: () => {
//TODO add tracing with opentelemetry
}
}
try {
const actionName = `${ctx.operation.operation} ${ctx.operation.selectionSet.selections[0].name.value}`
logger = logger.child({ actionName })
metricCallCount.labels(actionName).inc()
// logger.debug(actionName)
} catch (e) {
Sentry.captureException(e)
logger.error({ err: e, transaction }, 'Error while defining action name')
}
Sentry.configureScope((scope) => scope.setSpan(transaction))
ctx.request.transaction = transaction
ctx.context.log = logger
},
@@ -66,10 +67,15 @@ module.exports = {
for (const err of ctx.errors) {
const operationName = ctx.request.operationName || null
const query = ctx.request.query
const variables = ctx.request.variables
const variables = redactSensitiveVariables(ctx.request.variables)
if (err.path) {
logger = logger.child({ 'query-path': err.path.join(' > ') })
logger = logger.child({
'query-path': err.path.join(' > '),
graphql_operation_name: operationName,
graphql_query: query,
graphql_variables: variables
})
}
if (
(err instanceof GraphQLError && err.extensions?.code === 'FORBIDDEN') ||
@@ -85,21 +91,6 @@ module.exports = {
'{graphql_operation_value} failed after {apollo_query_duration_ms} ms'
)
}
Sentry.withScope((scope) => {
scope.setTag('operationName', operationName)
scope.setExtra('query', query)
scope.setExtra('variables', variables)
if (err.path) {
// We can also add the path as breadcrumb
scope.addBreadcrumb({
category: 'query-path',
message: err.path.join(' > '),
level: Sentry.Severity.Debug
})
}
Sentry.captureException(err)
})
}
},
willSendResponse(ctx) {
-21
View File
@@ -1,7 +1,4 @@
/* istanbul ignore file */
const Sentry = require('@sentry/node')
const Tracing = require('@sentry/tracing')
const { getMachineId } = require('./machineId')
const prometheusClient = require('prom-client')
const promBundle = require('express-prom-bundle')
@@ -18,8 +15,6 @@ const { startupLogger: logger } = require('@/logging/logging')
let prometheusInitialized = false
module.exports = function (app) {
const id = getMachineId()
if (!prometheusInitialized) {
prometheusInitialized = true
prometheusClient.register.clear()
@@ -52,20 +47,4 @@ module.exports = function (app) {
app.use(expressMetricsMiddleware)
}
if (process.env.DISABLE_TRACING !== 'true' && process.env.SENTRY_DSN) {
Sentry.setUser({ id })
Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({ app })
],
tracesSampleRate: 0.1
})
app.use(Sentry.Handlers.requestHandler())
app.use(Sentry.Handlers.tracingHandler())
}
}
-18
View File
@@ -1,18 +0,0 @@
/* istanbul ignore file */
const Sentry = require('@sentry/node')
/**
* @param {{
* err: Error | unknown,
* kind?: string | null,
* extras?: { [key: string]: any } | null
* }} param0
*/
module.exports = function ({ err, kind, extras }) {
Sentry.withScope((scope) => {
if (kind) scope.setTag('kind', kind)
if (extras) scope.setExtra('extras', extras)
Sentry.captureException(err)
})
}
@@ -1,8 +1,5 @@
'use strict'
const cors = require('cors')
const sentry = require(`@/logging/sentryHelper`)
const {
getApp,
createAuthorizationCode,
@@ -56,7 +53,6 @@ module.exports = (app) => {
req.log.info({ err }, 'Invalid access code request error, or Forbidden error.')
return res.status(400).send(err.message)
} else {
sentry({ err })
req.log.error(err)
return res
.status(500)
@@ -103,7 +99,6 @@ module.exports = (app) => {
})
return res.send(authResponse)
} catch (err) {
sentry({ err })
req.log.info({ err }, 'Error while trying to generate a new token.')
return res.status(401).send({ err: err.message })
}
@@ -124,7 +119,6 @@ module.exports = (app) => {
return res.status(200).send({ message: 'You have logged out.' })
} catch (err) {
sentry({ err })
req.log.info({ err }, 'Error while trying to logout.')
return res.status(400).send('Something went wrong while trying to logout.')
}
+3 -5
View File
@@ -1,15 +1,14 @@
import ExpressSession from 'express-session'
import ConnectRedis from 'connect-redis'
import passport from 'passport'
import sentry from '@/logging/sentryHelper'
import { createAuthorizationCode } from '@/modules/auth/services/apps'
import {
getFrontendOrigin,
getMailchimpStatus,
getMailchimpNewsletterIds,
getMailchimpOnboardingIds,
getSessionSecret
getSessionSecret,
enableMixpanel
} from '@/modules/shared/helpers/envHelper'
import { isSSLServer, getRedisUrl } from '@/modules/shared/helpers/envHelper'
import { authLogger, logger } from '@/logging/logging'
@@ -104,7 +103,7 @@ const setupStrategies = async (app: Express) => {
// Send event to MP
const userEmail = req.user.email
const isInvite = !!req.user.isInvite
if (userEmail) {
if (userEmail && enableMixpanel()) {
await mixpanel({ userEmail, req }).track('Sign Up', {
isInvite
})
@@ -134,7 +133,6 @@ const setupStrategies = async (app: Express) => {
return res.redirect(redirectUrl)
} catch (err) {
sentry({ err })
authLogger.error(err, 'Could not finalize auth')
if (req.session) req.session.destroy(noop)
return res.status(401).send({
@@ -1,6 +1,5 @@
import { redisLogger } from '@/logging/logging'
import Redis, { RedisOptions } from 'ioredis'
import sentry from '@/logging/sentryHelper'
import {
EnvironmentResourceError,
MisconfiguredEnvironmentError
@@ -19,7 +18,6 @@ export function createRedisClient(redisUrl: string, redisOptions: RedisOptions):
})
} catch (err) {
redisLogger.error(err, 'Could not create Redis client')
sentry({ err, kind: null, extras: null })
if (err instanceof Error) {
throw new MisconfiguredEnvironmentError('Unable to connect to Redis.', err) //FIXME backoff and retry?
}
-2
View File
@@ -43,8 +43,6 @@
"@godaddy/terminus": "^4.9.0",
"@graphql-tools/schema": "^10.0.4",
"@mailchimp/mailchimp_marketing": "^3.0.80",
"@sentry/node": "^6.17.9",
"@sentry/tracing": "^6.17.9",
"@speckle/objectloader": "workspace:^",
"@speckle/shared": "workspace:^",
"ajv": "^8.12.0",
@@ -839,18 +839,6 @@ Generate the environment variables for Speckle server and Speckle objects deploy
value: "{{ .Values.server.mailchimp.onboardingStepId}}"
{{- end }}
# *** Tracking / Tracing ***
- name: SENTRY_DSN
value: {{ .Values.server.sentry_dns }}
{{- if .Values.server.disable_tracing }}
- name: DISABLE_TRACING
value: "true"
{{- end }}
{{- if .Values.server.disable_tracking }}
- name: DISABLE_TRACKING
value: "true"
{{- end }}
# Monitoring - Apollo
{{- if .Values.server.monitoring.apollo.enabled }}
- name: APOLLO_GRAPH_ID
@@ -51,10 +51,6 @@ spec:
{{- if .Values.server.monitoring.apollo.enabled }}
- matchPattern: "*.api.apollographql.com"
{{- end }}
{{- if .Values.server.sentry_dns }}
# DNS lookup for sentry
- matchPattern: "*.ingest.sentry.io"
{{- end }}
{{- if (ne "false" .Values.server.monitoring.mp.enabled) }}
- matchName: 'analytics.speckle.systems'
{{- end }}
@@ -104,15 +100,6 @@ spec:
- port: "443"
protocol: TCP
{{- end }}
{{- if .Values.server.sentry_dns }}
# egress to sentry
- toCIDRSet:
- cidr: 34.120.195.249/32
toPorts:
- ports:
- port: "443"
protocol: TCP
{{- end }}
{{- if .Values.server.email.enabled }}
# email server
{{ include "speckle.networkpolicy.egress.email.cilium" $ | indent 4 }}
@@ -37,14 +37,6 @@ spec:
ports:
- port: 443
{{- end }}
{{- if .Values.server.sentry_dns }}
# sentry.io https://docs.sentry.io/product/security/ip-ranges/#event-ingestion
- to:
- ipBlock:
cidr: 34.120.195.249/32
ports:
- port: 443
{{- end }}
{{- if .Values.server.email.enabled }}
# email server
{{ include "speckle.networkpolicy.egress.email" $ | indent 4 }}
@@ -51,10 +51,6 @@ spec:
{{- if .Values.server.monitoring.apollo.enabled }}
- matchPattern: "*.api.apollographql.com"
{{- end }}
{{- if .Values.server.sentry_dns }}
# DNS lookup for sentry
- matchPattern: "*.ingest.sentry.io"
{{- end }}
{{- if (ne "false" .Values.server.monitoring.mp.enabled) }}
- matchName: 'analytics.speckle.systems'
{{- end }}
@@ -104,15 +100,6 @@ spec:
- port: "443"
protocol: TCP
{{- end }}
{{- if .Values.server.sentry_dns }}
# egress to sentry
- toCIDRSet:
- cidr: 34.120.195.249/32
toPorts:
- ports:
- port: "443"
protocol: TCP
{{- end }}
{{- if .Values.server.email.enabled }}
# email server
{{ include "speckle.networkpolicy.egress.email.cilium" $ | indent 4 }}
@@ -37,14 +37,6 @@ spec:
ports:
- port: 443
{{- end }}
{{- if .Values.server.sentry_dns }}
# sentry.io https://docs.sentry.io/product/security/ip-ranges/#event-ingestion
- to:
- ipBlock:
cidr: 34.120.195.249/32
ports:
- port: 443
{{- end }}
{{- if .Values.server.email.enabled }}
# email server
{{ include "speckle.networkpolicy.egress.email" $ | indent 4 }}
@@ -1223,11 +1223,6 @@
}
}
},
"sentry_dns": {
"type": "string",
"description": "(Optional) The Data Source Name that was provided by Sentry.io",
"default": ""
},
"disable_tracking": {
"type": "boolean",
"description": "If set to true, will prevent tracking metrics from being collected",
-7
View File
@@ -753,17 +753,10 @@ server:
secretKey: ''
## @param server.monitoring.mp (Optional) If server.monitoring.mp.enabled is set to false, metrics will not be collected by the Speckle server.
mp: {}
## @param server.sentry_dns (Optional) The Data Source Name that was provided by Sentry.io
## Sentry.io allows events within Speckle to be monitored
##
sentry_dns: ''
## @param server.disable_tracking If set to true, will prevent tracking metrics from being collected
## Setting this value to false requires `sentry_dns` to be set
##
disable_tracking: false
## @param server.disable_tracing If set to true, will prevent tracing metrics from being collected
## Setting this value to false requires `sentry_dns` to be set
##
disable_tracing: false
networkPolicy:
-97
View File
@@ -14138,87 +14138,6 @@ __metadata:
languageName: node
linkType: hard
"@sentry/core@npm:6.19.7":
version: 6.19.7
resolution: "@sentry/core@npm:6.19.7"
dependencies:
"@sentry/hub": "npm:6.19.7"
"@sentry/minimal": "npm:6.19.7"
"@sentry/types": "npm:6.19.7"
"@sentry/utils": "npm:6.19.7"
tslib: "npm:^1.9.3"
checksum: 10/75f98ae1ad2d27deda35f88f07cf6a29f1f2eaa956ba5e2292d4d8ea2cd087a6c4a9303856ac09e6cab5cea0a1579128f35f7add14524c6e72292e65ebeab6ab
languageName: node
linkType: hard
"@sentry/hub@npm:6.19.7":
version: 6.19.7
resolution: "@sentry/hub@npm:6.19.7"
dependencies:
"@sentry/types": "npm:6.19.7"
"@sentry/utils": "npm:6.19.7"
tslib: "npm:^1.9.3"
checksum: 10/ef2381ec399305ee56f7cff990c5bf0f221119193ac1b0862d237c42c9e214a8a3dcabe55085e197710c9667f1c541fffc3fe37e89d7562f3c86432c22d7f09a
languageName: node
linkType: hard
"@sentry/minimal@npm:6.19.7":
version: 6.19.7
resolution: "@sentry/minimal@npm:6.19.7"
dependencies:
"@sentry/hub": "npm:6.19.7"
"@sentry/types": "npm:6.19.7"
tslib: "npm:^1.9.3"
checksum: 10/eac4f79f7116dee90bfd8ea284c777c267e70c0b51883bc419f176dd5283b2b1955ede0bc471759f26a8c686f78f7a664560684a8998fc4c6f85d9e1539d39f9
languageName: node
linkType: hard
"@sentry/node@npm:^6.17.9":
version: 6.19.7
resolution: "@sentry/node@npm:6.19.7"
dependencies:
"@sentry/core": "npm:6.19.7"
"@sentry/hub": "npm:6.19.7"
"@sentry/types": "npm:6.19.7"
"@sentry/utils": "npm:6.19.7"
cookie: "npm:^0.4.1"
https-proxy-agent: "npm:^5.0.0"
lru_map: "npm:^0.3.3"
tslib: "npm:^1.9.3"
checksum: 10/8769b31f579688d073a357b767b45c2128f189500a5f38c7c130f73e7dd735f968ff89583d4ab8fdbddfcd3dad23467b11ad483355b8d06dd984d94b2a2eb134
languageName: node
linkType: hard
"@sentry/tracing@npm:^6.17.9":
version: 6.19.7
resolution: "@sentry/tracing@npm:6.19.7"
dependencies:
"@sentry/hub": "npm:6.19.7"
"@sentry/minimal": "npm:6.19.7"
"@sentry/types": "npm:6.19.7"
"@sentry/utils": "npm:6.19.7"
tslib: "npm:^1.9.3"
checksum: 10/4ac6c66c39ea39fe5b2fff0b74039e0c4475c2ea0667c9ec4a6414a56ddb20b9996e7dae8bc1292882745bd0800a3c6d8f4853fba32552d9cdb1cb6f7be9105c
languageName: node
linkType: hard
"@sentry/types@npm:6.19.7":
version: 6.19.7
resolution: "@sentry/types@npm:6.19.7"
checksum: 10/f9f70e94c4a3876f6119f7e3979051ea2a054adce6f5583de9f70a08642c7d2c2f80a70a1f9fe5f9fad4e99315f4483340ded1110ae2e7c825c4c1f210fc2507
languageName: node
linkType: hard
"@sentry/utils@npm:6.19.7":
version: 6.19.7
resolution: "@sentry/utils@npm:6.19.7"
dependencies:
"@sentry/types": "npm:6.19.7"
tslib: "npm:^1.9.3"
checksum: 10/0ea94d32940705d77b019ca821e45a5866bb3d443e0f19b9bf5edf3d7ffed68c451803f3388913fec4da875e4b7df46b5f8a8681c4d69972fb3d775d864997b2
languageName: node
linkType: hard
"@shikijs/core@npm:1.3.0":
version: 1.3.0
resolution: "@shikijs/core@npm:1.3.0"
@@ -15390,8 +15309,6 @@ __metadata:
"@graphql-tools/schema": "npm:^10.0.4"
"@mailchimp/mailchimp_marketing": "npm:^3.0.80"
"@parcel/watcher": "npm:^2.4.1"
"@sentry/node": "npm:^6.17.9"
"@sentry/tracing": "npm:^6.17.9"
"@speckle/objectloader": "workspace:^"
"@speckle/shared": "workspace:^"
"@swc/core": "npm:^1.2.222"
@@ -25999,13 +25916,6 @@ __metadata:
languageName: node
linkType: hard
"cookie@npm:^0.4.1":
version: 0.4.2
resolution: "cookie@npm:0.4.2"
checksum: 10/2e1de9fdedca54881eab3c0477aeb067f281f3155d9cfee9d28dfb252210d09e85e9d175c0a60689661feb9e35e588515352f2456bc1f8e8db4267e05fd70137
languageName: node
linkType: hard
"cookie@npm:^0.5.0":
version: 0.5.0
resolution: "cookie@npm:0.5.0"
@@ -36549,13 +36459,6 @@ __metadata:
languageName: node
linkType: hard
"lru_map@npm:^0.3.3":
version: 0.3.3
resolution: "lru_map@npm:0.3.3"
checksum: 10/50f6597924a7763ab0b31192e5e9965f08ca64a0044254138e74a65aecab95047d540f73739cff489866f4310e0202c11c10fdf18b10b236472160baaa68bbb1
languageName: node
linkType: hard
"ltgt@npm:^2.1.2":
version: 2.2.1
resolution: "ltgt@npm:2.2.1"