Skip to content

chore(deps): Fixes JS SDK v9 breakages #4566

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

Closed
wants to merge 9 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ protected void getSentryAndroidOptions(
if (rnOptions.hasKey("sessionTrackingIntervalMillis")) {
options.setSessionTrackingIntervalMillis(rnOptions.getInt("sessionTrackingIntervalMillis"));
}
if (rnOptions.hasKey("shutdownTimeout")) {
options.setShutdownTimeoutMillis(rnOptions.getInt("shutdownTimeout"));
}
if (rnOptions.hasKey("enableNdkScopeSync")) {
options.setEnableScopeSync(rnOptions.getBoolean("enableNdkScopeSync"));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/plugin/src/withSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface PluginProps {
const withSentryPlugin: ConfigPlugin<PluginProps | void> = (config, props) => {
const sentryProperties = getSentryProperties(props);

if (props && props.authToken) {
if (props?.authToken) {
// If not removed, the plugin config with the authToken will be written to the application package
delete props.authToken;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function withSentryAndroidGradlePlugin(
const withSentryProjectBuildGradle = (config: any): any => {
return withProjectBuildGradle(config, (projectBuildGradle: any) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (!projectBuildGradle.modResults || !projectBuildGradle.modResults.contents) {
if (!projectBuildGradle.modResults?.contents) {
warnOnce('android/build.gradle content is missing or undefined.');
return config;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/js/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type {
Breadcrumb,
Request,
RequestEventData,
SdkInfo,
Event,
Exception,
Expand Down Expand Up @@ -43,7 +43,6 @@ export {
getClient,
setCurrentClient,
addEventProcessor,
metricsDefault as metrics,
lastEventId,
} from '@sentry/core';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/integrations/debugsymbolicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function replaceExceptionFramesInException(exception: Exception, frames: SentryS
* @param frames StackFrame[]
*/
function replaceThreadFramesInEvent(event: Event, frames: SentryStackFrame[]): void {
if (event.threads && event.threads.values && event.threads.values[0] && event.threads.values[0].stacktrace) {
if (event.threads?.values && event.threads?.values[0] && event.threads?.values[0].stacktrace) {
event.threads.values[0].stacktrace.frames = frames.reverse();
}
}
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/js/integrations/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
// hasTracingEnabled from `@sentry/core` only check if tracesSampler or tracesSampleRate keys are present
// that's different from prev imp here and might lead misconfiguration
// `tracesSampleRate: undefined` should not enable tracing
const hasTracingEnabled =
options.enableTracing ||
typeof options.tracesSampleRate === 'number' ||
typeof options.tracesSampler === 'function';
const hasTracingEnabled = typeof options.tracesSampleRate === 'number' || typeof options.tracesSampler === 'function';
if (hasTracingEnabled && options.enableAppStartTracking) {
integrations.push(appStartIntegration());
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/js/integrations/nativelinkederrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const nativeLinkedErrorsIntegration = (options: Partial<LinkedErrorsOptio
};

function preprocessEvent(event: Event, hint: EventHint | undefined, client: Client, limit: number, key: string): void {
if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
if (!event.exception?.values || !hint || !isInstanceOf(hint.originalException, Error)) {
return;
}

Expand Down Expand Up @@ -176,7 +176,7 @@ function exceptionFromAppleStackReturnAddresses(objCException: {
type: objCException.name,
value: objCException.message,
stacktrace: {
frames: (nativeStackFrames && nativeStackFrames.frames.reverse()) || [],
frames: nativeStackFrames?.frames.reverse() || [],
},
},
appleDebugImages: (nativeStackFrames && (nativeStackFrames.debugMetaImages as DebugImage[])) || [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function setupErrorUtilsGlobalHandler(): void {
return;
}

const defaultHandler = errorUtils.getGlobalHandler && errorUtils.getGlobalHandler();
const defaultHandler = errorUtils.getGlobalHandler?.();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
errorUtils.setGlobalHandler(async (error: any, isFatal?: boolean) => {
Expand Down Expand Up @@ -155,7 +155,7 @@ function setupErrorUtilsGlobalHandler(): void {
return;
}

void client.flush(client.getOptions().shutdownTimeout || 2000).then(
void client.flush(2000).then(
() => {
defaultHandler(error, isFatal);
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/integrations/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const screenshotIntegration = (): Integration => {
};

async function processEvent(event: Event, hint: EventHint, client: ReactNativeClient): Promise<Event> {
const hasException = event.exception && event.exception.values && event.exception.values.length > 0;
const hasException = event.exception?.values?.length > 0;
if (!hasException || client.getOptions().beforeScreenshot?.(event, hint) === false) {
return event;
}
Expand Down
8 changes: 1 addition & 7 deletions packages/core/src/js/integrations/spotlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,5 @@ export function getDefaultSidecarUrl(): string {
function getHostnameFromString(urlString: string): string | null {
const regex = /^(?:\w+:)?\/\/([^/:]+)(:\d+)?(.*)$/;
const matches = urlString.match(regex);

if (matches && matches[1]) {
return matches[1];
} else {
// Invalid URL format
return null;
}
return matches?.[1] ?? null;
}
2 changes: 1 addition & 1 deletion packages/core/src/js/integrations/viewhierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const viewHierarchyIntegration = (): Integration => {
};

async function processEvent(event: Event, hint: EventHint): Promise<Event> {
const hasException = event.exception && event.exception.values && event.exception.values.length > 0;
const hasException = event.exception?.values?.length > 0;
if (!hasException) {
return event;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/profiling/convertHermesProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function mapStacks(
while (currentHermesFrameId !== undefined) {
const sentryFrameId = hermesStackFrameIdToSentryFrameIdMap.get(currentHermesFrameId);
sentryFrameId !== undefined && stack.push(sentryFrameId);
currentHermesFrameId = hermesStackFrames[currentHermesFrameId] && hermesStackFrames[currentHermesFrameId].parent;
currentHermesFrameId = hermesStackFrames[currentHermesFrameId]?.parent;
}
stacks.push(stack);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/profiling/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const hermesProfilingIntegration = (initOptions: HermesProfilingOptions =
}

const client = getClient<ReactNativeClient>();
const options = client && client.getOptions();
const options = client?.getOptions();

const profilesSampleRate =
options && typeof options.profilesSampleRate === 'number' ? options.profilesSampleRate : undefined;
Expand Down
42 changes: 19 additions & 23 deletions packages/core/src/js/profiling/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function enrichCombinedProfileWithEventContext(
return null;
}

const trace_id = (event.contexts && event.contexts.trace && event.contexts.trace.trace_id) || '';
const trace_id = event.contexts?.trace?.trace_id || '';

// Log a warning if the profile has an invalid traceId (should be uuidv4).
// All profiles and transactions are rejected if this is the case and we want to
Expand All @@ -97,25 +97,25 @@ export function enrichCombinedProfileWithEventContext(
release: event.release || '',
environment: event.environment || getDefaultEnvironment(),
os: {
name: (event.contexts && event.contexts.os && event.contexts.os.name) || '',
version: (event.contexts && event.contexts.os && event.contexts.os.version) || '',
build_number: (event.contexts && event.contexts.os && event.contexts.os.build) || '',
name: event.contexts?.os?.name || '',
version: event.contexts?.os?.version || '',
build_number: event.contexts?.os?.build || '',
},
device: {
locale: (event.contexts && event.contexts.device && (event.contexts.device.locale as string)) || '',
model: (event.contexts && event.contexts.device && event.contexts.device.model) || '',
manufacturer: (event.contexts && event.contexts.device && event.contexts.device.manufacturer) || '',
architecture: (event.contexts && event.contexts.device && event.contexts.device.arch) || '',
is_emulator: (event.contexts && event.contexts.device && event.contexts.device.simulator) || false,
locale: (event.contexts?.device?.locale as string) || '',
model: event.contexts?.device?.model || '',
manufacturer: event.contexts?.device?.manufacturer || '',
architecture: event.contexts?.device?.arch || '',
is_emulator: event.contexts?.device?.simulator || false,
},
transaction: {
name: event.transaction || '',
id: event.event_id || '',
trace_id,
active_thread_id: (profile.transaction && profile.transaction.active_thread_id) || '',
active_thread_id: profile.transaction?.active_thread_id || '',
},
debug_meta: {
images: [...getDebugMetadata(), ...((profile.debug_meta && profile.debug_meta.images) || [])],
images: [...getDebugMetadata(), ...(profile.debug_meta?.images || [])],
},
};
}
Expand All @@ -136,19 +136,15 @@ export function enrichAndroidProfileWithEventContext(
build_id: profile.build_id || '',

device_cpu_frequencies: [],
device_is_emulator: (event.contexts && event.contexts.device && event.contexts.device.simulator) || false,
device_locale: (event.contexts && event.contexts.device && (event.contexts.device.locale as string)) || '',
device_manufacturer: (event.contexts && event.contexts.device && event.contexts.device.manufacturer) || '',
device_model: (event.contexts && event.contexts.device && event.contexts.device.model) || '',
device_os_name: (event.contexts && event.contexts.os && event.contexts.os.name) || '',
device_os_version: (event.contexts && event.contexts.os && event.contexts.os.version) || '',
device_is_emulator: event.contexts?.device?.simulator || false,
device_locale: (event.contexts?.device?.locale as string) || '',
device_manufacturer: event.contexts?.device?.manufacturer || '',
device_model: event.contexts?.device?.model || '',
device_os_name: event.contexts?.os?.name || '',
device_os_version: event.contexts?.os?.version || '',

device_physical_memory_bytes:
(event.contexts &&
event.contexts.device &&
event.contexts.device.memory_size &&
Number(event.contexts.device.memory_size).toString(10)) ||
'',
(event.contexts?.device?.memory_size && Number(event.contexts.device.memory_size).toString(10)) || '',

environment: event.environment || getDefaultEnvironment(),

Expand All @@ -161,7 +157,7 @@ export function enrichAndroidProfileWithEventContext(

transaction_id: event.event_id || '',
transaction_name: event.transaction || '',
trace_id: (event.contexts && event.contexts.trace && event.contexts.trace.trace_id) || '',
trace_id: event.contexts?.trace?.trace_id || '',

version_name: event.release || '',
version_code: event.dist || '',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/replay/CustomMask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const UnmaskFallback = (viewProps: ViewProps): React.ReactElement => {
return <View {...viewProps} />;
};

const hasViewManagerConfig = (nativeComponentName: string): boolean => UIManager.hasViewManagerConfig && UIManager.hasViewManagerConfig(nativeComponentName);
const hasViewManagerConfig = (nativeComponentName: string): boolean => UIManager.hasViewManagerConfig?.(nativeComponentName);

const Mask = ((): HostComponent<ViewProps> | React.ComponentType<ViewProps> => {
if (!hasViewManagerConfig(MaskNativeComponentName)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/replay/mobilereplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const mobileReplayIntegration = (initOptions: MobileReplayOptions = defau
const options = { ...defaultOptions, ...initOptions };

async function processEvent(event: Event): Promise<Event> {
const hasException = event.exception && event.exception.values && event.exception.values.length > 0;
const hasException = event.exception?.values?.length > 0;
if (!hasException) {
// Event is not an error, will not capture replay
return event;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/sdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function wrap<P extends Record<string, unknown>>(
const RootApp: React.FC<P> = (appProps) => {
return (
<TouchEventBoundary {...(options?.touchEventBoundaryProps ?? {})}>
<ReactNativeProfiler {...profilerProps}>
<ReactNativeProfiler {...profilerProps} updateProps={profilerProps.updateProps ?? {}}>
<RootComponent {...appProps} />
</ReactNativeProfiler>
</TouchEventBoundary>
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/js/tools/metroconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export function withSentryBabelTransformer(
config: MetroConfig,
annotateReactComponents: true | { ignoredComponents?: string[] },
): MetroConfig {
const defaultBabelTransformerPath = config.transformer && config.transformer.babelTransformerPath;
const defaultBabelTransformerPath = config.transformer?.babelTransformerPath;
logger.debug('Default Babel transformer path from `config.transformer`:', defaultBabelTransformerPath);

if (!defaultBabelTransformerPath) {
Expand Down Expand Up @@ -270,10 +270,10 @@ export function withSentryFramesCollapsed(config: MetroConfig): MetroConfig {
originalCustomization: MetroCustomizeFrame | undefined,
): MetroCustomizeFrame => ({
...originalCustomization,
collapse: (originalCustomization && originalCustomization.collapse) || collapseSentryInternalFrames(frame),
collapse: originalCustomization?.collapse || collapseSentryInternalFrames(frame),
});

const maybePromiseCustomization = (originalCustomizeFrame && originalCustomizeFrame(frame)) || undefined;
const maybePromiseCustomization = originalCustomizeFrame?.(frame) || undefined;

if (maybePromiseCustomization !== undefined && 'then' in maybePromiseCustomization) {
return maybePromiseCustomization.then<MetroCustomizeFrame>(originalCustomization =>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/tracing/integrations/appStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export const appStartIntegration = ({
return;
}

if (!event.contexts || !event.contexts.trace) {
if (!event.contexts?.trace) {
logger.warn('[AppStart] Transaction event is missing trace context. Can not attach app start.');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/tracing/onSpanEndUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const cancelInBackground = (client: Client, span: Span): void => {
client.on('spanEnd', (endedSpan: Span) => {
if (endedSpan === span) {
logger.debug(`Removing AppState listener for ${spanToJSON(span).op} transaction.`);
subscription && subscription.remove && subscription.remove();
subscription?.remove?.();
}
});
};
2 changes: 1 addition & 1 deletion packages/core/src/js/tracing/reactnativenavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const reactNativeNavigationIntegration = ({
}

latestNavigationSpan = startGenericIdleNavigationSpan(
tracing && tracing.options.beforeStartSpan
tracing?.options.beforeStartSpan
? tracing.options.beforeStartSpan(getDefaultIdleNavigationSpanOptions())
: getDefaultIdleNavigationSpanOptions(),
idleSpanOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/tracing/reactnativeprofiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ReactNativeProfiler extends Profiler {
return;
}

client.addIntegration && client.addIntegration(createIntegration(this.name));
client.addIntegration?.(createIntegration(this.name));
// eslint-disable-next-line @typescript-eslint/no-floating-promises
_captureAppStart({ isManual: false });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/tracing/reactnavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const reactNavigationIntegration = ({
}

latestNavigationSpan = startGenericIdleNavigationSpan(
tracing && tracing.options.beforeStartSpan
tracing?.options.beforeStartSpan
? tracing.options.beforeStartSpan(getDefaultIdleNavigationSpanOptions())
: getDefaultIdleNavigationSpanOptions(),
idleSpanOptions,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/js/tracing/span.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Client, Scope, Span, StartSpanOptions } from '@sentry/core';
import {
generatePropagationContext,
generateTraceId,
getActiveSpan,
getClient,
getCurrentScope,
Expand Down Expand Up @@ -104,7 +104,7 @@ export const startIdleSpan = (
return new SentryNonRecordingSpan();
}

getCurrentScope().setPropagationContext(generatePropagationContext());
getCurrentScope().setPropagationContext({ traceId: generateTraceId(), sampleRand: Math.random() });

const span = coreStartIdleSpan(startSpanOption, { finalTimeout, idleTimeout });
cancelInBackground(client, span);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/transports/encodePolyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const useEncodePolyfill = (): void => {
(RN_GLOBAL_OBJ.__SENTRY__ as Partial<(typeof RN_GLOBAL_OBJ)['__SENTRY__']>) = {};
}

RN_GLOBAL_OBJ.__SENTRY__.encodePolyfill = encodePolyfill;
// RN_GLOBAL_OBJ.__SENTRY__.encodePolyfill = encodePolyfill; // TODO: Recheck this line
};

export const encodePolyfill = (text: string): Uint8Array => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/utils/AsyncExpiringMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class AsyncExpiringMap<K, V> {
*/
public ttl(key: K): number | undefined {
const entry = this._map.get(key);
if (entry && entry.expiresAt) {
if (entry?.expiresAt) {
const remainingTime = entry.expiresAt - Date.now();
return remainingTime > 0 ? remainingTime : 0;
}
Expand Down
13 changes: 6 additions & 7 deletions packages/core/src/js/utils/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ export function createUserFeedbackEnvelope(
const headers: EventEnvelope[0] = {
event_id: feedback.event_id,
sent_at: new Date().toISOString(),
...(metadata &&
metadata.sdk && {
sdk: {
name: metadata.sdk.name,
version: metadata.sdk.version,
},
}),
...(metadata?.sdk && {
sdk: {
name: metadata.sdk.name,
version: metadata.sdk.version,
},
}),
...(!!tunnel && !!dsn && { dsn: dsnToString(dsn) }),
};
const item = createUserFeedbackEnvelopeItem(feedback);
Expand Down
Loading
Loading