Skip to content
Open
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
6 changes: 5 additions & 1 deletion Cargo.Bazel.lock

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

1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ internal object CaptureJniLibrary : IBridge, IStreamingReportProcessor {
* @param applicationVersion the version of the current app, used to identify with the backend
* @param model the host device model, used to identify with the backend
* @param network the network implementation to use to communicate with the backend
* @param preferences the preferences storage to use for persistent storage of simple settings and configuration.
* @param errorReporter the error reporter to use for reporting error to bitdrift services.
* @param startInSleepMode true to initialize in sleep mode
*/
Expand All @@ -66,7 +65,6 @@ internal object CaptureJniLibrary : IBridge, IStreamingReportProcessor {
applicationVersion: String,
model: String,
network: ICaptureNetwork,
preferences: IPreferences,
errorReporter: IErrorReporter,
startInSleepMode: Boolean,
): Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ internal interface IBridge {
applicationVersion: String,
model: String,
network: ICaptureNetwork,
preferences: IPreferences,
errorReporter: IErrorReporter,
startInSleepMode: Boolean,
): Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ internal class LoggerImpl(
clientAttributes.appVersion,
deviceAttributes.model(),
network,
preferences,
localErrorReporter,
configuration.sleepMode == SleepMode.ACTIVE,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class CaptureLoggerNetworkTest {
"test",
network,
mock(),
mock(),
false,
)
CaptureJniLibrary.startLogger(logger)
Expand Down Expand Up @@ -169,7 +168,6 @@ class CaptureLoggerNetworkTest {
"test",
network,
mock(),
mock(),
false,
)
CaptureJniLibrary.startLogger(loggerId)
Expand Down Expand Up @@ -203,7 +201,6 @@ class CaptureLoggerNetworkTest {
network,
// this test fails if we pass mock() in here. It has something to do with
// jni trying to call methods on Mockito mocks.
MockPreferences(),
mock(),
false,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class ConfigurationTest {
anyOrNull(),
anyOrNull(),
anyOrNull(),
anyOrNull(),
),
).thenReturn(-1L)

Expand Down Expand Up @@ -76,7 +75,6 @@ class ConfigurationTest {
anyOrNull(),
anyOrNull(),
anyOrNull(),
anyOrNull(),
)

// We perform another attempt to configure the logger to verify that
Expand Down Expand Up @@ -105,7 +103,6 @@ class ConfigurationTest {
anyOrNull(),
anyOrNull(),
anyOrNull(),
anyOrNull(),
)
}

Expand Down
17 changes: 13 additions & 4 deletions platform/jvm/src/jni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt

use crate::events::ListenerTargetHandler as EventsListenerTargetHandler;
use crate::key_value_storage::PreferencesHandle;
use crate::resource_utilization::TargetHandler as ResourceUtilizationTargetHandler;
use crate::session::SessionStrategyConfigurationHandle;
use crate::session_replay::{self, TargetHandler as SessionReplayTargetHandler};
Expand Down Expand Up @@ -58,6 +57,8 @@ use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::{Arc, OnceLock};
use time::{Duration, OffsetDateTime};

static STORAGE_BUFFER_SIZE: usize = 1024 * 1024;

// If we are running on Android, we need to initialize the logging system to send logs to
// `android_log` instead of `stderr. Use a compile time flag to determine if we are running on
// Android to avoid setting this up in JVM tests where we want to log to stderr.
Expand Down Expand Up @@ -596,7 +597,6 @@ pub extern "system" fn Java_io_bitdrift_capture_CaptureJniLibrary_createLogger(
application_version: JString<'_>,
model: JString<'_>,
network: JObject<'_>,
preferences: JObject<'_>,
error_reporter: JObject<'_>,
start_in_sleep_mode: jboolean,
) -> jlong {
Expand All @@ -609,13 +609,22 @@ pub extern "system" fn Java_io_bitdrift_capture_CaptureJniLibrary_createLogger(
.to_string_lossy()
.to_string(),
);

// Create the SDK directory if it doesn't exist
std::fs::create_dir_all(&sdk_directory)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this required? I see it exists here but not on the iOS side?


let network_manager = Box::new(Network {
handle: new_global!(NetworkHandle, &mut env, network)?,
active_streams: Arc::new(AtomicU32::new(0)),
});

let preferences = new_global!(PreferencesHandle, &mut env, preferences)?;
let store = Arc::new(bd_key_value::Store::new(Box::new(preferences)));
let storage = Box::new(bd_key_value::resilient_kv::ResilientKvStorage::new(
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're no longer passing the storage implementation from the platform layer should we just move this initialization into builder.rs instead? That would let us unify all the setup and sequence the initialization better with the rest of the logger setup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a look, but the relationships between the various objects are surprisingly complicated here (and arranged differently in JVM vs Swift). I think this would be better done in a separate PR as it could get quite hairy...

sdk_directory.join("storage"),
STORAGE_BUFFER_SIZE,
None,
None,
)?);
let store = Arc::new(bd_key_value::Store::new(storage));
let previous_run_global_state = read_global_state_snapshot(store.clone());

let session_strategy = Arc::new(new_global!(
Expand Down
11 changes: 8 additions & 3 deletions platform/swift/source/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mod bridge_tests;

use crate::bridge::ffi::make_nsstring;
use crate::ffi::{make_empty_nsstring, nsstring_into_string};
use crate::key_value_storage::UserDefaultsStorage;
use crate::{events, ffi, resource_utilization, session_replay};
use anyhow::anyhow;
use bd_api::{Platform, PlatformNetworkManager, PlatformNetworkStream, StreamEvent};
Expand Down Expand Up @@ -51,6 +50,7 @@ use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

static STORAGE_BUFFER_SIZE: usize = 1024 * 1024;
static LOGGING_INIT: Once = Once::new();

fn initialize_logging() {
Expand Down Expand Up @@ -447,7 +447,13 @@ extern "C" fn capture_create_logger(

with_handle_unexpected_or(
|| {
let storage = Box::<UserDefaultsStorage>::default();
let path = unsafe { CStr::from_ptr(path) }.to_str()?;
let storage = Box::new(bd_key_value::resilient_kv::ResilientKvStorage::new(
format!("{path}/storage"),
STORAGE_BUFFER_SIZE,
None,
None,
)?);
let store = Arc::new(bd_key_value::Store::new(storage));
let previous_run_global_state = read_global_state_snapshot(store.clone());

Expand Down Expand Up @@ -493,7 +499,6 @@ extern "C" fn capture_create_logger(
})
};

let path = unsafe { CStr::from_ptr(path) }.to_str()?;
let logger = bd_logger::LoggerBuilder::new(bd_logger::InitParams {
sdk_directory: path.into(),
api_key: unsafe { CStr::from_ptr(api_key) }.to_str()?.to_string(),
Expand Down
3 changes: 1 addition & 2 deletions platform/swift/source/src/crash_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ fn parse_address_value(address: &Value) -> anyhow::Result<u64> {
})
.ok_or_else(|| anyhow::anyhow!("Address value is negative: {address}")),
_ => Err(anyhow::anyhow!(
"Address value is not a valid number (got {:?})",
address
"Address value is not a valid number (got {address:?})"
)),
}
}
Expand Down
1 change: 1 addition & 0 deletions test/platform/swift/bridging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version = "1.0.0"

[dependencies]
bd-bonjson = { workspace = true }
bd-bonjson-ffi = { workspace = true }
bd-client-common = { workspace = true }
bd-error-reporter = { workspace = true }
bd-key-value = { workspace = true }
Expand Down
Loading