Audacity 3.2.0
Classes | Functions
audacity::sentry::anonymous_namespace{SentryReport.cpp} Namespace Reference

Classes

class  ExceptionContext
 Helper class to store additional details about the exception. More...
 

Functions

void AddOSContext (rapidjson::Value &root, rapidjson::Document::AllocatorType &allocator)
 Append the data about the operating system to the JSON document. More...
 
rapidjson::Document CreateSentryDocument ()
 Create the minimal required Sentry JSON document. More...
 
void AddExceptionDataToJson (rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator, const ExceptionData &data)
 Append the ExceptionData to the Exception JSON object. More...
 
void SerializeException (const Exception &exception, rapidjson::Value &root, rapidjson::Document::AllocatorType &allocator)
 Serialize the Exception to JSON. More...
 

Function Documentation

◆ AddExceptionDataToJson()

void audacity::sentry::anonymous_namespace{SentryReport.cpp}::AddExceptionDataToJson ( rapidjson::Value &  value,
rapidjson::Document::AllocatorType &  allocator,
const ExceptionData data 
)

Append the ExceptionData to the Exception JSON object.

Definition at line 169 of file SentryReport.cpp.

172{
173 value.AddMember(
174 rapidjson::Value(data.first.c_str(), data.first.length(), allocator),
175 rapidjson::Value(data.second.c_str(), data.second.length(), allocator),
176 allocator);
177}

Referenced by SerializeException().

Here is the caller graph for this function:

◆ AddOSContext()

void audacity::sentry::anonymous_namespace{SentryReport.cpp}::AddOSContext ( rapidjson::Value &  root,
rapidjson::Document::AllocatorType &  allocator 
)

Append the data about the operating system to the JSON document.

Definition at line 86 of file SentryReport.cpp.

88{
89 rapidjson::Value osContext(rapidjson::kObjectType);
90
91 const wxPlatformInfo platformInfo = wxPlatformInfo::Get();
92
93 const std::string osName =
94 ToUTF8(platformInfo.GetOperatingSystemFamilyName());
95
96 osContext.AddMember("type", rapidjson::Value("os", allocator), allocator);
97
98 osContext.AddMember(
99 "name", rapidjson::Value(osName.c_str(), osName.length(), allocator),
100 allocator);
101
102 const std::string osVersion =
103 std::to_string(platformInfo.GetOSMajorVersion()) + "." +
104 std::to_string(platformInfo.GetOSMinorVersion()) + "." +
105 std::to_string(platformInfo.GetOSMicroVersion());
106
107 osContext.AddMember(
108 "version",
109 rapidjson::Value(osVersion.c_str(), osVersion.length(), allocator),
110 allocator);
111
112 root.AddMember("os", std::move(osContext), allocator);
113}
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
std::string ToUTF8(const std::wstring &wstr)

References BasicUI::Get(), and audacity::ToUTF8().

Referenced by CreateSentryDocument().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateSentryDocument()

rapidjson::Document audacity::sentry::anonymous_namespace{SentryReport.cpp}::CreateSentryDocument ( )

Create the minimal required Sentry JSON document.

Definition at line 116 of file SentryReport.cpp.

117{
118 using namespace std::chrono;
119 rapidjson::Document document;
120
121 document.SetObject();
122
123 document.AddMember(
124 "timestamp",
125 rapidjson::Value(
126 duration_cast<seconds>(system_clock::now().time_since_epoch())
127 .count()),
128 document.GetAllocator());
129
130 std::string eventId = Uuid::Generate().ToHexString();
131
132 document.AddMember(
133 "event_id",
134 rapidjson::Value(
135 eventId.c_str(), eventId.length(), document.GetAllocator()),
136 document.GetAllocator());
137
138 constexpr char platform[] = "native";
139
140 document.AddMember(
141 "platform",
142 rapidjson::Value(platform, sizeof(platform) - 1, document.GetAllocator()),
143 document.GetAllocator());
144
145 document["platform"].SetString(
146 platform, sizeof(platform) - 1, document.GetAllocator());
147
148 const std::string release = std::string("audacity@") +
149 std::to_string(AUDACITY_VERSION) + "." +
150 std::to_string(AUDACITY_RELEASE) + "." +
151 std::to_string(AUDACITY_REVISION);
152
153 document.AddMember(
154 "release",
155 rapidjson::Value(
156 release.c_str(), release.length(), document.GetAllocator()),
157 document.GetAllocator());
158
159 rapidjson::Value contexts = rapidjson::Value(rapidjson::kObjectType);
160
161 AddOSContext(contexts, document.GetAllocator());
162
163 document.AddMember("contexts", contexts, document.GetAllocator());
164
165 return document;
166}
void AddOSContext(rapidjson::Value &root, rapidjson::Document::AllocatorType &allocator)
Append the data about the operating system to the JSON document.

References AddOSContext(), audacity::Uuid::Generate(), and audacity::Uuid::ToHexString().

Here is the call graph for this function:

◆ SerializeException()

void audacity::sentry::anonymous_namespace{SentryReport.cpp}::SerializeException ( const Exception exception,
rapidjson::Value &  root,
rapidjson::Document::AllocatorType &  allocator 
)

Serialize the Exception to JSON.

Definition at line 180 of file SentryReport.cpp.

183{
184 root.AddMember(
185 "type",
186 rapidjson::Value(
187 exception.Type.c_str(), exception.Type.length(), allocator),
188 allocator);
189
190 root.AddMember(
191 "value",
192 rapidjson::Value(
193 exception.Value.c_str(), exception.Value.length(), allocator),
194 allocator);
195
196 rapidjson::Value mechanismObject(rapidjson::kObjectType);
197
198 mechanismObject.AddMember(
199 "type", rapidjson::Value("runtime_error", allocator), allocator);
200
201 mechanismObject.AddMember(
202 "handled", false, allocator);
203
204 auto contextData = ExceptionContext::Get().MoveParameters();
205
206 if (!exception.Data.empty() || !contextData.empty())
207 {
208 rapidjson::Value dataObject(rapidjson::kObjectType);
209
210 for (const auto& data : contextData)
211 AddExceptionDataToJson(dataObject, allocator, data);
212
213 for (const auto& data : exception.Data)
214 AddExceptionDataToJson(dataObject, allocator, data);
215
216 mechanismObject.AddMember("data", std::move(dataObject), allocator);
217 }
218
219 root.AddMember("mechanism", std::move(mechanismObject), allocator);
220}
size_t length() const noexcept
Returns the length of the message.
const char * c_str() const noexcept
Checks, if the message is empty.
void AddExceptionDataToJson(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator, const ExceptionData &data)
Append the ExceptionData to the Exception JSON object.
AnonymizedMessage Value
Message, associated with the Exception.
Definition: SentryReport.h:35
std::string Type
Exception type. Should not have spaces.
Definition: SentryReport.h:33
std::vector< ExceptionData > Data
Arbitrary payload.
Definition: SentryReport.h:37

References AddExceptionDataToJson(), audacity::sentry::AnonymizedMessage::c_str(), audacity::sentry::Exception::Data, BasicUI::Get(), audacity::sentry::AnonymizedMessage::length(), audacity::sentry::Exception::Type, and audacity::sentry::Exception::Value.

Referenced by audacity::sentry::Report::ReportImpl::ReportImpl().

Here is the call graph for this function:
Here is the caller graph for this function: