aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/zenserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenserver/zenserver.cpp')
-rw-r--r--src/zenserver/zenserver.cpp80
1 files changed, 72 insertions, 8 deletions
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 087b40d6a..6bf22eef8 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -13,6 +13,7 @@
#include <zencore/iobuffer.h>
#include <zencore/jobqueue.h>
#include <zencore/logging.h>
+#include <zencore/logging/broadcastsink.h>
#include <zencore/memory/fmalloc.h>
#include <zencore/scopeguard.h>
#include <zencore/sentryintegration.h>
@@ -28,6 +29,9 @@
#include <zenhttp/security/passwordsecurityfilter.h>
#include <zentelemetry/otlptrace.h>
#include <zenutil/authutils.h>
+#include <zenutil/config/commandlineoptions.h>
+#include <zenutil/invocationhistory.h>
+#include <zenutil/logging.h>
#include <zenutil/service.h>
#include <zenutil/workerpools.h>
#include <zenutil/zenserverprocess.h>
@@ -64,6 +68,9 @@ ZEN_THIRD_PARTY_INCLUDES_END
#include "config/config.h"
#include "diag/logging.h"
+#include "sessions/httpsessions.h"
+#include "sessions/inprocsessionlogsink.h"
+#include "sessions/sessions.h"
#include <zencore/memory/llm.h>
@@ -225,6 +232,8 @@ ZenServerBase::Initialize(const ZenServerConfig& ServerOptions, ZenServerState::
LogSettingsSummary(ServerOptions);
+ InitializeSessions();
+
return EffectiveBasePort;
}
@@ -233,6 +242,11 @@ ZenServerBase::Finalize()
{
m_StatsService.RegisterHandler("http", *m_Http);
+ if (m_HttpSessionsService)
+ {
+ m_Http->RegisterService(*m_HttpSessionsService);
+ }
+
m_Http->SetDefaultRedirect("/dashboard/");
// Register health service last so if we return "OK" for health it means all services have been properly initialized
@@ -243,11 +257,49 @@ ZenServerBase::Finalize()
void
ZenServerBase::ShutdownServices()
{
- m_StatsService.UnregisterHandler("http", *m_Http);
+ if (m_InProcSessionLogSink)
+ {
+ GetDefaultBroadcastSink()->RemoveSink(m_InProcSessionLogSink);
+ m_InProcSessionLogSink = {};
+ }
+
+ if (m_SessionsService)
+ {
+ m_SessionsService->RemoveSession(GetSessionId());
+ }
+
+ m_HttpSessionsService.reset();
+ m_SessionsService.reset();
+
+ if (m_Http)
+ {
+ m_StatsService.UnregisterHandler("http", *m_Http);
+ }
m_StatsService.Shutdown();
}
void
+ZenServerBase::InitializeSessions()
+{
+ m_SessionsService = std::make_unique<SessionsService>();
+ m_HttpSessionsService = std::make_unique<HttpSessionsService>(m_StatusService, m_StatsService, *m_SessionsService, m_IoContext);
+ m_HttpSessionsService->SetSelfSessionId(GetSessionId());
+
+ m_InProcSessionLogSink = logging::SinkPtr(new InProcSessionLogSink(*m_SessionsService));
+ m_InProcSessionLogSink->SetLevel(logging::Info);
+ GetDefaultBroadcastSink()->AddSink(m_InProcSessionLogSink);
+}
+
+void
+ZenServerBase::StartSelfSession(std::string_view AppName)
+{
+ if (m_SessionsService)
+ {
+ m_SessionsService->RegisterSession(GetSessionId(), std::string(AppName), GetServerMode(), Oid::Zero, {});
+ }
+}
+
+void
ZenServerBase::GetBuildOptions(StringBuilderBase& OutOptions, char Separator) const
{
ZEN_MEMSCOPE(GetZenserverTag());
@@ -614,6 +666,9 @@ ZenServerMain::Run()
zen::SetCurrentThreadName("main");
#endif
+ std::string ScrubbedCmdLine = m_ServerOptions.CommandLine;
+ ScrubSensitiveValues(ScrubbedCmdLine);
+
#if ZEN_USE_SENTRY
SentryIntegration Sentry;
@@ -621,16 +676,25 @@ ZenServerMain::Run()
{
ZEN_OTEL_SPAN("SentryInit");
- std::string SentryDatabasePath = (m_ServerOptions.DataDir / ".sentry-native").string();
- std::string SentryAttachmentPath = m_ServerOptions.LoggingConfig.AbsLogFile.string();
+ std::string SentryDatabasePath = (m_ServerOptions.DataDir / ".sentry-native").string();
+
+ std::vector<std::filesystem::path> AttachmentPaths;
+ if (!m_ServerOptions.LoggingConfig.AbsLogFile.empty())
+ {
+ AttachmentPaths.push_back(m_ServerOptions.LoggingConfig.AbsLogFile);
+ }
+ if (std::filesystem::path HistoryPath = GetInvocationHistoryPath(); !HistoryPath.empty())
+ {
+ AttachmentPaths.push_back(std::move(HistoryPath));
+ }
Sentry.Initialize({.DatabasePath = SentryDatabasePath,
- .AttachmentsPath = SentryAttachmentPath,
+ .AttachmentPaths = std::move(AttachmentPaths),
.Dsn = m_ServerOptions.SentryConfig.Dsn,
.Environment = m_ServerOptions.SentryConfig.Environment,
.AllowPII = m_ServerOptions.SentryConfig.AllowPII,
.Debug = m_ServerOptions.SentryConfig.Debug},
- m_ServerOptions.CommandLine);
+ ScrubbedCmdLine);
}
#endif
@@ -699,7 +763,7 @@ ZenServerMain::Run()
// The entry's process failed to pick up our sponsor request after
// multiple attempts. Before reclaiming the entry, verify that the
// PID does not still belong to a zenserver process. If it does, the
- // server is alive but unresponsive – fall back to the original error
+ // server is alive but unresponsive - fall back to the original error
// path. If the PID is gone or belongs to a different executable the
// entry is genuinely stale and safe to reclaim.
const int StalePid = Entry->Pid.load();
@@ -717,7 +781,7 @@ ZenServerMain::Run()
}
ZEN_CONSOLE_WARN(
"Failed to add sponsor to process on port {} (pid {}); "
- "pid belongs to '{}' – assuming stale entry and reclaiming",
+ "pid belongs to '{}' - assuming stale entry and reclaiming",
m_ServerOptions.BasePort,
StalePid,
ExeEc ? "<unknown>" : PidExePath.filename().string());
@@ -762,7 +826,7 @@ ZenServerMain::Run()
InitializeLogging();
- ZEN_INFO("Command line: {}", m_ServerOptions.CommandLine);
+ ZEN_INFO("Command line: {}", ScrubbedCmdLine);
#if ZEN_USE_SENTRY
Sentry.LogStartupInformation();