Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f7ed7df
feat(core): add experimental SDK config integration
nicohrubec Nov 11, 2026
6833e61
refactor(core): limit SDK config exports to dogfooding runtimes
nicohrubec Nov 11, 2026
2dda507
refactor(vercel-edge): remove experimental SDK config export
nicohrubec Nov 11, 2026
276363a
refactor(core): serialize SDK config options only once
nicohrubec Nov 11, 2026
4e4e059
docs(core): explain SDK config serialization
nicohrubec Nov 11, 2026
d4d6e80
refactor(core): centralize SDK config option exclusions
nicohrubec Nov 11, 2026
81cdd0e
docs(core): clarify SDK config hash exclusions
nicohrubec Nov 11, 2026
bb8bd32
refactor(core): derive config hash exclusions from metadata
nicohrubec Nov 11, 2026
845d54b
refactor(core): inline SDK config option exclusions
nicohrubec Nov 11, 2026
a40fab7
docs(core): clarify instance-specific config exclusions
nicohrubec Nov 11, 2026
f53a5da
refactor(core): encode SDK config hashes as Base64
nicohrubec Nov 11, 2026
6147663
docs(core): explain serializer edge cases
nicohrubec Nov 11, 2026
9f0e7c8
refactor(core): flatten SDK config primitive serialization
nicohrubec Nov 11, 2026
78560ad
docs(core): explain primitive pass-through
nicohrubec Nov 11, 2026
1c07d88
refactor(core): reuse FNV hashing for SDK config capture
nicohrubec Nov 11, 2026
4130d5a
refactor(core): inline SDK config hash calls
nicohrubec Nov 11, 2026
847b8c8
refactor(core): return encoded strings from FNV hash utility
nicohrubec Nov 11, 2026
086b056
feat(core): capture user-set SDK option keys
nicohrubec Nov 13, 2026
1c09a73
feat(core): capture integration options in SDK config
nicohrubec Nov 13, 2026
59146e7
refactor(core): rename experimental SDK config reporting integration
nicohrubec Nov 13, 2026
a18248f
fix(core): report SDK config before early shutdown flushes
nicohrubec Nov 13, 2026
61c0d9d
feat(core): report resolved data collection options
nicohrubec Nov 13, 2026
d6b4e6d
feat(core): report runtime at config top level
nicohrubec Nov 13, 2026
5f04568
Merge develop into feat/experimental-sdk-config-integration
nicohrubec Nov 13, 2026
5f73c1f
fix(core): exclude serverName from SDK config hash
nicohrubec Nov 13, 2026
0c08353
Merge branch 'develop' into feat/experimental-sdk-config-integration
nicohrubec Nov 16, 2026
9789074
refactor(core): defer integration options reporting
nicohrubec Nov 17, 2026
1ebfe67
fix(core): preserve undefined SDK config properties
nicohrubec Nov 17, 2026
cc31fb4
Merge branch 'develop' into feat/experimental-sdk-config-integration
nicohrubec Nov 17, 2026
c94dd20
test(nextjs): expect captured user option keys
nicohrubec Nov 17, 2026
e68e4ad
test(e2e): exclude experimental config reporter from export parity
nicohrubec Nov 17, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const NODE_EXPORTS_IGNORE = [
'setOpenTelemetryContextAsyncContextStrategy',
'getDefaultIntegrationsWithoutPerformance',
'initWithoutDefaultIntegrations',
// Experimental config reporting is only exposed by selected SDKs.
'experimentalReportSdkConfigIntegration',
// Internal helper only needed within integrations (e.g. bunRuntimeMetricsIntegration)
'_INTERNAL_normalizeCollectionInterval',
// Only needed by framework SDKs that enable the managed tunnel after `init`
Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type { RequestInstrumentationOptions } from './tracing/request';
export {
captureConsoleIntegration,
extraErrorDataIntegration,
experimentalReportSdkConfigIntegration,
rewriteFramesIntegration,
consoleLoggingIntegration,
createConsolaReporter,
Expand Down
5 changes: 4 additions & 1 deletion packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Client, Integration, Options } from '@sentry/core';
import {
_INTERNAL_captureOptionsSetByUser,
consoleIntegration,
conversationIdIntegration,
dedupeIntegration,
Expand Down Expand Up @@ -94,7 +95,9 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
*
* @see {@link BrowserOptions} for documentation on configuration options.
*/
export function init(options: BrowserOptions = {}): Client | undefined {
export function init(userOptions: BrowserOptions = {}): Client | undefined {
const options = _INTERNAL_captureOptionsSetByUser(userOptions);

const shouldDisableBecauseIsBrowserExtenstion =
!options.skipBrowserExtensionCheck && checkAndWarnIfIsEmbeddedBrowserExtension();

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export {
} from './utils/spanUtils';
export { _setSpanForScope as _INTERNAL_setSpanForScope } from './utils/spanOnScope';
export { parseSampleRate } from './utils/parseSampleRate';
export { applySdkMetadata } from './utils/sdkMetadata';
export { applySdkMetadata, captureOptionsSetByUser as _INTERNAL_captureOptionsSetByUser } from './utils/sdkMetadata';
export { getTraceData } from './utils/traceData';
export { matchesTracePropagationTargets, shouldPropagateTraceForUrl } from './utils/tracePropagationTargets';
export { getTraceMetaTags } from './utils/meta';
Expand Down Expand Up @@ -167,6 +167,7 @@ export { requestDataIntegration } from './integrations/requestdata';
export { captureConsoleIntegration } from './integrations/captureconsole';
export { dedupeIntegration } from './integrations/dedupe';
export { extraErrorDataIntegration } from './integrations/extraerrordata';
export { experimentalReportSdkConfigIntegration } from './integrations/reportSdkConfig';
export { rewriteFramesIntegration } from './integrations/rewriteframes';
export { supabaseIntegration, instrumentSupabaseClient } from './integrations/supabase';
export { zodErrorsIntegration } from './integrations/zoderrors';
Expand Down
146 changes: 146 additions & 0 deletions packages/core/src/integrations/reportSdkConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import type { Client } from '../client';
import { DEBUG_BUILD } from '../debug-build';
import { defineIntegration } from '../integration';
import { _INTERNAL_flushMetricsBuffer } from '../metrics/internal';
import { count } from '../metrics/public-api';
import { Scope } from '../scope';
import type { IntegrationFn } from '../types/integration';
import { debug } from '../utils/debug-logger';
import { fnv1a32 } from '../utils/hash';
import { isPlainObject } from '../utils/is';
import { timestampInSeconds } from '../utils/time';
import { safeUnref } from '../utils/timer';

const _experimentalReportSdkConfigIntegration = (() => ({
name: 'ExperimentalReportSdkConfig',
afterAllSetup(client: Client) {
const scope = new Scope();
scope.setClient(client);
let reported = false;

const report = (): void => {
// The timer and flush hook can both request capture; only report once.
if (reported) {
return;
}

reported = true;
clearTimeout(timer);

try {
const attributes = buildConfigAttributes(client);
count('sdk.config', 1, { attributes, scope });
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
} catch (error) {
DEBUG_BUILD && debug.warn('Failed to report SDK configuration', error);
}
};

// Allow configuration to settle unless the client flushes earlier.
const timer = safeUnref(setTimeout(report, 5000));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the RFC also suggest re-sending at a slow interval for server SDKs, but I guess for the initial implementation this might not be needed.


// Close, tab hiding, and natural Node process exit trigger flushing.
client.on('flush', () => {
report();
// report() may register the first metric flusher too late for this flush,
// or run after an existing flusher. Drain explicitly to cover both cases.
_INTERNAL_flushMetricsBuffer(client);
Comment thread
nicohrubec marked this conversation as resolved.
Resolved
});
},
})) satisfies IntegrationFn;

/**
* Reports effective SDK configuration once after initialization.
*
* @experimental This integration may change or be removed without notice.
*/
export const experimentalReportSdkConfigIntegration = defineIntegration(_experimentalReportSdkConfigIntegration);

// Sort object keys recursively, preserving array order. Replace functions
// and unsupported values with fingerprints before hashing the config.
function serialize(value: unknown, ancestors = new Set<object>()): unknown {
Comment thread
nicohrubec marked this conversation as resolved.
Resolved
if (typeof value === 'function') {
return `[Function:${fnv1a32(Function.prototype.toString.call(value))}]`;
}

// initialScope extras can contain bigints or symbols; JSON throws on bigints and omits symbols.
if (typeof value === 'bigint' || typeof value === 'symbol') {
return `[${typeof value}:${fnv1a32(String(value))}]`;
}

// Pass through primitives and null unchanged.
if (value === null || typeof value !== 'object') {
return value;
}

if (value instanceof RegExp) {
return value.toString();
}

// Stop recursion if an object references itself or an ancestor.
if (ancestors.has(value)) {
return '[Circular]';
}

if (!Array.isArray(value) && !isPlainObject(value)) {
const type = String(Object.prototype.toString.call(value)).slice(8, -1);
return `[${type}:${fnv1a32(String(value))}]`;
}

const nextAncestors = new Set(ancestors).add(value);
if (Array.isArray(value)) {
return value.map(item => serialize(item, nextAncestors) ?? null);
}

const result: Record<string, unknown> = {};
for (const key of Object.keys(value).sort()) {
const item: unknown = value[key];
result[key] = item === undefined ? '[undefined]' : serialize(item, nextAncestors);
}
return result;
}

function buildConfigAttributes(client: Client): Record<string, string> {
// Integrations are reported separately; SDK metadata lives under `sdk`.
const { runtime, ...options } = Object.fromEntries(
Object.entries(client.getOptions()).filter(

@nicohrubec nicohrubec Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another interesting problem is that this will not have all resolved options no matter how late we call this, because we set options in different ways:

  1. user provided options take precedence
  2. in case a value is not provided by the user framework/runtime inits might overwrite options with defaults before constructing the client
  3. certain defaults are applied during initialization of the client
  4. certain defaults are applied locally after the client construction

1-3 will show up in getOptions but 4 does not. adding to the problem is that certain local defaults might be different depending on the context. for instance maxDepth is 3 by default, but for trpc inputs its 5. so just writing back the local defaults to the client options doesn't work for these cases, since we introduce a race condition (depending on which runs first the behavior can be different everywhere). likely we'll need a to move to a model where all the final options are resolved centrally in the client as much as possible and where we need them local defaults can be managed with integration options. these would have to be explicitly passed to the integration though (currently they are oftentimes resolved after construction of the integration where we can no longer record them).

([key]) => !['integrations', 'defaultIntegrations', '_metadata'].includes(key),
),
);

const config = {
version: 1,
sdk: client.getSdkMetadata()?.sdk,
runtime,
options: serialize({
...options,
dataCollection: client.getDataCollectionOptions(),
}) as Record<string, unknown>,
options_set_by_user: client.getSdkMetadata()?.optionsSetByUser,
integrations: client.getIntegrationNames().map(name => ({ name })),
};
Comment thread
nicohrubec marked this conversation as resolved.
Resolved

const metadata = {
timestamp: timestampInSeconds(),
release: options.release,
environment: options.environment,
dist: options.dist,
};

// Exclude reporting metadata and instance-specific defaults from config identity.
const hashExclusions = new Set(['serverName', ...Object.keys(metadata)]);

const hashInput = {
...config,
options: Object.fromEntries(Object.entries(config.options).filter(([key]) => !hashExclusions.has(key))),
};

const payload = {
...config,
...metadata,
};

return {
'sentry.sdk_config.hash': fnv1a32(JSON.stringify(hashInput)),
'sentry.sdk_config.payload': JSON.stringify(payload),
};

Check warning on line 145 in packages/core/src/integrations/reportSdkConfig.ts

View check run for this annotation

@sentry/warden / warden: security-review

SDK config metric serializes secrets from client options

`buildConfigAttributes` dumps nearly all `client.getOptions()` into `sentry.sdk_config.payload` with no redaction, so values like `transportOptions.headers`, `transportOptions.proxy` credentials, string `caCerts`, and `dsn` secrets are uploaded and stored as metric data. Deny or redact those sensitive option keys before serialize/send.
}
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Resolved
2 changes: 2 additions & 0 deletions packages/core/src/types/sdkmetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import type { SdkInfo } from './sdkinfo';

export interface SdkMetadata {
sdk?: SdkInfo;
/** Option keys explicitly supplied to the outermost init call. */
optionsSetByUser?: string[];
}
14 changes: 14 additions & 0 deletions packages/core/src/utils/hash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 32-bit FNV-1a. Keep this algorithm stable: tunnel paths must match across SDK versions.
*/
export function fnv1a32(input: string): string {
let hash = 0x811c9dc5;
for (let i = 0; i < input.length; i++) {
// eslint-disable-next-line no-bitwise
hash ^= input.charCodeAt(i);
hash = Math.imul(hash, 0x01000193);
}

// eslint-disable-next-line no-bitwise
return (hash >>> 0).toString(36);
}
20 changes: 20 additions & 0 deletions packages/core/src/utils/sdkMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import type { CoreOptions } from '../types/options';
import { SDK_VERSION } from '../utils/version';

/**
* Preserve user-provided option keys before SDK wrappers add defaults.
* @internal
*/
export function captureOptionsSetByUser<T extends Pick<CoreOptions, '_metadata'>>(options: T): T {
if (options._metadata?.optionsSetByUser) {
return options;
}

return {
...options,
_metadata: {
...options._metadata,
optionsSetByUser: Object.keys(options)
.filter(key => key !== '_metadata')
.sort(),
},
};
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
Comment thread
nicohrubec marked this conversation as resolved.
Resolved

/**
* A builder for the SDK metadata in the options for the SDK initialization.
*
Expand Down
20 changes: 2 additions & 18 deletions packages/core/src/utils/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DEBUG_BUILD } from '../debug-build';
import { escapeStringForRegex } from '../vendor/escapeStringForRegex';
import { debug } from './debug-logger';
import { dsnToString, makeDsn } from './dsn';
import { fnv1a32 } from './hash';
import { getClientTunnel, setClientTunnel } from './tunnelStore';
import { parseUrl } from './url';

Expand Down Expand Up @@ -83,7 +84,7 @@ export function applyBrowserTunnelDefaults(
export function getTunnelPath(dsn?: DsnLike): string | undefined {
const components = dsn ? makeDsn(dsn) : getClient()?.getDsn();

return components ? `/${fnv1a32(dsnToString(components)).toString(36)}` : undefined;
return components ? `/${fnv1a32(dsnToString(components))}` : undefined;
}

/**
Expand Down Expand Up @@ -290,20 +291,3 @@ function stripBasePath(pathname: string, basePath: string | undefined): string |

return pathname === base || pathname.startsWith(`${base}/`) ? pathname.slice(base.length) : undefined;
}

/**
* 32-bit FNV-1a (https://www.ietf.org/archive/id/draft-eastlake-fnv-22.html#name-fnv32-code): synchronous (the
* browser needs it in `init`) and dependency free. Changing it breaks mixed SDK versions, since browser and server
* compute the path separately.
*/
function fnv1a32(input: string): number {
let hash = 0x811c9dc5;
for (let i = 0; i < input.length; i++) {
// eslint-disable-next-line no-bitwise
hash ^= input.charCodeAt(i);
hash = Math.imul(hash, 0x01000193);
}

// eslint-disable-next-line no-bitwise
return hash >>> 0;
}
5 changes: 4 additions & 1 deletion packages/nextjs/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import type { BrowserTunnelOptions, Client, EventProcessor, Integration } from '@sentry/core';
import {
_INTERNAL_applyBrowserTunnelDefaults as applyBrowserTunnelDefaults,
_INTERNAL_captureOptionsSetByUser,
applySdkMetadata,
consoleSandbox,
getGlobalScope,
Expand Down Expand Up @@ -39,7 +40,9 @@ const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
declare const __SENTRY_TRACING__: boolean;

/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
export function init(options: BrowserOptions): Client | undefined {
export function init(userOptions: BrowserOptions): Client | undefined {
const options = _INTERNAL_captureOptionsSetByUser(userOptions);

if (!DEBUG_BUILD && options.debug) {
consoleSandbox(() => {
// TODO(v12): Remove the `webpack.treeshake` mention together with that option
Expand Down
5 changes: 4 additions & 1 deletion packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* eslint-disable import/export */
import type { Scope } from '@sentry/core';
import {
_INTERNAL_captureOptionsSetByUser,
_INTERNAL_getActiveClient,
applySdkMetadata,
debug,
Expand Down Expand Up @@ -116,12 +117,14 @@ function getCloudflareRuntimeConfig(): { runtime: { name: string } } | undefined

/** Inits the Sentry NextJS SDK on node. */
// eslint-disable-next-line complexity
export function init(options: NodeOptions): NodeClient | undefined {
export function init(userOptions: NodeOptions): NodeClient | undefined {
prepareSafeIdGeneratorContext();
if (isBuild()) {
return;
}

const options = _INTERNAL_captureOptionsSetByUser(userOptions);

if (!DEBUG_BUILD && options.debug) {
// TODO(v12): Remove the `webpack.treeshake` mention together with that option
// eslint-disable-next-line no-console
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/test/clientSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('Client init()', () => {
expect(reactInit).toHaveBeenCalledWith(
expect.objectContaining({
_metadata: {
optionsSetByUser: [],
sdk: {
name: 'sentry.javascript.nextjs',
version: expect.any(String),
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/test/serverSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('Server init()', () => {
expect(nodeInit).toHaveBeenLastCalledWith(
expect.objectContaining({
_metadata: {
optionsSetByUser: [],
sdk: {
name: 'sentry.javascript.nextjs',
version: expect.any(String),
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export {
captureConsoleIntegration,
dedupeIntegration,
extraErrorDataIntegration,
experimentalReportSdkConfigIntegration,
rewriteFramesIntegration,
startSession,
captureSession,
Expand Down
4 changes: 3 additions & 1 deletion packages/node/src/sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Integration, Options } from '@sentry/core';
import {
_INTERNAL_captureOptionsSetByUser,
_INTERNAL_warnIfClientIsActive,
applySdkMetadata,
consoleSandbox,
Expand Down Expand Up @@ -112,7 +113,7 @@ export function initWithoutDefaultIntegrations(options: NodeOptions | undefined
* Internal initialization function.
*/
function _init(
options: NodeOptions | undefined = {},
userOptions: NodeOptions | undefined = {},
getDefaultIntegrationsImpl: (options: Options) => Integration[],
): NodeClient | undefined {
// Node re-runs `--require` preloads (though not `--import` ones) on the module loader thread it
Expand All @@ -133,6 +134,7 @@ function _init(
});
}

const options = _INTERNAL_captureOptionsSetByUser(userOptions);
applySdkMetadata(options, 'node');

// Enable debug logging before the client is created, so failure modes during setup (e.g. the
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
setContext,
} from '@sentry/browser';
import type { Client } from '@sentry/core';
import { applySdkMetadata, setNormalizeStringifier } from '@sentry/core';
import { _INTERNAL_captureOptionsSetByUser, applySdkMetadata, setNormalizeStringifier } from '@sentry/core';
import { version } from 'react';
import { isSyntheticEvent } from './isSyntheticEvent';

Expand All @@ -14,7 +14,7 @@ import { isSyntheticEvent } from './isSyntheticEvent';
*/
export function init(options: BrowserOptions): Client | undefined {
const opts = {
...options,
..._INTERNAL_captureOptionsSetByUser(options),
};

applySdkMetadata(opts, 'react');
Expand Down
Loading