Skip to content
Draft
Changes from all 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
22 changes: 22 additions & 0 deletions bd-logger/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,27 @@ impl LoggerHandle {
);
}

pub fn log_session_start(&self) {
let fields = [
(
"_sdk_version".into(),
AnnotatedLogField::new_ootb(self.sdk_version.to_string()),
),
]
.into();

self.log(
log_level::INFO,
LogType::Lifecycle,
"SessionStarted".into(),
fields,
[].into(),
None,
Block::No,
CaptureSession::default(),
);
}

#[must_use]
pub fn should_log_app_update(
&self,
Expand Down Expand Up @@ -430,6 +451,7 @@ impl LoggerHandle {
LOGGER_GUARD.with(|cell| {
if cell.try_borrow().is_ok() {
self.session_strategy.start_new_session();
self.log_session_start();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only covers the case when a new session explicitly is started via the https://docs.bitdrift.io/sdk/features.html#generating-new-session-id call, we probably want this to also include the other ways in which a session is automatically started like on process start or activity expiration?

For the session metric we already emit I did this deep into the workflow engine as it already monitors for session change, but logging from there is a bit tricky so we probably need to think a bit about how it should work https://github.com/bitdriftlabs/shared-core/blob/main/bd-workflows/src/engine.rs#L504-L535

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the heads up, I was wondering about the rest as well. I see being useful where there is no new cold launch but def want to include for all session creation cases. Will investigate and report back

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be done inside bd-session module?

} else {
log::warn!(
"failed to start a new session, the operation is not allowed from within a field \
Expand Down
Loading