Skip to main content

rpfm_telemetry/
feedback.rs

1//---------------------------------------------------------------------------//
2// Copyright (c) 2017-2026 Ismael Gutiérrez González. All rights reserved.
3//
4// This file is part of the Rusted PackFile Manager (RPFM) project,
5// which can be found here: https://github.com/Frodo45127/rpfm.
6//
7// This file is licensed under the MIT license, which can be found here:
8// https://github.com/Frodo45127/rpfm/blob/master/LICENSE.
9//---------------------------------------------------------------------------//
10
11//! User feedback capture, posted to Sentry as a tagged event.
12//!
13//! The Sentry Rust SDK (v0.47) does not expose Sentry's dedicated User
14//! Feedback envelope item, so feedback is sent as a regular `Level::Info`
15//! event with a `rpfm.kind=user_feedback` tag and the user's text in
16//! `extra.feedback`. The tag lets the [`crate::logger`] `before_send` hook
17//! tell feedback apart from telemetry and crash reports, and lets you filter
18//! for it in the Sentry UI.
19
20use crate::actions::TELEMETRY_EVENT_TAG;
21use crate::info;
22use crate::logger::{sentry, Event, Level};
23
24/// `rpfm.kind` tag value attached to user-feedback events.
25pub(crate) const FEEDBACK_EVENT_VALUE: &str = "user_feedback";
26
27/// Captures a single user-feedback message and ships it to Sentry.
28///
29/// The event is tagged so the logger's `before_send` filter lets it through
30/// unconditionally. The user just clicked Send: that is consent in the
31/// moment, regardless of the telemetry/crash-report toggles.
32///
33/// # Arguments
34///
35/// * `message` - The free-form text the user typed in the feedback dialog.
36pub fn send_user_feedback(message: &str) {
37    info!("Sending user feedback ({} chars)...", message.len());
38
39    let mut event = Event::new();
40    event.level = Level::Info;
41    event.message = Some("User Feedback".to_string());
42    event.tags.insert(TELEMETRY_EVENT_TAG.to_string(), FEEDBACK_EVENT_VALUE.to_string());
43    event.extra.insert(
44        "feedback".to_string(),
45        sentry::protocol::Value::from(message.to_string()),
46    );
47
48    sentry::capture_event(event);
49}