-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrash_reporting.cpp
More file actions
107 lines (89 loc) · 4.1 KB
/
Copy pathcrash_reporting.cpp
File metadata and controls
107 lines (89 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2025-Present Datadog, Inc.
#include "datadog/crash_reporting.hpp"
#include "datadog/core.hpp"
#include "datadog/impl/core/core.hpp"
#include "datadog/impl/core/feature.hpp"
#include "datadog/impl/crash_reporting/crash_handler.hpp"
#include "datadog/impl/crash_reporting/crash_handler_init.hpp"
#include "datadog/impl/crash_reporting/crash_reporting.hpp"
namespace datadog {
CrashReportingConfig::CrashReportingConfig() = default;
CrashReportingConfig::CrashReportingConfig(const CrashReportingConfig&) = default;
CrashReportingConfig& CrashReportingConfig::operator=(const CrashReportingConfig&) =
default;
CrashReportingConfig::CrashReportingConfig(CrashReportingConfig&&) noexcept = default;
CrashReportingConfig& CrashReportingConfig::operator=(CrashReportingConfig&&) noexcept =
default;
CrashReportingConfig& CrashReportingConfig::SetHandlerExePath(std::string_view value) {
handler_exe_path = value;
return *this;
}
CrashReporting::CrashReporting(CrashReporting::PrivateCtorTag)
: _impl(nullptr),
_diagnostic_handler(nullptr),
_diagnostic_threshold(DiagnosticLevel::Error) {}
CrashReporting::CrashReporting(
std::shared_ptr<impl::CrashReporting>&& impl,
DiagnosticHandler diagnostic_handler,
DiagnosticLevel diagnostic_threshold,
CrashReporting::PrivateCtorTag
)
: _impl(std::move(impl)),
_diagnostic_handler(std::move(diagnostic_handler)),
_diagnostic_threshold(diagnostic_threshold) {
// The C++ crash reporting API doesn't currently emit any diagnostic messages, but
// storing these values ensures that we can do so in the future without ABI changes
(void)_diagnostic_handler;
(void)_diagnostic_threshold;
}
CrashReporting::~CrashReporting() = default;
std::shared_ptr<CrashReporting> CrashReporting::Register(
const std::shared_ptr<Core>& core, const CrashReportingConfig& config
) {
// Return a no-op CrashReporting interface if called without a valid core
if (!core || !core->_impl) {
return std::make_shared<CrashReporting>(CrashReporting::PrivateCtorTag{});
}
// Prepare a directory at <application-storage>/.datadog/.crashes/ to contain
// crash-related artifacts
auto storage = core->_impl->InitializeArtifactStorage(".crashes");
if (!storage) {
return std::make_shared<CrashReporting>(CrashReporting::PrivateCtorTag{});
}
// Initialize an ICrashHandler implementation and get a pointer to the global handler
// instance, which persists throughout the lifetime of the process: this will only
// return a valid pointer the first time it's called, ensuring that only a single
// instance of the CrashReporting feature is empowered to handle and upload crashes
impl::ICrashHandler* handler = impl::CrashHandler::InitializeOnce(
impl::DiagnosticLogger{core->_diagnostic_handler, core->_diagnostic_threshold},
core->_impl->GetFilesystem(),
storage->GetPath(),
config.handler_exe_path
);
// If handler initialization failed, or if crash reporting is being enabled for an SDK
// instance after the first, return a no-op CrashReporting interface
if (!handler) {
return std::make_shared<CrashReporting>(CrashReporting::PrivateCtorTag{});
}
// Initialize our CrashReporting feature implementation
auto crash_reporting_impl = std::make_shared<impl::CrashReporting>(
*handler, core->_impl->GetFilesystem(), storage->GetPath()
);
// Register the feature with the core, returning a no-op interface on failure
if (!core->_impl->RegisterFeature(crash_reporting_impl)) {
return std::make_shared<CrashReporting>(CrashReporting::PrivateCtorTag{});
}
// Initialize and return the API object that represents our user-facing interface
// for the crash reporting feature
return std::make_shared<CrashReporting>(
std::move(crash_reporting_impl),
core->_diagnostic_handler,
core->_diagnostic_threshold,
CrashReporting::PrivateCtorTag{}
);
}
} // namespace datadog