Skip to content

[Issue Reporter Hook] Emit callback with issue report details#414

Draft
FranAguilera wants to merge 6 commits intomainfrom
franjam/issue-reporter-crash-hook
Draft

[Issue Reporter Hook] Emit callback with issue report details#414
FranAguilera wants to merge 6 commits intomainfrom
franjam/issue-reporter-crash-hook

Conversation

@FranAguilera
Copy link
Contributor

@FranAguilera FranAguilera commented Mar 5, 2026

What

TBF

Tech spec doc

Verification

Wired in this PR bitdriftlabs/capture-sdk#904

@FranAguilera FranAguilera marked this pull request as draft March 5, 2026 15:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a crash/issue-report hook API so SDK consumers can inspect crash report details before upload and optionally attach additional log fields, plus adds a shared helper for identifying SDK-reserved (“core”) field names.

Changes:

  • Added CrashReportHook / CrashReportInfo in bd-crash-handler and plumbed an optional hook through Monitor to merge returned fields into the emitted crash log.
  • Added with_crash_report_hook to bd-logger::LoggerBuilder to wire the hook into crash monitoring.
  • Added bd-metadata::is_core_field and a CORE_FIELDS list for reserved field name detection.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
bd-metadata/src/lib.rs Adds CORE_FIELDS + is_core_field helper for reserved/core field detection.
bd-logger/src/builder.rs Adds builder plumbing to accept an optional crash report hook and pass it into Monitor.
bd-crash-handler/src/lib.rs Defines the hook API, stores the hook in Monitor, invokes it during report processing, and merges returned fields.
bd-crash-handler/src/monitor_test.rs Updates test setup to pass the newly-added hook parameter.
bd-crash-handler/src/file_watcher.rs Removes an extraneous blank line (no functional change).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bitdriftlabs bitdriftlabs deleted a comment from Copilot AI Mar 9, 2026
@bitdriftlabs bitdriftlabs deleted a comment from Copilot AI Mar 9, 2026
@bitdriftlabs bitdriftlabs deleted a comment from Copilot AI Mar 9, 2026
@bitdriftlabs bitdriftlabs deleted a comment from Copilot AI Mar 9, 2026
@bitdriftlabs bitdriftlabs deleted a comment from Copilot AI Mar 9, 2026
@bitdriftlabs bitdriftlabs deleted a comment from Copilot AI Mar 9, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +85 to +113
// SDK-internal ("core") field names that should not be exposed as custom fields.
// Fields prefixed with "_" are also considered core fields.
// See https://docs.bitdrift.io/sdk/features-fields.html#custom-fields
const CORE_FIELDS: &[&str] = &[
"app_id",
"app_version",
"carrier",
"config_version",
"context",
"detail",
"device_id",
"foreground",
"log_level",
"model",
"network_type",
"os",
"os_version",
"platform",
"radio_type",
"reason",
"report_type",
"sdk_version",
"session_id",
];

#[must_use]
pub fn is_core_field(field: &str) -> bool {
field.starts_with('_') || CORE_FIELDS.contains(&field)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

good point bot, should we reuse?

Comment on lines +136 to +138
/// Sets a hook that is invoked before each crash report is sent. The hook can inspect
/// the report and return additional log fields. A timeout is enforced to prevent blocking.
#[must_use]
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The docstring says "A timeout is enforced to prevent blocking", but the hook is passed through to bd_crash_handler::Monitor and invoked synchronously without any timeout protection. Either implement an actual timeout (e.g., call the hook in a dedicated task/thread and bound wait time) or adjust the documentation to match the current behavior.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Still talks about a timeout here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, updating in sec

Comment on lines +568 to 569
fields.extend(hook_fields);

Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

Because crash log field annotation happens later by marking all fields as LogFieldKind::Ootb, any hook-supplied fields added here will also be treated as OOTB. If the hook is meant for user/custom fields, consider plumbing hook fields through as AnnotatedLogFields (or otherwise tagging them as Custom) so they don't get misclassified.

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +138
/// Sets a hook that is invoked before each crash report is sent. The hook can inspect
/// the report and return additional log fields. A timeout is enforced to prevent blocking.
#[must_use]
Copy link
Contributor

Choose a reason for hiding this comment

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

Still talks about a timeout here

Comment on lines +85 to +113
// SDK-internal ("core") field names that should not be exposed as custom fields.
// Fields prefixed with "_" are also considered core fields.
// See https://docs.bitdrift.io/sdk/features-fields.html#custom-fields
const CORE_FIELDS: &[&str] = &[
"app_id",
"app_version",
"carrier",
"config_version",
"context",
"detail",
"device_id",
"foreground",
"log_level",
"model",
"network_type",
"os",
"os_version",
"platform",
"radio_type",
"reason",
"report_type",
"sdk_version",
"session_id",
];

#[must_use]
pub fn is_core_field(field: &str) -> bool {
field.starts_with('_') || CORE_FIELDS.contains(&field)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

good point bot, should we reuse?

// SDK-internal ("core") field names that should not be exposed as custom fields.
// Fields prefixed with "_" are also considered core fields.
// See https://docs.bitdrift.io/sdk/features-fields.html#custom-fields
const CORE_FIELDS: &[&str] = &[
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think all of these are fields like config_version, device_id and session_id so not sure where this list came from? Why would we not expose stuff like network type and foreground via this callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the idea is to expose the custom fields that customer added only

@bitdriftlabs bitdriftlabs deleted a comment from Copilot AI Mar 9, 2026
@bitdriftlabs bitdriftlabs deleted a comment from Copilot AI Mar 9, 2026
@bitdriftlabs bitdriftlabs deleted a comment from Copilot AI Mar 9, 2026
@bitdriftlabs bitdriftlabs deleted a comment from Copilot AI Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants