Compare commits
11 Commits
v2.4.32
...
fix/qa-wor
| Author | SHA1 | Date | |
|---|---|---|---|
| a5776f24d7 | |||
| 19ccd90070 | |||
| c1cad7b99b | |||
| cbda41ee95 | |||
| 42ccafd445 | |||
| 84402f90fc | |||
| a701495607 | |||
| 88132b8f84 | |||
| 7a9a21732b | |||
| f75bc146c5 | |||
| 0f554f2317 |
3
.env
3
.env
@@ -27,7 +27,7 @@ UMAMI_API_ENDPOINT=https://analytics.infra.mintel.me
|
|||||||
# Error Tracking (GlitchTip/Sentry)
|
# Error Tracking (GlitchTip/Sentry)
|
||||||
# ────────────────────────────────────────────────────────────────────────────
|
# ────────────────────────────────────────────────────────────────────────────
|
||||||
# Optional: Leave empty to disable error tracking
|
# Optional: Leave empty to disable error tracking
|
||||||
SENTRY_DSN=https://dcb81958-dbf2-4a3d-b422-875f4672c14b@glitchtip.infra.mintel.me/5
|
SENTRY_DSN=https://dcb81958dbf24a3db422875f4672c14b@errors.infra.mintel.me/5
|
||||||
|
|
||||||
# ────────────────────────────────────────────────────────────────────────────
|
# ────────────────────────────────────────────────────────────────────────────
|
||||||
# Email Configuration (SMTP)
|
# Email Configuration (SMTP)
|
||||||
@@ -45,7 +45,6 @@ MAIL_RECIPIENTS=info@e-tib.com
|
|||||||
# ────────────────────────────────────────────────────────────────────────────
|
# ────────────────────────────────────────────────────────────────────────────
|
||||||
LOG_LEVEL=info
|
LOG_LEVEL=info
|
||||||
GATEKEEPER_PASSWORD=klz2026
|
GATEKEEPER_PASSWORD=klz2026
|
||||||
SENTRY_DSN=
|
|
||||||
# SENTRY_ENVIRONMENT is set automatically by CI
|
# SENTRY_ENVIRONMENT is set automatically by CI
|
||||||
|
|
||||||
# ────────────────────────────────────────────────────────────────────────────
|
# ────────────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ MAIL_RECIPIENTS=info@e-tib.com
|
|||||||
# ────────────────────────────────────────────────────────────────────────────
|
# ────────────────────────────────────────────────────────────────────────────
|
||||||
LOG_LEVEL=info
|
LOG_LEVEL=info
|
||||||
GATEKEEPER_PASSWORD=klz2026
|
GATEKEEPER_PASSWORD=klz2026
|
||||||
SENTRY_DSN=
|
|
||||||
# SENTRY_ENVIRONMENT is set automatically by CI
|
# SENTRY_ENVIRONMENT is set automatically by CI
|
||||||
|
|
||||||
# ────────────────────────────────────────────────────────────────────────────
|
# ────────────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ UMAMI_WEBSITE_ID=d773ea10-a3b3-4ccf-9024-987e14c4d669
|
|||||||
UMAMI_API_ENDPOINT=https://analytics.infra.mintel.me
|
UMAMI_API_ENDPOINT=https://analytics.infra.mintel.me
|
||||||
|
|
||||||
# Error Tracking (GlitchTip/Sentry)
|
# Error Tracking (GlitchTip/Sentry)
|
||||||
SENTRY_DSN=
|
SENTRY_DSN=https://dcb81958dbf24a3db422875f4672c14b@errors.infra.mintel.me/5
|
||||||
|
|
||||||
# Email Configuration (Mailgun)
|
# Email Configuration (Mailgun)
|
||||||
MAIL_HOST=smtp.eu.mailgun.org
|
MAIL_HOST=smtp.eu.mailgun.org
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ const mdxComponents = {
|
|||||||
JsonLd,
|
JsonLd,
|
||||||
Button,
|
Button,
|
||||||
Badge,
|
Badge,
|
||||||
|
Heading,
|
||||||
AnimatedCounter,
|
AnimatedCounter,
|
||||||
GrowthChart,
|
GrowthChart,
|
||||||
DeepDrillAnimation,
|
DeepDrillAnimation,
|
||||||
|
|||||||
@@ -1,13 +1,83 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
|
import https from 'https';
|
||||||
|
|
||||||
|
const ALLOWED_HOSTS = ['glitchtip.infra.mintel.me', 'errors.infra.mintel.me'];
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
try {
|
try {
|
||||||
const rawText = await req.text();
|
const rawText = await req.text();
|
||||||
// Sentry sends NDJSON (Newline Delimited JSON). Split by newline to parse safely.
|
const items = rawText.split('\n');
|
||||||
const items = rawText.split('\n').filter(Boolean).map(line => JSON.parse(line));
|
|
||||||
console.log("CLIENT ERROR INTERCEPTED:", JSON.stringify(items[0], null, 2));
|
if (items.length === 0 || !items[0]) {
|
||||||
|
return NextResponse.json({ error: 'Empty payload' }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const header = JSON.parse(items[0]);
|
||||||
|
// Use the server's configured DSN (if available) to override the client's potentially fake DSN
|
||||||
|
// This allows the client to work without exposing NEXT_PUBLIC_SENTRY_DSN
|
||||||
|
const dsn = process.env.SENTRY_DSN || header.dsn;
|
||||||
|
if (!dsn) {
|
||||||
|
return NextResponse.json({ error: 'No DSN found' }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(dsn);
|
||||||
|
const projectId = url.pathname.replace('/', '');
|
||||||
|
const host = url.hostname;
|
||||||
|
|
||||||
|
if (!ALLOWED_HOSTS.includes(host)) {
|
||||||
|
return NextResponse.json({ error: 'Invalid Sentry Host' }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rewrite the DSN in the envelope header so Glitchtip doesn't reject the fake client DSN
|
||||||
|
if (process.env.SENTRY_DSN) {
|
||||||
|
header.dsn = process.env.SENTRY_DSN;
|
||||||
|
items[0] = JSON.stringify(header);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sentryIngestUrl = `https://${host}/api/${projectId}/envelope/`;
|
||||||
|
const payloadToForward = items.join('\n');
|
||||||
|
|
||||||
|
return new Promise<NextResponse>((resolve) => {
|
||||||
|
const req = https.request(
|
||||||
|
sentryIngestUrl,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-sentry-envelope',
|
||||||
|
},
|
||||||
|
// Bypass self-signed cert error since glitchtip.infra.mintel.me uses an internal CA
|
||||||
|
// that the Next.js docker container doesn't trust by default.
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
},
|
||||||
|
(res) => {
|
||||||
|
res.on('data', () => {
|
||||||
|
// Consume data to free up memory
|
||||||
|
});
|
||||||
|
res.on('end', () => {
|
||||||
|
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
||||||
|
resolve(NextResponse.json({ success: true }));
|
||||||
|
} else {
|
||||||
|
resolve(
|
||||||
|
NextResponse.json(
|
||||||
|
{ error: `Relay rejected (${res.statusCode})` },
|
||||||
|
{ status: res.statusCode || 500 }
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
req.on('error', (err) => {
|
||||||
|
console.error('[Sentry Tunnel] https.request failed', err);
|
||||||
|
resolve(NextResponse.json({ error: 'Relay failed' }, { status: 500 }));
|
||||||
|
});
|
||||||
|
|
||||||
|
req.write(payloadToForward);
|
||||||
|
req.end();
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Failed to parse relay body (NDJSON)", e);
|
console.error("[Sentry Tunnel] Failed to parse or relay body", e);
|
||||||
|
return NextResponse.json({ error: 'Relay failed' }, { status: 500 });
|
||||||
}
|
}
|
||||||
return NextResponse.json({ success: true });
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ const mdxComponents = {
|
|||||||
ul: (props: any) => <ul className="grid grid-cols-1 gap-2 mb-6" {...props} />,
|
ul: (props: any) => <ul className="grid grid-cols-1 gap-2 mb-6" {...props} />,
|
||||||
li: CustomLi,
|
li: CustomLi,
|
||||||
p: (props: any) => <p className="text-neutral-600 text-sm mb-4 leading-relaxed" {...props} />,
|
p: (props: any) => <p className="text-neutral-600 text-sm mb-4 leading-relaxed" {...props} />,
|
||||||
|
Heading,
|
||||||
};
|
};
|
||||||
|
|
||||||
interface PageProps {
|
interface PageProps {
|
||||||
|
|||||||
@@ -22,11 +22,18 @@ export default function AnalyticsShell() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const initServices = () => {
|
||||||
|
import('@/lib/services/create-services').then(({ getAppServices }) => {
|
||||||
|
getAppServices();
|
||||||
|
setShouldLoad(true);
|
||||||
|
}).catch(console.error);
|
||||||
|
};
|
||||||
|
|
||||||
// Wait until browser is completely idle before loading heavy analytics/logger/sentry SDKs
|
// Wait until browser is completely idle before loading heavy analytics/logger/sentry SDKs
|
||||||
if (typeof window !== 'undefined' && 'requestIdleCallback' in window) {
|
if (typeof window !== 'undefined' && 'requestIdleCallback' in window) {
|
||||||
window.requestIdleCallback(() => setShouldLoad(true), { timeout: 3000 });
|
window.requestIdleCallback(initServices, { timeout: 3000 });
|
||||||
} else {
|
} else {
|
||||||
const timer = setTimeout(() => setShouldLoad(true), 2500);
|
const timer = setTimeout(initServices, 2500);
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { AppServices } from './app-services';
|
|||||||
import { NoopAnalyticsService } from './analytics/noop-analytics-service';
|
import { NoopAnalyticsService } from './analytics/noop-analytics-service';
|
||||||
import { UmamiAnalyticsService } from './analytics/umami-analytics-service';
|
import { UmamiAnalyticsService } from './analytics/umami-analytics-service';
|
||||||
import { MemoryCacheService } from './cache/memory-cache-service';
|
import { MemoryCacheService } from './cache/memory-cache-service';
|
||||||
|
import { GlitchtipErrorReportingService } from './errors/glitchtip-error-reporting-service';
|
||||||
import { NoopErrorReportingService } from './errors/noop-error-reporting-service';
|
import { NoopErrorReportingService } from './errors/noop-error-reporting-service';
|
||||||
import { NoopLoggerService } from './logging/noop-logger-service';
|
import { NoopLoggerService } from './logging/noop-logger-service';
|
||||||
import { PinoLoggerService } from './logging/pino-logger-service';
|
import { PinoLoggerService } from './logging/pino-logger-service';
|
||||||
@@ -67,7 +68,17 @@ export function getAppServices(): AppServices {
|
|||||||
logger.info('Notification service initialized (noop)');
|
logger.info('Notification service initialized (noop)');
|
||||||
|
|
||||||
// Create error reporting service (GlitchTip/Sentry or no-op)
|
// Create error reporting service (GlitchTip/Sentry or no-op)
|
||||||
const errors = new NoopErrorReportingService();
|
const errors = sentryEnabled
|
||||||
|
? new GlitchtipErrorReportingService(
|
||||||
|
{
|
||||||
|
enabled: true,
|
||||||
|
dsn: config.errors.glitchtip.dsn,
|
||||||
|
tracesSampleRate: 0.1, // Client-side we usually want lower sample rate
|
||||||
|
},
|
||||||
|
logger,
|
||||||
|
notifications,
|
||||||
|
)
|
||||||
|
: new NoopErrorReportingService();
|
||||||
|
|
||||||
if (sentryEnabled) {
|
if (sentryEnabled) {
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|||||||
@@ -140,7 +140,7 @@
|
|||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
"preinstall": "npx only-allow pnpm"
|
"preinstall": "npx only-allow pnpm"
|
||||||
},
|
},
|
||||||
"version": "2.4.28",
|
"version": "2.4.36",
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"onlyBuiltDependencies": [
|
"onlyBuiltDependencies": [
|
||||||
"@parcel/watcher",
|
"@parcel/watcher",
|
||||||
|
|||||||
26
tests/create-services.test.ts
Normal file
26
tests/create-services.test.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
|
import { getAppServices } from '../lib/services/create-services';
|
||||||
|
import { GlitchtipErrorReportingService } from '../lib/services/errors/glitchtip-error-reporting-service';
|
||||||
|
|
||||||
|
// Mock config to ensure sentry is enabled
|
||||||
|
vi.mock('../lib/config', () => ({
|
||||||
|
config: {
|
||||||
|
analytics: { umami: { enabled: false } },
|
||||||
|
errors: { glitchtip: { enabled: true, dsn: 'https://test@glitchtip.infra.mintel.me/5' } },
|
||||||
|
logging: { level: 'info' },
|
||||||
|
notifications: { gotify: { enabled: false } },
|
||||||
|
},
|
||||||
|
getMaskedConfig: () => ({}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('AppServices (Client)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
// Reset singleton
|
||||||
|
globalThis.__appServices = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should instantiate GlitchtipErrorReportingService when enabled', () => {
|
||||||
|
const services = getAppServices();
|
||||||
|
expect(services.errors).toBeInstanceOf(GlitchtipErrorReportingService);
|
||||||
|
});
|
||||||
|
});
|
||||||
20
tests/sentry-config.test.ts
Normal file
20
tests/sentry-config.test.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import * as dotenv from 'dotenv';
|
||||||
|
|
||||||
|
describe('Sentry Configuration', () => {
|
||||||
|
it('should have a valid SENTRY_DSN in .env', () => {
|
||||||
|
// Read the .env file as a string
|
||||||
|
const envPath = resolve(process.cwd(), '.env');
|
||||||
|
const envContent = readFileSync(envPath, 'utf8');
|
||||||
|
|
||||||
|
// Parse it using dotenv
|
||||||
|
const envConfig = dotenv.parse(envContent);
|
||||||
|
|
||||||
|
// Assert that SENTRY_DSN is defined and not empty
|
||||||
|
expect(envConfig.SENTRY_DSN).toBeDefined();
|
||||||
|
expect(envConfig.SENTRY_DSN.length).toBeGreaterThan(0);
|
||||||
|
expect(envConfig.SENTRY_DSN).toMatch(/^https:\/\/.+@glitchtip.infra.mintel.me\/\d+$/);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user