Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion controlplane/src/core/sentry.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@ const {
SENTRY_ENABLE_LOGS,
} = sentryEnvVariables.parse(process.env);

// RPC paths we always trace at 100%, regardless of SENTRY_TRACES_SAMPLE_RATE. Batch
// subgraph publishes are rare, slow, and frequently hit the request timeout — we want a
// trace for every one so their end-to-end composition cost can be tracked. Child spans
// (e.g. ComposeGraphsWorker.composeGraphsInWorker) inherit the parent's sampling decision.
const ALWAYS_SAMPLE_PATHS = ['/wg.cosmo.platform.v1.PlatformService/PublishFederatedSubgraphs'];

const publishAwareTracesSampler: NonNullable<Sentry.NodeOptions['tracesSampler']> = (ctx) => {
const attrs = ctx.attributes ?? {};
const target = [ctx.name, attrs['http.route'], attrs['http.target'], attrs['url.path'], attrs['url.full']]
Comment thread
gausie marked this conversation as resolved.
Outdated
.filter(Boolean)
.join(' ');

// Batch publishes are always traced, regardless of the base rate or any upstream decision.
if (ALWAYS_SAMPLE_PATHS.some((path) => target.includes(path))) {
Comment thread
comatory marked this conversation as resolved.
Outdated
return 1;
}

// Otherwise honor an upstream sampling decision exactly so distributed traces stay intact:
// a parent that opted out (parentSampled === false) must not leave orphaned child spans.
if (typeof ctx.parentSampled === 'boolean') {
return ctx.parentSampled ? 1 : 0;
}

return SENTRY_TRACES_SAMPLE_RATE;
};

if (SENTRY_ENABLED && SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,
Expand All @@ -28,7 +54,9 @@ if (SENTRY_ENABLED && SENTRY_DSN) {
],
profileSessionSampleRate: SENTRY_PROFILE_SESSION_SAMPLE_RATE,
sendDefaultPii: SENTRY_SEND_DEFAULT_PII,
tracesSampleRate: SENTRY_TRACES_SAMPLE_RATE,
// tracesSampler takes precedence over tracesSampleRate; the sampler falls back to
// SENTRY_TRACES_SAMPLE_RATE for everything that isn't in ALWAYS_SAMPLE_PATHS.
tracesSampler: publishAwareTracesSampler,
profileLifecycle: SENTRY_PROFILE_LIFECYCLE,
enableLogs: SENTRY_ENABLE_LOGS,
spotlight: process.env.NODE_ENV !== 'production',
Expand Down
Loading