-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (75 loc) · 2.69 KB
/
Copy pathmain.cpp
File metadata and controls
96 lines (75 loc) · 2.69 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
// 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 <chrono>
#include <iostream>
#include <thread>
#include "datadog.hpp"
int main() // NOLINT(bugprone-exception-escape)
{
// TODO: Compile with -fno-exceptions; clarify exception guarantees; ensure that all
// exceptions besides std::bad_alloc are practically impossible
std::cout << "Datadog Native SDK C++ Example\n";
// Prepare our configuration and create the Datadog SDK Core
datadog::CoreConfig config("fake-client-token", "example-service", "development");
config.SetVersion("1.0.0");
auto core = datadog::Core::Create(config, datadog::TrackingConsent::Pending);
if (!core) {
std::cout << "Failed to create Datadog core\n";
return 1;
}
// Register the logging feature
auto logging = datadog::Logging::Register(core);
if (!logging) {
std::cout << "Failed to register logging\n";
return 1;
}
// Create a logger (this can be done before or after Core start)
auto logger = logging->CreateLogger();
if (!logger) {
std::cout << "Failed to create logger\n";
return 1;
}
// Register the RUM feature
auto rum = datadog::Rum::Register(
core, datadog::RumConfig("a991ca10-4004-4004-4004-beefbeefbeef")
);
if (!rum) {
// TODO: null checks are unnecessary
std::cout << "Failed to register RUM\n";
return 1;
}
// Start the core to begin processing events
std::cout << "Starting Datadog core...\n";
if (!core->Start()) {
std::cout << "Failed to start core\n";
return 1;
}
// Whenever the user's tracking consent changes, convey it to the SDK
core->SetTrackingConsent(datadog::TrackingConsent::Granted);
// Use our logger to send a message
logger->Info("Hello world!");
// Start a RUM View
rum->StartView("main_menu");
// Log messages will now be correlated with our session and view in the RUM UI
logger->Info("Main menu loaded");
// Record a RUM Action
rum->AddAction(datadog::RumActionType::Custom, "Start Menu Navigation");
// Track a operation that succeeds
rum->StartOperation("Checkout");
rum->SucceedOperation("Checkout");
// Track a operation that fails
rum->StartOperation("Upload", "profile-photo");
rum->FailOperation(
"Upload", datadog::RumOperationFailureReason::Error, "profile-photo"
);
// Stop the RUM view
rum->StopView("main_menu");
// Stop the core on application shutdown
std::cout << "Core started successfully. Shutting down...\n";
core->Stop();
std::cout << "Example completed successfully\n";
return 0;
}