Sentry: Log params as attachment and new tags to startup event

This commit is contained in:
Jason Wen 2023-12-09 21:34:03 +00:00
parent e13641080b
commit e143d45c21
5 changed files with 66 additions and 13 deletions

View File

@ -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

View File

@ -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="")

View File

@ -49,22 +49,38 @@ static kj::Array<capnp::word> 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;
}

View File

@ -99,6 +99,28 @@ kj::Array<capnp::word> logger_build_init_data() {
return capnp::messageToFlatArray(msg);
}
kj::Array<capnp::word> logger_build_params_data_car_start() {
MessageBuilder msg;
auto init = msg.initEvent().initInitData();
// log params
auto params = Params();
std::map<std::string, std::string> 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);

View File

@ -66,6 +66,7 @@ typedef struct LoggerState {
} LoggerState;
kj::Array<capnp::word> logger_build_init_data();
kj::Array<capnp::word> 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,