Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

improved new relic integration

Blue Mousec783c79c128c
diff --git a/.env.example b/.env.example
index 53dbf75f8..26b3e1100 100644
--- a/.env.example
+++ b/.env.example
@@ -34,4 +34,6 @@ SMTP_MOCK=true
PASSWORD=12345678
-SELFHOSTED=true
\ No newline at end of file
+# Use New Relic monitoring, leave empty if not using it
+USE_NEW_RELIC=
+NEW_RELIC_LICENSE_KEY=
\ No newline at end of file
diff --git a/src/app.module.ts b/src/app.module.ts
index b1fdbd339..e3ee75498 100644
--- a/src/app.module.ts
+++ b/src/app.module.ts
@@ -28,7 +28,7 @@ import { PingModule } from './ping/ping.module'
username: process.env.MYSQL_USER,
password: process.env.MYSQL_ROOT_PASSWORD,
database: process.env.MYSQL_DATABASE,
- synchronize: process.env.NODE_ENV === 'development' ? true : false,
+ synchronize: process.env.NODE_ENV === 'development',
entities: [User, ActionToken, Project, ProjectShare],
}),
ScheduleModule.forRoot(),
diff --git a/src/common/constants.ts b/src/common/constants.ts
index ddaa7ac23..63c7000a1 100644
--- a/src/common/constants.ts
+++ b/src/common/constants.ts
@@ -36,6 +36,7 @@ const clickhouse = new ClickHouse({
})
const isSelfhosted = Boolean(process.env.SELFHOSTED)
+const isNewRelicEnabled = Boolean(process.env.USE_NEW_RELIC)
const CLICKHOUSE_INIT_QUERIES = [
'CREATE DATABASE IF NOT EXISTS analytics',
@@ -169,4 +170,5 @@ export {
REDIS_SESSION_SALT_KEY, HEARTBEAT_SID_LIFE_TIME, isSelfhosted, UUIDV5_NAMESPACE, SELFHOSTED_EMAIL,
SELFHOSTED_PASSWORD, SELFHOSTED_UUID, CLICKHOUSE_INIT_QUERIES, REDIS_USERS_COUNT_KEY, REDIS_PROJECTS_COUNT_KEY,
REDIS_PAGEVIEWS_COUNT_KEY, SEND_WARNING_AT_PERC, PROJECT_INVITE_EXPIRE, TWO_FACTOR_AUTHENTICATION_APP_NAME,
+ isNewRelicEnabled,
}
diff --git a/src/main.ts b/src/main.ts
index 19772f8c0..8a99bc6d2 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -2,17 +2,17 @@ import { NestFactory } from '@nestjs/core'
import { ValidationPipe } from '@nestjs/common'
import * as cookieParser from 'cookie-parser'
import * as bodyParser from 'body-parser'
-import newrelic from 'newrelic';
+import { isNewRelicEnabled } from './common/constants'
import { AppModule } from './app.module'
-import { NewrelicInterceptor } from './common/interceptors/newrelic.interceptor';
+import { NewrelicInterceptor } from './common/interceptors/newrelic.interceptor'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
app.use(cookieParser())
app.useGlobalPipes(new ValidationPipe())
- if (process.env.SELFHOSTED) {
+ if (isNewRelicEnabled && process.env.NODE_ENV !== 'development') {
app.useGlobalInterceptors(new NewrelicInterceptor())
}
diff --git a/src/newrelic.ts b/src/newrelic.ts
index 7ab9bc81b..6995b446a 100644
--- a/src/newrelic.ts
+++ b/src/newrelic.ts
@@ -1 +1,62 @@
-// config here
\ No newline at end of file
+'use strict'
+
+/**
+ * New Relic agent configuration.
+ *
+ * See lib/config/default.js in the agent distribution for a more complete
+ * description of configuration variables and their potential values.
+ */
+exports.config = {
+ /**
+ * Array of application names.
+ */
+ app_name: ['SwetrixAPI'],
+ /**
+ * Your New Relic license key.
+ */
+ license_key: process.env.NEW_RELIC_LICENSE_KEY,
+ logging: {
+ /**
+ * Level at which to log. 'trace' is most useful to New Relic when diagnosing
+ * issues with the agent, 'info' and higher will impose the least overhead on
+ * production applications.
+ */
+ level: 'info'
+ },
+ /**
+ * When true, all request headers except for those listed in attributes.exclude
+ * will be captured for all traces, unless otherwise specified in a destination's
+ * attributes include/exclude lists.
+ */
+ allow_all_headers: true,
+ application_logging: {
+ forwarding: {
+ /**
+ * Toggles whether the agent gathers log records for sending to New Relic.
+ */
+ enabled: true
+ }
+ },
+ attributes: {
+ /**
+ * Prefix of attributes to exclude from all destinations. Allows * as wildcard
+ * at end.
+ *
+ * NOTE: If excluding headers, they must be in camelCase form to be filtered.
+ *
+ * @env NEW_RELIC_ATTRIBUTES_EXCLUDE
+ */
+ exclude: [
+ 'request.headers.cookie',
+ 'request.headers.authorization',
+ 'request.headers.proxyAuthorization',
+ 'request.headers.setCookie*',
+ 'request.headers.x*',
+ 'response.headers.cookie',
+ 'response.headers.authorization',
+ 'response.headers.proxyAuthorization',
+ 'response.headers.setCookie*',
+ 'response.headers.x*'
+ ]
+ }
+}