mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
chore: use instrumentation hook for telemetry
This commit is contained in:
@ -118,4 +118,4 @@ NEXT_PRIVATE_REDIS_URL=
|
|||||||
NEXT_PRIVATE_REDIS_TOKEN=
|
NEXT_PRIVATE_REDIS_TOKEN=
|
||||||
|
|
||||||
# [[Telemetry]]
|
# [[Telemetry]]
|
||||||
DISABLE_TELEMETRY=true
|
DISABLE_TELEMETRY=false
|
||||||
|
|||||||
@ -28,6 +28,7 @@ const config = {
|
|||||||
experimental: {
|
experimental: {
|
||||||
outputFileTracingRoot: path.join(__dirname, '../../'),
|
outputFileTracingRoot: path.join(__dirname, '../../'),
|
||||||
serverComponentsExternalPackages: ['@node-rs/bcrypt', '@documenso/pdf-sign', 'playwright'],
|
serverComponentsExternalPackages: ['@node-rs/bcrypt', '@documenso/pdf-sign', 'playwright'],
|
||||||
|
instrumentationHook: true,
|
||||||
serverActions: {
|
serverActions: {
|
||||||
bodySizeLimit: '50mb',
|
bodySizeLimit: '50mb',
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,14 +4,12 @@ import { Caveat, Inter } from 'next/font/google';
|
|||||||
|
|
||||||
import { AxiomWebVitals } from 'next-axiom';
|
import { AxiomWebVitals } from 'next-axiom';
|
||||||
import { PublicEnvScript } from 'next-runtime-env';
|
import { PublicEnvScript } from 'next-runtime-env';
|
||||||
import { version } from 'package.json';
|
|
||||||
|
|
||||||
import { FeatureFlagProvider } from '@documenso/lib/client-only/providers/feature-flag';
|
import { FeatureFlagProvider } from '@documenso/lib/client-only/providers/feature-flag';
|
||||||
import { LocaleProvider } from '@documenso/lib/client-only/providers/locale';
|
import { LocaleProvider } from '@documenso/lib/client-only/providers/locale';
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
import { getServerComponentAllFlags } from '@documenso/lib/server-only/feature-flags/get-server-component-feature-flag';
|
import { getServerComponentAllFlags } from '@documenso/lib/server-only/feature-flags/get-server-component-feature-flag';
|
||||||
import { getLocale } from '@documenso/lib/server-only/headers/get-locale';
|
import { getLocale } from '@documenso/lib/server-only/headers/get-locale';
|
||||||
import { sendInstanceInfo } from '@documenso/lib/server-only/telemetry/send-instance-info';
|
|
||||||
import { TrpcProvider } from '@documenso/trpc/react';
|
import { TrpcProvider } from '@documenso/trpc/react';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Toaster } from '@documenso/ui/primitives/toaster';
|
import { Toaster } from '@documenso/ui/primitives/toaster';
|
||||||
@ -60,13 +58,6 @@ export default async function RootLayout({ children }: { children: React.ReactNo
|
|||||||
|
|
||||||
const locale = getLocale();
|
const locale = getLocale();
|
||||||
|
|
||||||
void sendInstanceInfo({
|
|
||||||
// TODO: Get actual uniqueId for each user
|
|
||||||
uniqueId: 1,
|
|
||||||
timestamp: new Date(),
|
|
||||||
version,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<html
|
<html
|
||||||
lang="en"
|
lang="en"
|
||||||
|
|||||||
9
apps/web/src/instrumentation.ts
Normal file
9
apps/web/src/instrumentation.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { sendInstanceInfo } from '@documenso/lib/server-only/telemetry/send-instance-info';
|
||||||
|
|
||||||
|
export async function register() {
|
||||||
|
await sendInstanceInfo({
|
||||||
|
uniqueId: '1',
|
||||||
|
timestamp: new Date(),
|
||||||
|
version: '1.2.3',
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -1,14 +1,10 @@
|
|||||||
export type SendInstanceInfo = {
|
export type SendInstanceInfo = {
|
||||||
uniqueId: number;
|
uniqueId: string;
|
||||||
timestamp: Date;
|
timestamp: Date;
|
||||||
version: string;
|
version: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sendInstanceInfo = async ({
|
export const sendInstanceInfo = async ({ uniqueId, timestamp, version }: SendInstanceInfo) => {
|
||||||
uniqueId,
|
|
||||||
timestamp,
|
|
||||||
version,
|
|
||||||
}: SendInstanceInfo): Promise<void> => {
|
|
||||||
const isProduction = process.env.NODE_ENV === 'production';
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
const isTelemetryDisabled = process.env.DISABLE_TELEMETRY === 'true';
|
const isTelemetryDisabled = process.env.DISABLE_TELEMETRY === 'true';
|
||||||
|
|
||||||
@ -22,8 +18,8 @@ export const sendInstanceInfo = async ({
|
|||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
uniqueId,
|
uniqueId: String(uniqueId),
|
||||||
timestamp,
|
timestamp: new Date(timestamp).toISOString(),
|
||||||
version,
|
version,
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
@ -35,8 +31,8 @@ export const sendInstanceInfo = async ({
|
|||||||
throw new Error(`Failed to record instance, failed with status code ${response.status}`);
|
throw new Error(`Failed to record instance, failed with status code ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await response.json();
|
return await response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error posting instance information:', error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user