@saas-pro-lib/monitoring
v0.1.0
Published
Shared browser and Next.js monitoring helpers for SaaS products: Sentry trace sampling and CloudWatch RUM error capture.
Readme
@saas-pro-lib/monitoring
Shared monitoring helpers for SaaS frontends.
The package keeps provider SDKs optional. Product apps can use the Sentry
sampler without importing @sentry/nextjs, and can pass the AwsRum
constructor only in browser-only initialization code.
Sentry trace sampling
import {
buildSentryTracesSamplerFromEnv,
DEFAULT_TRACE_SAMPLING_POLICY,
} from "@saas-pro-lib/monitoring";
Sentry.init({
dsn,
environment,
tracesSampler: buildSentryTracesSamplerFromEnv(
process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE,
DEFAULT_TRACE_SAMPLING_POLICY,
),
});Default priority:
- Health-like server paths:
0% - Error or
5xx:100% - Billing / Stripe paths:
100% - Auth / OAuth paths:
50% - Sequence execution paths and
sequence-step-executor:30% - CRM core paths:
15% - Admin paths:
50% - Baseline:
10%, clipped at30%
Products can provide a custom TraceSamplingPolicy to replace the path
priorities while keeping the same resolver.
CloudWatch RUM
import { AwsRum } from "aws-rum-web";
import { createCloudWatchRumMonitor } from "@saas-pro-lib/monitoring";
const rum = createCloudWatchRumMonitor(
{
applicationId: process.env.NEXT_PUBLIC_AWS_RUM_APPLICATION_ID,
identityPoolId: process.env.NEXT_PUBLIC_AWS_RUM_IDENTITY_POOL_ID,
applicationVersion: "1.0.0",
applicationRegion: "ap-northeast-1",
},
AwsRum,
);
rum.recordError(new Error("example"));When required IDs are missing, initialization returns an explicit disabled monitor instead of throwing or silently pretending to send data.
