From 7f0a5c552494020e0b21b060f3b3376540975e53 Mon Sep 17 00:00:00 2001 From: Daria Bialobrzeska Date: Fri, 13 Dec 2024 17:08:24 +0100 Subject: [PATCH] Add debug logs --- .buildkite/react-native-pipeline.yml | 2 ++ package-lock.json | 16 ++------- packages/delivery-fetch/lib/delivery.ts | 5 +++ .../NativeBugsnagPerformanceImpl.java | 36 +++++++++++++++++-- .../lib/persistence/file-based.ts | 14 +++++++- .../react-native/lib/retry-queue/directory.ts | 15 +++++++- .../lib/retry-queue/file-based.ts | 28 ++++++++++++--- 7 files changed, 94 insertions(+), 22 deletions(-) diff --git a/.buildkite/react-native-pipeline.yml b/.buildkite/react-native-pipeline.yml index 2fd319af9..597c863e9 100644 --- a/.buildkite/react-native-pipeline.yml +++ b/.buildkite/react-native-pipeline.yml @@ -117,6 +117,7 @@ steps: run: react-native-maze-runner service-ports: true command: + - features/retries.feature - --app=/app/features/fixtures/generated/old-arch/{{matrix}}/reactnative.apk - --farm=bb - --device=ANDROID_12 @@ -151,6 +152,7 @@ steps: run: react-native-maze-runner service-ports: true command: + - features/retries.feature - --app=/app/features/fixtures/generated/new-arch/{{matrix}}/reactnative.apk - --farm=bb - --device=ANDROID_12 diff --git a/package-lock.json b/package-lock.json index f116e74de..0dc5e2bdd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23993,16 +23993,6 @@ } } }, - "node_modules/react-native-file-access": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/react-native-file-access/-/react-native-file-access-3.1.0.tgz", - "integrity": "sha512-wOpfKpJ8s4Csfjcvf7H4L1EtmejM07HQpndzMRWAianLC50EsPc78iV8TQaw5yI7j18rh9fWMqpevz8f5a1rsA==", - "dev": true, - "peerDependencies": { - "react": "*", - "react-native": "*" - } - }, "node_modules/react-native-navigation": { "version": "7.37.2", "resolved": "https://registry.npmjs.org/react-native-navigation/-/react-native-navigation-7.37.2.tgz", @@ -28581,14 +28571,12 @@ "devDependencies": { "@react-native-community/netinfo": "^9.4.1", "@types/react": "^18.2.24", - "metro-react-native-babel-preset": "^0.77.0", - "react-native-file-access": ">=1.7.1 <4.0.0" + "metro-react-native-babel-preset": "^0.77.0" }, "peerDependencies": { "@react-native-community/netinfo": ">= 9.4.1", "react": "*", - "react-native": "*", - "react-native-file-access": ">=1.7.1 <4.0.0" + "react-native": "*" } }, "packages/plugin-react-native-navigation": { diff --git a/packages/delivery-fetch/lib/delivery.ts b/packages/delivery-fetch/lib/delivery.ts index 69a638b27..f81b6c84d 100644 --- a/packages/delivery-fetch/lib/delivery.ts +++ b/packages/delivery-fetch/lib/delivery.ts @@ -41,9 +41,11 @@ function createFetchDeliveryFactory ( } return function fetchDeliveryFactory (endpoint: string): Delivery { + console.log('[BUGSNAG-PERF] fetchDeliveryFactory start') return { async send (payload: TracePayload) { const body = JSON.stringify(payload.body) + console.log('[BUGSNAG-PERF] fetchDeliveryFactory json payload', body) payload.headers['Bugsnag-Sent-At'] = clock.date().toISOString() @@ -55,11 +57,14 @@ function createFetchDeliveryFactory ( headers: payload.headers }) + console.log('[BUGSNAG-PERF] fetchDeliveryFactory got response', response) + return { state: responseStateFromStatusCode(response.status), samplingProbability: samplingProbabilityFromHeaders(response.headers) } } catch (err) { + console.log('[BUGSNAG-PERF] fetchDeliveryFactory error', err) if (body.length > 10e5) { return { state: 'failure-discard' } } diff --git a/packages/platforms/react-native/android/src/main/java/com/bugsnag/android/performance/NativeBugsnagPerformanceImpl.java b/packages/platforms/react-native/android/src/main/java/com/bugsnag/android/performance/NativeBugsnagPerformanceImpl.java index 2c89f5b16..0c6ab5b6e 100644 --- a/packages/platforms/react-native/android/src/main/java/com/bugsnag/android/performance/NativeBugsnagPerformanceImpl.java +++ b/packages/platforms/react-native/android/src/main/java/com/bugsnag/android/performance/NativeBugsnagPerformanceImpl.java @@ -1,6 +1,7 @@ package com.bugsnag.reactnative.performance; import android.content.Context; +import android.util.Log; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; @@ -23,6 +24,7 @@ class NativeBugsnagPerformanceImpl { static final String MODULE_NAME = "BugsnagReactNativePerformance"; + private static final String TAG = "[BUGSNAG-PERF-NATIVE]"; private final ReactApplicationContext reactContext; @@ -82,61 +84,83 @@ void requestEntropyAsync(Promise promise) { } WritableMap getNativeConstants() { + Log.w(TAG, "getNativeConstants start"); WritableMap map = Arguments.createMap(); - map.putString("CacheDir", this.reactContext.getCacheDir().getAbsolutePath()); - map.putString("DocumentDir", this.reactContext.getFilesDir().getAbsolutePath()); + + String cacheDir = this.reactContext.getCacheDir().getAbsolutePath(); + Log.w(TAG, "getNativeConstants cacheDir: " + cacheDir); + map.putString("CacheDir", cacheDir); + + String filesDir = this.reactContext.getFilesDir().getAbsolutePath(); + Log.w(TAG, "getNativeConstants filesDir: " + filesDir); + map.putString("DocumentDir", filesDir); return map; } void exists(String path, Promise promise) { + Log.w(TAG, "exists start " + path); try { boolean result = new File(path).exists(); if (result) { + Log.w(TAG, "exists true " + path); promise.resolve(result); } else { + Log.w(TAG, "exists false " + path); promise.reject(new Exception("File does not exist")); } } catch(Exception e) { + Log.w(TAG, "exists exception " + e.toString()); promise.reject(e); } } void isDir(String path, Promise promise) { + Log.w(TAG, "isDir start " + path); try { boolean result = new File(path).isDirectory(); if (result) { + Log.w(TAG, "isDir true " + path); promise.resolve(result); } else { + Log.w(TAG, "isDir false " + path); promise.reject(new Exception("Path is not a directory")); } } catch(Exception e) { + Log.w(TAG, "isDir exception " + e.toString()); promise.reject(e); } } void ls(String path, Promise promise) { + Log.w(TAG, "ls start " + path); try { promise.resolve(new File(path).list()); } catch(Exception e) { + Log.w(TAG, "ls exception " + e.toString()); promise.reject(e); } } void mkdir(String path, Promise promise) { + Log.w(TAG, "mkdir start " + path); try { boolean result = new File(path).mkdir(); if (result) { + Log.w(TAG, "mkdir true " + path); promise.resolve(path); } else { + Log.w(TAG, "mkdir false " + path); promise.reject(new Exception("Failed to create directory")); } } catch(Exception e) { + Log.w(TAG, "mkdir exception " + e.toString()); promise.reject(e); } } void readFile(String path, String encoding, Promise promise) { + Log.w(TAG, "readfile start " + path); File file = new File(path); StringBuilder fileContent = new StringBuilder((int) file.length()); try( @@ -148,26 +172,33 @@ void readFile(String path, String encoding, Promise promise) { while ((charsRead = isr.read(buffer)) != -1) { fileContent.append(buffer, 0, charsRead); } + Log.w(TAG, "readfile content " + fileContent.toString()); promise.resolve(fileContent.toString()); } catch (Exception e) { + Log.w(TAG, "readfile exception " + e.toString()); promise.reject(e); } } void unlink(String path, Promise promise) { + Log.w(TAG, "unlink start " + path); try { boolean result = new File(path).delete(); if (result) { + Log.w(TAG, "unlink true " + path); promise.resolve(null); } else { + Log.w(TAG, "unlink false " + path); promise.reject(new Exception("Failed to delete file/directory")); } } catch(Exception e) { + Log.w(TAG, "unlink exception " + e.toString()); promise.reject(e); } } void writeFile(String path, String data, String encoding, Promise promise){ + Log.w(TAG, "writeFile start " + path); try( FileOutputStream fout = new FileOutputStream(path); Writer w = new OutputStreamWriter(fout, encoding); @@ -175,6 +206,7 @@ void writeFile(String path, String data, String encoding, Promise promise){ w.write(data); promise.resolve(null); } catch (Exception e) { + Log.w(TAG, "writeFile exception " + e.toString()); promise.reject(e); } } diff --git a/packages/platforms/react-native/lib/persistence/file-based.ts b/packages/platforms/react-native/lib/persistence/file-based.ts index 7f6a7a1c6..f89e470ab 100644 --- a/packages/platforms/react-native/lib/persistence/file-based.ts +++ b/packages/platforms/react-native/lib/persistence/file-based.ts @@ -35,6 +35,7 @@ export default class FileBasedPersistence implements Persistence { } async load (key: K): Promise { + console.log('[BUGSNAG-PERF] FileBasedPersistence.load start', key) // attempt to read the native SDK's device ID file // this may not exist as the native SDK isn't necessarily installed or it // could have yet to write device ID to disk @@ -60,10 +61,12 @@ export default class FileBasedPersistence implements Persistence { : undefined } + console.log('[BUGSNAG-PERF] FileBasedPersistence.end', key) key satisfies never } async save (key: K, value: PersistencePayloadMap[K]): Promise { + console.log('[BUGSNAG-PERF] FileBasedPersistence.save start', key) this.saveQueue = this.saveQueue.then(async () => { const existing = await this.readJson() const dataToBePersisted: DataToBePersisted = {} @@ -93,26 +96,35 @@ export default class FileBasedPersistence implements Persistence { key satisfies never } + console.log('[BUGSNAG-PERF] FileBasedPersistence.save data to save', dataToBePersisted) + try { await this.file.write(JSON.stringify(dataToBePersisted)) } catch {} }) + console.log('[BUGSNAG-PERF] FileBasedPersistence.save end', key) await this.saveQueue } private async readJson (): Promise { + console.log('[BUGSNAG-PERF] FileBasedPersistence.readJSON start') try { - return JSON.parse(await this.file.read()) + const result = JSON.parse(await this.file.read()) + console.log('[BUGSNAG-PERF] FileBasedPersistence.readJSON result', result) + return result } catch (err) { return {} } } private async readDeviceIdFromNativeSdk (): Promise { + console.log('[BUGSNAG-PERF] FileBasedPersistence.readDeviceIdFromNativeSdk start') + try { const contents = await this.nativeDeviceIdFile.read() + console.log('[BUGSNAG-PERF] FileBasedPersistence.readDeviceIdFromNativeSdk contents', contents) return JSON.parse(contents)[this.nativeDeviceIdJsonKey] } catch { } diff --git a/packages/platforms/react-native/lib/retry-queue/directory.ts b/packages/platforms/react-native/lib/retry-queue/directory.ts index 6da83468f..c25d89fa6 100644 --- a/packages/platforms/react-native/lib/retry-queue/directory.ts +++ b/packages/platforms/react-native/lib/retry-queue/directory.ts @@ -48,7 +48,9 @@ export default class RetryQueueDirectory { } async files (): Promise { + console.log('[BUGSNAG-PERF] RetryQueueDirectory.files start') if (!await this.fileSystem.exists(this.path)) { + console.log('[BUGSNAG-PERF] RetryQueueDirectory.files end1') return [] } @@ -61,21 +63,28 @@ export default class RetryQueueDirectory { } files.sort(filenameSorter) + console.log('[BUGSNAG-PERF] RetryQueueDirectory.files result', files) return files } async read (name: string): Promise { + console.log('[BUGSNAG-PERF] RetryQueueDirectory.read start', name) const path = `${this.path}/${Util.basename(name)}` if (await this.fileSystem.exists(path)) { - return await this.fileSystem.readFile(path) + const result = await this.fileSystem.readFile(path) + console.log('[BUGSNAG-PERF] RetryQueueDirectory.read result', result) + return result } + console.log('[BUGSNAG-PERF] RetryQueueDirectory.read end', name) + return '' } async write (name: string, contents: string): Promise { + console.log('[BUGSNAG-PERF] RetryQueueDirectory.write start', name) await this.ensureExists() const path = `${this.path}/${Util.basename(name)}` @@ -84,14 +93,18 @@ export default class RetryQueueDirectory { } async delete (name: string): Promise { + console.log('[BUGSNAG-PERF] RetryQueueDirectory.delete start', name) + const path = `${this.path}/${Util.basename(name)}` if (await this.fileSystem.exists(path)) { + console.log('[BUGSNAG-PERF] RetryQueueDirectory.delete exists', name) await this.fileSystem.unlink(path) } } private async ensureExists (): Promise { + console.log('[BUGSNAG-PERF] RetryQueueDirectory.ensureExists start') try { await this.fileSystem.mkdir(this.path) } catch (err) { diff --git a/packages/platforms/react-native/lib/retry-queue/file-based.ts b/packages/platforms/react-native/lib/retry-queue/file-based.ts index a3e7e3f68..d0ba72b46 100644 --- a/packages/platforms/react-native/lib/retry-queue/file-based.ts +++ b/packages/platforms/react-native/lib/retry-queue/file-based.ts @@ -9,20 +9,25 @@ import type Directory from './directory' import timestampFromFilename from './timestamp-from-filename' function getLastSpan (body: DeliveryPayload): DeliverySpan | undefined { + console.log('[BUGSNAG-PERF] getLastSpan start') for (let i = body.resourceSpans.length - 1; i >= 0; i--) { const resourceSpan = body.resourceSpans[i] for (let j = resourceSpan.scopeSpans.length - 1; j >= 0; j--) { const scopeSpan = resourceSpan.scopeSpans[j] if (scopeSpan.spans.length > 0) { - return scopeSpan.spans[scopeSpan.spans.length - 1] + const result = scopeSpan.spans[scopeSpan.spans.length - 1] + console.log('[BUGSNAG-PERF] getLastSpan result', result) + return result } } } } function isValidFilename (filename: string): boolean { + console.log('[BUGSNAG-PERF] isValidFilename start', filename) // if the filename is too short then it can't be valid if (filename.length < MININUM_FILENAME_LENGTH) { + console.log('[BUGSNAG-PERF] isValidFilename false0', filename) return false } @@ -30,6 +35,7 @@ function isValidFilename (filename: string): boolean { // if we can't parse a timestamp then the filename can't be valid if (!timestamp) { + console.log('[BUGSNAG-PERF] isValidFilename false1', filename) return false } @@ -38,6 +44,7 @@ function isValidFilename (filename: string): boolean { // files that are older than 24 hours are not valid as the data may not be // relevant anymore if (timestamp < now - MILLISECONDS_IN_DAY) { + console.log('[BUGSNAG-PERF] isValidFilename false2', filename) return false } @@ -45,9 +52,10 @@ function isValidFilename (filename: string): boolean { // valid as something may have gone wrong with the clock and this is // unlikely to be a timezone issue if (timestamp > now + MILLISECONDS_IN_DAY) { + console.log('[BUGSNAG-PERF] isValidFilename false3', filename) return false } - + console.log('[BUGSNAG-PERF] isValidFilename end', filename) return true } @@ -71,9 +79,11 @@ export default class FileBasedRetryQueue implements RetryQueue { } async add (payload: TracePayload, time: number): Promise { + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.add start') const span = getLastSpan(payload.body) if (!span) { + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.add no last span') return } @@ -84,24 +94,29 @@ export default class FileBasedRetryQueue implements RetryQueue { try { const json = JSON.stringify(payload) + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.add json', json) await this.directory.write(filename, json) - } catch { + } catch (error) { + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.add exception', error) } } async flush (): Promise { + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.flush start') this.requestQueue = this.requestQueue.then(async () => { const files = await this.directory.files() for (const filename of files) { try { const outcome = await this.flushFile(filename) + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.flush outcome', outcome) if (outcome === FlushOutcome.DeleteFile) { await this.directory.delete(filename) } - } catch { + } catch (error) { + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.flush exception', error) } } }) @@ -110,17 +125,22 @@ export default class FileBasedRetryQueue implements RetryQueue { } private async flushFile (filename: string): Promise { + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.flushFile start') if (!isValidFilename(filename)) { + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.flushFile invalid filename', filename) return FlushOutcome.DeleteFile } const payload = await this.getPayloadFromFile(filename) + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.flushFile payload', payload) if (!payload) { + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.flushFile no payload', filename) return FlushOutcome.DeleteFile } const response = await this.delivery.send(payload) + console.log('[BUGSNAG-PERF] FileBasedRetryQueue.flushFile response', response) switch (response.state) { case 'success':