Skip to content

ref: Remove some usages of dropUndefinedKeys() #15781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 26 additions & 28 deletions packages/astro/src/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';
import { sentryVitePlugin } from '@sentry/vite-plugin';
import type { AstroConfig, AstroIntegration } from 'astro';

import { consoleSandbox, dropUndefinedKeys } from '@sentry/core';
import { consoleSandbox } from '@sentry/core';
import { buildClientSnippet, buildSdkInitFileImportSnippet, buildServerSnippet } from './snippets';
import type { SentryOptions } from './types';

Expand Down Expand Up @@ -62,34 +62,32 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
sourcemap: computedSourceMapSettings.updatedSourceMapSetting,
},
plugins: [
sentryVitePlugin(
dropUndefinedKeys({
org: uploadOptions.org ?? env.SENTRY_ORG,
project: uploadOptions.project ?? env.SENTRY_PROJECT,
authToken: uploadOptions.authToken ?? env.SENTRY_AUTH_TOKEN,
telemetry: uploadOptions.telemetry ?? true,
_metaOptions: {
telemetry: {
metaFramework: 'astro',
},
sentryVitePlugin({
org: uploadOptions.org ?? env.SENTRY_ORG,
project: uploadOptions.project ?? env.SENTRY_PROJECT,
authToken: uploadOptions.authToken ?? env.SENTRY_AUTH_TOKEN,
telemetry: uploadOptions.telemetry ?? true,
_metaOptions: {
telemetry: {
metaFramework: 'astro',
},
...unstable_sentryVitePluginOptions,
debug: options.debug ?? false,
sourcemaps: {
assets: uploadOptions.assets ?? [getSourcemapsAssetsGlob(config)],
filesToDeleteAfterUpload:
uploadOptions?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload,
...unstable_sentryVitePluginOptions?.sourcemaps,
},
bundleSizeOptimizations: {
...options.bundleSizeOptimizations,
// TODO: with a future version of the vite plugin (probably 2.22.0) this re-mapping is not needed anymore
// ref: https://github.com/getsentry/sentry-javascript-bundler-plugins/pull/582
excludePerformanceMonitoring: options.bundleSizeOptimizations?.excludeTracing,
...unstable_sentryVitePluginOptions?.bundleSizeOptimizations,
},
}),
),
},
...unstable_sentryVitePluginOptions,
debug: options.debug ?? false,
sourcemaps: {
assets: uploadOptions.assets ?? [getSourcemapsAssetsGlob(config)],
filesToDeleteAfterUpload:
uploadOptions?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload,
...unstable_sentryVitePluginOptions?.sourcemaps,
},
bundleSizeOptimizations: {
...options.bundleSizeOptimizations,
// TODO: with a future version of the vite plugin (probably 2.22.0) this re-mapping is not needed anymore
// ref: https://github.com/getsentry/sentry-javascript-bundler-plugins/pull/582
excludePerformanceMonitoring: options.bundleSizeOptimizations?.excludeTracing,
...unstable_sentryVitePluginOptions?.bundleSizeOptimizations,
},
}),
],
},
});
Expand Down
5 changes: 2 additions & 3 deletions packages/browser-utils/src/metrics/inp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
browserPerformanceTimeOrigin,
dropUndefinedKeys,
getActiveSpan,
getCurrentScope,
getRootSpan,
Expand Down Expand Up @@ -101,11 +100,11 @@ function _trackINP(): () => void {
const routeName = spanToUse ? spanToJSON(spanToUse).description : getCurrentScope().getScopeData().transactionName;

const name = htmlTreeAsString(entry.target);
const attributes: SpanAttributes = dropUndefinedKeys({
const attributes: SpanAttributes = {
Copy link
Member Author

Choose a reason for hiding this comment

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

nothing possibly undefined here!

[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.browser.inp',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: `ui.interaction.${interactionType}`,
[SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME]: entry.duration,
});
};

const span = startStandaloneWebVitalSpan({
name,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/checkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
} from './types-hoist';
import { dsnToString } from './utils-hoist/dsn';
import { createEnvelope } from './utils-hoist/envelope';
import { dropUndefinedKeys } from './utils-hoist/object';

/**
* Create envelope from check in item.
Expand Down Expand Up @@ -36,7 +35,7 @@ export function createCheckInEnvelope(
}

if (dynamicSamplingContext) {
headers.trace = dropUndefinedKeys(dynamicSamplingContext) as DynamicSamplingContext;
headers.trace = dynamicSamplingContext as DynamicSamplingContext;
Copy link
Member Author

Choose a reason for hiding this comment

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

this should not care if there is something undefined in there, I believe?

Copy link
Member

Choose a reason for hiding this comment

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

it should not!

}

const item = createCheckInEnvelopeItem(checkIn);
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/feedback.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getClient, getCurrentScope } from './currentScopes';
import type { EventHint, FeedbackEvent, SendFeedbackParams } from './types-hoist';
import { dropUndefinedKeys } from './utils-hoist/object';

/**
* Send user feedback to Sentry.
Expand All @@ -14,14 +13,14 @@ export function captureFeedback(

const feedbackEvent: FeedbackEvent = {
contexts: {
feedback: dropUndefinedKeys({
feedback: {
Copy link
Member Author

Choose a reason for hiding this comment

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

this should not care about undefined fields

contact_email: email,
name,
message,
url,
source,
associated_event_id: associatedEventId,
}),
},
},
type: 'feedback',
level: 'info',
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/session.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SerializedSession, Session, SessionContext, SessionStatus } from './types-hoist';
import { dropUndefinedKeys, timestampInSeconds, uuid4 } from './utils-hoist';
import { timestampInSeconds, uuid4 } from './utils-hoist';

/**
* Creates a new `Session` object by setting certain default parameters. If optional @param context
Expand Down Expand Up @@ -137,7 +137,7 @@ export function closeSession(session: Session, status?: Exclude<SessionStatus, '
* @returns a JSON object of the passed session
*/
function sessionToJSON(session: Session): SerializedSession {
return dropUndefinedKeys({
return {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is only called when we send the session, where this should be cleared out by JSON.stringify() anyhow

sid: `${session.sid}`,
init: session.init,
// Make sure that sec is converted to ms for date constructor
Expand All @@ -154,5 +154,5 @@ function sessionToJSON(session: Session): SerializedSession {
ip_address: session.ipAddress,
user_agent: session.userAgent,
},
});
};
}
2 changes: 1 addition & 1 deletion packages/core/src/tracing/dynamicSamplingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function getDynamicSamplingContextFromClient(trace_id: string, client: Cl
release: options.release,
public_key,
trace_id,
}) as DynamicSamplingContext;
}) satisfies DynamicSamplingContext;

client.emit('createDsc', dsc);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { serializeFormData } from '@sentry-internal/browser-utils';
import type { NetworkMetaWarning } from '@sentry-internal/browser-utils';
import { dropUndefinedKeys, stringMatchesSomePattern } from '@sentry/core';
import { stringMatchesSomePattern } from '@sentry/core';

import { NETWORK_BODY_MAX_SIZE, WINDOW } from '../../constants';
import type {
Expand Down Expand Up @@ -98,12 +98,12 @@ export function makeNetworkReplayBreadcrumb(
start: startTimestamp / 1000,
end: endTimestamp / 1000,
name: url,
data: dropUndefinedKeys({
data: {
Copy link
Member Author

Choose a reason for hiding this comment

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

this should be fine to contain undefined

method,
statusCode,
request,
response,
}),
},
};

return result;
Expand Down
6 changes: 3 additions & 3 deletions packages/sveltekit/src/client/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { navigating, page } from '$app/stores';
import type { Client, Integration, Span } from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, dropUndefinedKeys } from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import {
WINDOW,
browserTracingIntegration as originalBrowserTracingIntegration,
Expand Down Expand Up @@ -113,15 +113,15 @@ function _instrumentNavigations(client: Client): void {
routingSpan.end();
}

const navigationInfo = dropUndefinedKeys({
const navigationInfo = {
Copy link
Member Author

Choose a reason for hiding this comment

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

attributes can be undefined, that should not change anything.

// `navigation.type` denotes the origin of the navigation. e.g.:
// - link (clicking on a link)
// - goto (programmatic via goto() or redirect())
// - popstate (back/forward navigation)
'sentry.sveltekit.navigation.type': navigation.type,
'sentry.sveltekit.navigation.from': parameterizedRouteOrigin || undefined,
'sentry.sveltekit.navigation.to': parameterizedRouteDestination || undefined,
});
};

startBrowserTracingNavigationSpan(client, {
name: parameterizedRouteDestination || rawRouteDestination || 'unknown',
Expand Down
Loading