Skip to content

Commit

Permalink
Add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
DariaKunoichi committed Dec 13, 2024
1 parent e39bc64 commit 7f0a5c5
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .buildkite/react-native-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 2 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/delivery-fetch/lib/delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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' }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,6 +24,7 @@
class NativeBugsnagPerformanceImpl {

static final String MODULE_NAME = "BugsnagReactNativePerformance";
private static final String TAG = "[BUGSNAG-PERF-NATIVE]";

private final ReactApplicationContext reactContext;

Expand Down Expand Up @@ -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(
Expand All @@ -148,33 +172,41 @@ 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);
) {
w.write(data);
promise.resolve(null);
} catch (Exception e) {
Log.w(TAG, "writeFile exception " + e.toString());
promise.reject(e);
}
}
Expand Down
14 changes: 13 additions & 1 deletion packages/platforms/react-native/lib/persistence/file-based.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default class FileBasedPersistence implements Persistence {
}

async load<K extends PersistenceKey> (key: K): Promise<PersistencePayloadMap[K] | undefined> {
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
Expand All @@ -60,10 +61,12 @@ export default class FileBasedPersistence implements Persistence {
: undefined
}

console.log('[BUGSNAG-PERF] FileBasedPersistence.end', key)
key satisfies never
}

async save<K extends PersistenceKey> (key: K, value: PersistencePayloadMap[K]): Promise<void> {
console.log('[BUGSNAG-PERF] FileBasedPersistence.save start', key)
this.saveQueue = this.saveQueue.then(async () => {
const existing = await this.readJson()
const dataToBePersisted: DataToBePersisted = {}
Expand Down Expand Up @@ -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<PersistedData> {
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<string | undefined> {
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 {
}
Expand Down
15 changes: 14 additions & 1 deletion packages/platforms/react-native/lib/retry-queue/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default class RetryQueueDirectory {
}

async files (): Promise<string[]> {
console.log('[BUGSNAG-PERF] RetryQueueDirectory.files start')
if (!await this.fileSystem.exists(this.path)) {
console.log('[BUGSNAG-PERF] RetryQueueDirectory.files end1')
return []
}

Expand All @@ -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<string> {
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<void> {
console.log('[BUGSNAG-PERF] RetryQueueDirectory.write start', name)
await this.ensureExists()

const path = `${this.path}/${Util.basename(name)}`
Expand All @@ -84,14 +93,18 @@ export default class RetryQueueDirectory {
}

async delete (name: string): Promise<void> {
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<void> {
console.log('[BUGSNAG-PERF] RetryQueueDirectory.ensureExists start')
try {
await this.fileSystem.mkdir(this.path)
} catch (err) {
Expand Down
Loading

0 comments on commit 7f0a5c5

Please sign in to comment.