#include "start.h" #include "all.h" #include #include #include #include #include #include using namespace NLWTrace; namespace { struct TTraceManagerHolder { TManager TraceManager; TTraceManagerHolder() : TraceManager(*Singleton(), true) { } }; void TraceFromEnv(TString path) { TString script = TUnbufferedFileInput(path).ReadAll(); TQuery query; bool ok = google::protobuf::TextFormat::ParseFromString(script, &query); Y_ABORT_UNLESS(ok, "failed to parse protobuf"); Singleton()->TraceManager.New("env", query); } } // anonymous namespace void NLWTrace::StartLwtraceFromEnv() { static bool started = false; if (started) { return; } else { started = true; } TString path = GetEnv("LWTRACE"); if (!path) { return; } try { TraceFromEnv(path); } catch (...) { Cerr << "failed to load lwtrace script: " << CurrentExceptionMessage() << "\n"; abort(); } } void NLWTrace::StartLwtraceFromEnv(std::function prepare) { TString path = GetEnv("LWTRACE"); if (Y_LIKELY(!path)) { return; } try { prepare(Singleton()->TraceManager); TraceFromEnv(path); } catch (...) { Cerr << "failed to load lwtrace script: " << CurrentExceptionMessage() << "\n"; abort(); } }