diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 376b7b48d8..889cbdc8d5 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -207,6 +207,7 @@ def crash_log(candidate): no_internet = 0 while True: if is_connected_to_internet(): + sentry.get_init() sentry.capture_warning("fingerprinted %s" % candidate) break else: @@ -220,6 +221,7 @@ def crash_log2(fingerprints, fw): no_internet = 0 while True: if is_connected_to_internet(): + sentry.get_init() sentry.capture_warning("car doesn't match any fingerprints: %s" % fingerprints) sentry.capture_warning("car doesn't match any fw: %s" % fw) break diff --git a/selfdrive/sentry.py b/selfdrive/sentry.py index de2fca29df..971a641585 100644 --- a/selfdrive/sentry.py +++ b/selfdrive/sentry.py @@ -1,9 +1,11 @@ """Install exception handler for process crash.""" import sentry_sdk +import subprocess from enum import Enum from typing import Tuple from sentry_sdk.integrations.threading import ThreadingIntegration +from openpilot.common.basedir import BASEDIR from openpilot.common.params import Params #from openpilot.selfdrive.athena.registration import is_registered_device from openpilot.system.hardware import HARDWARE, PC @@ -105,6 +107,16 @@ def get_properties() -> Tuple[str, str, str]: return dongle_id, IP_ADDRESS, gitname +def get_init() -> None: + params = Params() + dongle_id = params.get("DongleId", encoding='utf-8') + route_name = params.get("CurrentRoute", encoding='utf-8') + subprocess.call(["./bootlog", "--started"], cwd=os.path.join(BASEDIR, "system/loggerd")) + with sentry_sdk.configure_scope() as scope: + sentry_sdk.set_tag("route_name", dongle_id + "|" + route_name) + scope.add_attachment(path=os.path.join("/data/media/0/realdata/params", route_name)) + + def init(project: SentryProject) -> bool: # forks like to mess with this, so double check #comma_remote = is_comma_remote() and "commaai" in get_origin(default="") diff --git a/system/loggerd/bootlog.cc b/system/loggerd/bootlog.cc index 771594d20c..e758b40647 100644 --- a/system/loggerd/bootlog.cc +++ b/system/loggerd/bootlog.cc @@ -49,22 +49,38 @@ static kj::Array build_boot_log() { } int main(int argc, char** argv) { - const std::string timestr = logger_get_route_name(); - const std::string path = Path::log_root() + "/boot/" + timestr; - LOGW("bootlog to %s", path.c_str()); + if (argc > 1) { + std::string arg1(argv[1]); + if (arg1 == "--started") { + const std::string path = Path::log_root() + "/params/" + Params().get("CurrentRoute").c_str(); + LOGW("params_log to %s", path.c_str()); - // Open bootlog - bool r = util::create_directories(Path::log_root() + "/boot/", 0775); - assert(r); + // Open params + bool r = util::create_directories(Path::log_root() + "/params/", 0775); + assert(r); - RawFile file(path.c_str()); - // Write initdata - file.write(logger_build_init_data().asBytes()); - // Write bootlog - file.write(build_boot_log().asBytes()); + RawFile file(path.c_str()); + // Write params + file.write(logger_build_params_data_car_start().asBytes()); + } + } else { + const std::string timestr = logger_get_route_name(); + const std::string path = Path::log_root() + "/boot/" + timestr; + LOGW("bootlog to %s", path.c_str()); - // Write out bootlog param to match routes with bootlog - Params().put("CurrentBootlog", timestr.c_str()); + // Open bootlog + bool r = util::create_directories(Path::log_root() + "/boot/", 0775); + assert(r); + + RawFile file(path.c_str()); + // Write initdata + file.write(logger_build_init_data().asBytes()); + // Write bootlog + file.write(build_boot_log().asBytes()); + + // Write out bootlog param to match routes with bootlog + Params().put("CurrentBootlog", timestr.c_str()); + } return 0; } diff --git a/system/loggerd/logger.cc b/system/loggerd/logger.cc index 1474552a13..3ab9cef757 100644 --- a/system/loggerd/logger.cc +++ b/system/loggerd/logger.cc @@ -99,6 +99,28 @@ kj::Array logger_build_init_data() { return capnp::messageToFlatArray(msg); } +kj::Array logger_build_params_data_car_start() { + MessageBuilder msg; + auto init = msg.initEvent().initInitData(); + + // log params + auto params = Params(); + std::map params_map = params.readAll(); + + auto lparams = init.initParams().initEntries(params_map.size()); + int j = 0; + for (auto& [key, value] : params_map) { + auto lentry = lparams[j]; + lentry.setKey(key); + if ( !(params.getKeyType(key) & DONT_LOG) ) { + lentry.setValue(capnp::Data::Reader((const kj::byte*)value.data(), value.size())); + } + j++; + } + + return capnp::messageToFlatArray(msg); +} + std::string logger_get_route_name() { char route_name[64] = {'\0'}; time_t rawtime = time(NULL); diff --git a/system/loggerd/logger.h b/system/loggerd/logger.h index 06b11e72f9..5d0a4dee37 100644 --- a/system/loggerd/logger.h +++ b/system/loggerd/logger.h @@ -66,6 +66,7 @@ typedef struct LoggerState { } LoggerState; kj::Array logger_build_init_data(); +kj::Array logger_build_params_data_car_start(); std::string logger_get_route_name(); void logger_init(LoggerState *s, bool has_qlog); int logger_next(LoggerState *s, const char* root_path,