Skip to content
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

send device model in handshake and error reports #143

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1,652 changes: 810 additions & 842 deletions Cargo.Bazel.lock

Large diffs are not rendered by default.

368 changes: 180 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ resolver = "2"

[workspace.dependencies]
android_logger = { version = "0.14.1", default-features = false }
anyhow = "1.0.90"
anyhow = "1.0.94"
assert_matches = "1.5.0"
async-trait = "0.1.83"
bd-api = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-buffer = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-client-common = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-client-stats-store = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-device = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-grpc = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-hyper-network = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-key-value = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-log = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-log-metadata = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-log-primitives = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-logger = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-noop-network = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-proto = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-runtime = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-session = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-shutdown = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-test-helpers = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b", default-features = false }
bd-time = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "6c66f075b5a4eb1434b00fa849361bd6cd3be51b" }
bd-api = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-buffer = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-client-common = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-client-stats-store = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-device = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-grpc = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-hyper-network = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-key-value = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-log = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-log-metadata = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-log-primitives = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-logger = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-noop-network = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-proto = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-runtime = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-session = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-shutdown = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
bd-test-helpers = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0", default-features = false }
bd-time = { git = "https://github.com/bitdriftlabs/shared-core.git", rev = "c6d73cee51b319d102292e92f77b8dbdb662eff0" }
chrono = "0.4.38"
clap = { version = "4.5.20", features = ["derive", "env"] }
ctor = "0.2.8"
clap = { version = "4.5.23", features = ["derive", "env"] }
ctor = "0.2.9"
env_logger = { version = "0.11.5", default-features = false }
jni = "0.21.1"
log = { version = "0.4.22", features = ["max_level_trace", "release_max_level_info"] }
Expand All @@ -58,10 +58,10 @@ rand = "0.8.5"
rand_distr = "0.4.3"
regex = "1.11.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.132"
serde_json = "1.0.133"
tempdir = "0.3.7"
time = { version = "0.3.36", features = ["serde-well-known", "macros"] }
tokio = { version = "1.41.1", features = ["full", "test-util"] }
tracing = { version = "0.1.40", features = ["log"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
time = { version = "0.3.37", features = ["serde-well-known", "macros"] }
tokio = { version = "1.42.0", features = ["full", "test-util"] }
tracing = { version = "0.1.41", features = ["log"] }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
uuid = { version = "1.11.0", features = ["v4"] }
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ allow = [
"MIT",
"MPL-2.0",
"OpenSSL",
"Unicode-DFS-2016",
"Unicode-3.0",
]
confidence-threshold = 0.8
exceptions = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal object CaptureJniLibrary : IBridge {
* @param eventsListenerTarget responsible for listening to platform events and emitting logs in response to them.
* @param applicationId the application ID of the current app, used to identify with the backend
* @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.
Expand All @@ -60,6 +61,7 @@ internal object CaptureJniLibrary : IBridge {
eventsListenerTarget: IEventsListenerTarget,
applicationId: String,
applicationVersion: String,
model: String,
network: ICaptureNetwork,
preferences: IPreferences,
errorReporter: IErrorReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal interface IBridge {
eventsListenerTarget: IEventsListenerTarget,
applicationId: String,
applicationVersion: String,
model: String,
network: ICaptureNetwork,
preferences: IPreferences,
errorReporter: IErrorReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.annotation.SuppressLint
import android.app.ActivityManager
import android.content.Context
import android.content.pm.ApplicationInfo
import android.os.Build
import android.system.Os
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.ProcessLifecycleOwner
Expand Down Expand Up @@ -172,6 +173,7 @@ internal class LoggerImpl(
eventsListenerTarget,
clientAttributes.appId,
clientAttributes.appVersion,
Build.MODEL,
mattklein123 marked this conversation as resolved.
Show resolved Hide resolved
network,
preferences,
localErrorReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CaptureLoggerNetworkTest {
mock(),
"test",
"test",
"test",
network,
mock(),
mock(),
Expand Down Expand Up @@ -159,6 +160,7 @@ class CaptureLoggerNetworkTest {
mock(),
"test",
"test",
"test",
network,
mock(),
mock(),
Expand Down Expand Up @@ -188,6 +190,7 @@ class CaptureLoggerNetworkTest {
mock(),
"test",
"test",
"test",
network,
// this test fails if we pass mock() in here. It has something to do with
// jni trying to call methods on Mockito mocks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class CaptureLoggerTest {
"os" to "android",
"device_id" to deviceId,
"kind" to "mobile",
"model" to "robolectric",
),
listOf("sdk_version", "config_version"),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ConfigurationTest {
anyOrNull(),
anyOrNull(),
anyOrNull(),
anyOrNull(),
),
).thenReturn(-1L)

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

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

Expand Down
2 changes: 2 additions & 0 deletions platform/jvm/src/jni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ pub extern "system" fn Java_io_bitdrift_capture_CaptureJniLibrary_createLogger(
events_listener_target: JObject<'_>,
application_id: JString<'_>,
application_version: JString<'_>,
model: JString<'_>,
network: JObject<'_>,
preferences: JObject<'_>,
error_reporter: JObject<'_>,
Expand Down Expand Up @@ -633,6 +634,7 @@ pub extern "system" fn Java_io_bitdrift_capture_CaptureJniLibrary_createLogger(
app_version: Some(unsafe { env.get_string_unchecked(&application_version) }?.into()),
platform: Platform::Android,
device: device.clone(),
model: unsafe { env.get_string_unchecked(&model) }?.into(),
});

let error_reporter = Arc::new(new_global!(ErrorReporterHandle, &mut env, error_reporter)?);
Expand Down
3 changes: 3 additions & 0 deletions platform/shared/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct Mobile {

/// Provides current device installation identifier.
pub device: Arc<bd_logger::Device>,

pub model: String,
}

impl bd_api::Metadata for Mobile {
Expand All @@ -49,6 +51,7 @@ impl bd_api::Metadata for Mobile {
}

metadata_map.insert("device_id".to_string(), self.device.id());
metadata_map.insert("model".to_string(), self.model.clone());

metadata_map
}
Expand Down
16 changes: 9 additions & 7 deletions platform/swift/source/CaptureRustBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ void capture_report_error(const char *message);
* @param events_listener_target responsible for listening to platform events and emitting logs in response to them.
* @param app_id the app id to identify the client as a null terminated C string.
* @param app_version the app version to identify the client as a null terminated C string.
* @param model the model of the device to identify the client as a null terminated C string.
* @param network the Capture Network protocol to use for performing network requests.
* @param error_reporter the error reported protocol to use for reporting errors.
*/
logger_id capture_create_logger(
const char *_Nullable path,
const char *_Nullable path,
const char *api_key,
id<SessionStrategyProvider> session_strategy_provider,
id<MetadataProvider> metadata_provider,
id<ResourceUtilizationTarget> resource_utilization_target,
id<SessionReplayTarget> session_replay_target,
id<EventsListenerTarget> events_listener_target,
const char *app_id,
const char *app_version,
const char *app_version,
const char *model,
_Nullable id<Network> network,
_Nullable id<RemoteErrorReporting> error_reporter
);
Expand All @@ -68,7 +70,7 @@ void capture_start_logger(logger_id logger_id);
* remote services.
* @param matching_fields The list of matching fields that can be read when processing a given log but are
* not a part of the log itself.
* @Param blocking whether the method should return only after the log is processed.
* @Param blocking whether the method should return only after the log is processed.
*/
void capture_write_log(
logger_id logger_id,
Expand Down Expand Up @@ -167,7 +169,7 @@ void capture_write_app_update_log(
* have no effect.
*
* @param loggerId the ID of the logger to write to.
* @param duration_s the duration of time between a user's intent to launch an app and the point in time
* @param duration_s the duration of time between a user's intent to launch an app and the point in time
* when the app became interactive. Calls with a negative duration are ignored.
*/
void capture_write_app_launch_tti_log(
Expand Down Expand Up @@ -230,7 +232,7 @@ void capture_flush(logger_id logger_id, bool blocking);

/**
* Signals the specified logger to shut down.
*
*
* @param blocking whether the method should return only after shutdown is complete.
*/
void capture_shutdown_logger(logger_id logger_id, bool blocking);
Expand Down Expand Up @@ -265,11 +267,11 @@ bool capture_runtime_bool_variable_value(logger_id logger_id, const char *variab

/*
* Returns the value of an integer runtime variable via client runtime configuration.
*
*
* @param logger_id the logger to check the variable value for.
* @param variable_name the name of the int variable to check.
* @param default_value the default value to use when the relevant configuration entry is missing.
*
*
* @returns the value of the uin32_t variable.
*/
uint32_t capture_runtime_uint32_variable_value(logger_id logger_id, const char *variable_name, uint32_t default_value);
Expand Down
2 changes: 2 additions & 0 deletions platform/swift/source/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public final class Logger {
let appStateAttributes = AppStateAttributes()
let clientAttributes = ClientAttributes()
let deviceAttributes = DeviceAttributes()
let hardwareVersion = deviceAttributes.hardwareVersion
mattklein123 marked this conversation as resolved.
Show resolved Hide resolved
let networkAttributes = NetworkAttributes()
let ootbFieldProviders: [FieldProvider] = [
appStateAttributes,
Expand Down Expand Up @@ -183,6 +184,7 @@ public final class Logger {
eventsListenerTarget: self.eventsListenerTarget,
appID: clientAttributes.appID,
releaseVersion: clientAttributes.appVersion,
model: hardwareVersion,
network: network,
errorReporting: self.remoteErrorReporter
) else {
Expand Down
4 changes: 4 additions & 0 deletions platform/swift/source/LoggerBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class LoggerBridge: LoggerBridging {
eventsListenerTarget: CaptureLoggerBridge.EventsListenerTarget,
appID: String,
releaseVersion: String,
model: String,
network: Network?,
errorReporting: RemoteErrorReporting
) {
Expand All @@ -39,6 +40,7 @@ final class LoggerBridge: LoggerBridging {
eventsListenerTarget,
appID,
releaseVersion,
model,
network,
errorReporting
)
Expand Down Expand Up @@ -68,6 +70,7 @@ final class LoggerBridge: LoggerBridging {
eventsListenerTarget: CaptureLoggerBridge.EventsListenerTarget,
appID: String,
releaseVersion: String,
model: String,
network: Network?,
errorReporting: RemoteErrorReporting
) -> LoggerBridging? {
Expand All @@ -81,6 +84,7 @@ final class LoggerBridge: LoggerBridging {
eventsListenerTarget: eventsListenerTarget,
appID: appID,
releaseVersion: releaseVersion,
model: model,
network: network,
errorReporting: errorReporting
)
Expand Down
2 changes: 2 additions & 0 deletions platform/swift/source/LoggerBridgingFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class LoggerBridgingFactory: LoggerBridgingFactoryProvider {
eventsListenerTarget: CaptureLoggerBridge.EventsListenerTarget,
appID: String,
releaseVersion: String,
model: String,
network: Network?,
errorReporting: RemoteErrorReporting
) -> LoggerBridging? {
Expand All @@ -31,6 +32,7 @@ final class LoggerBridgingFactory: LoggerBridgingFactoryProvider {
eventsListenerTarget: eventsListenerTarget,
appID: appID,
releaseVersion: releaseVersion,
model: model,
network: network,
errorReporting: errorReporting
)
Expand Down
2 changes: 2 additions & 0 deletions platform/swift/source/LoggerBridgingFactoryProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protocol LoggerBridgingFactoryProvider {
/// - parameter eventsListenerTarget: The events listener target to use.
/// - parameter appID: The host application application identifier.
/// - parameter releaseVersion: The host application release version.
/// - parameter model: The host device model.
/// - parameter network: The interface to use for network operations.
/// - parameter errorReporting: The interface to use for reporting errors.
///
Expand All @@ -34,6 +35,7 @@ protocol LoggerBridgingFactoryProvider {
eventsListenerTarget: CaptureLoggerBridge.EventsListenerTarget,
appID: String,
releaseVersion: String,
model: String,
network: Network?,
errorReporting: RemoteErrorReporting
) -> LoggerBridging?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
/// Attributes related to the device information including hardware model, locale, etc.
final class DeviceAttributes {
private let locale = Atomic<String>(Locale.current.identifier)
private let hardwareVersion: String = {
let hardwareVersion: String = {
let size = UnsafeMutablePointer<Int>.allocate(capacity: 1)
sysctlbyname("hw.machine", nil, size, nil, 0)

Expand Down
2 changes: 2 additions & 0 deletions platform/swift/source/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ extern "C" fn capture_create_logger(
events_listener_target: *mut Object,
app_id: *const c_char,
app_version: *const c_char,
model: *const c_char,
bd_network_nsobject: *mut Object,
error_reporter_ns_object: *mut Object,
) -> LoggerId<'static> {
Expand All @@ -466,6 +467,7 @@ extern "C" fn capture_create_logger(
app_version: Some(unsafe { CStr::from_ptr(app_version) }.to_str()?.to_string()),
platform: Platform::Ios,
device: device.clone(),
model: unsafe { CStr::from_ptr(model) }.to_str()?.to_string(),
});

let error_reporter = MetadataErrorReporter::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ open class BaseNetworkingTestCase: XCTestCase {
eventsListenerTarget: MockEventsListenerTarget(),
appID: "io.bitdrift.capture.test",
releaseVersion: "",
model: "",
network: network,
errorReporting: MockRemoteErrorReporter()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public final class MockLoggerBridgingFactory: LoggerBridgingFactoryProvider {
eventsListenerTarget _: CaptureLoggerBridge.EventsListenerTarget,
appID _: String,
releaseVersion _: String,
model _: String,
network _: Network?,
errorReporting _: RemoteErrorReporting
) -> LoggerBridging? {
Expand Down
Loading