Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Other important options include:
- `-DDD_HTTP_USE_SYSTEM_LIBCURL=ON` will link the SDK dynamically against the version of libcurl installed on your system; use `OFF` to download libcurl, build it from source, and link it into the `dd-sdk-cpp` binary
- `-DDD_DEVELOPMENT_ALLOW_AUTO_INSTALL=ON` will permit the CMake configuration process to download **clang-format** and **clang-tidy** if not already present on your system
- `-DDD_ENABLE_CLANG_FORMAT=OFF` and `-DDD_ENABLE_CLANG_TIDY=OFF` will omit those tools from the build
- `-DDD_ENABLE_COVERAGE=OFF` will disable `llvm-cov` instrumentation in environments where it's unsupported or undesirable
- `-DDD_ENABLE_SANITIZERS=` will disable sanitizers (useful for testing crash behavior etc.); default is `ASan,UBSan`; `TSan` and/or `MSan` can also be used as alternatives

For a complete list of configuration options, see [`CMakeLists.txt`](./CMakeLists.txt).

Expand Down Expand Up @@ -79,15 +81,26 @@ ctest --test-dir build
- [`src/datadog/c/`][src-c] implements the C API.
- [`src/datadog/cpp/`][src-cpp] implements the C++ API.
- [`src/datadog/impl/`][src-impl] implements the core business logic of the library, split into:
- [`core/`][impl-core]: Implements the primary business logic of the SDK, including:
- [`core/`][impl-core] implements the primary business logic of the SDK, including:
- [`util/`][core-util]: Internal utility code for commonly-used functionality like asserts, diagnostic logging, etc.
- [`attribute/`][core-attribute]: Copy-on-Write implementation and other utilities used in conjunction with API-layer `datadog::Attribute` type
- [`json/`][core-json]: Minimal JSON serialization routines for encoding event data and attribute values
- [`events/`][core-events]: Utilities used to build JSON-serializable struct types for event payloads
- [`feature_types/`][core-feature-types]: Feature-specific data types used across module boundaries, including event payload types and shared context types
- [`storage/`][core-storage]: Code used to access the filesystem, prepare the SDK's `.datadog/` storage directory, and write and migrate event data
- [`platform/`][core-platform]: Implementations of platform-specific functionality like system info, HTTP client, and access to the system clock
- [`core.hpp`][core-hpp]: Internal core of the SDK, which handles initialization, feature registration, and which runs the storage and upload threads.
- [`context.hpp`][context-hpp]: Common types like `CoreContext`, which provides all features with a snapshot of the SDK's essential state.
- [`feature.hpp`][feature-hpp]: Interfaces used to implement specific features, allowing a feature implementation to register itself with the core, define how it generates events for storage and processes them for upload, and implement its user-facing API.
- [`storage_thread.hpp`][storage-thread-hpp]: Business logic of the storage thread, which asynchronously writes event payloads to disk, batched into TLV-formatted binary files, as those events are generated by feature implementations.
- [`upload_thread.hpp`][upload-thread-hpp]: Business logic of the upload thread, which periodically reads batches of events from storage, passes them to the appropriate feature implementation for processing, then sends them to intake over HTTP.
- [`feature_types/`][impl-feature-types]: Feature-specific data types that permit feature-to-feature interop and are thus defined as part of the core.
- [`features/`][impl-features]: Individual, independent modules for specific features:
- [`logging/`][impl-logging]: Allows users to create loggers; generates log message events in response to log calls.
- [`platform/`][impl-platform]: Platform abstraction layer, i.e. modular subsystems for platform-specific functionality like filesystem access and HTTP client.
- [`feature_scope.hpp`][feature-scope-hpp]: Definition of `FeatureScope`, the interface that gives each feature to access to Core functionality required to access and update context, generate events, etc.
- [`context_thread.hpp`][context-thread-hpp]: The context thread, where work initiated by API calls is enqueued to be processed in the background (so as not to block the calling thread), ultimately modifying `CoreContext` and/or sending events to the storage thread.
- [`storage_thread.hpp`][storage-thread-hpp]: The storage thread, which asynchronously writes event payloads to disk, batched into TLV-formatted binary files, as those events are generated by feature implementations.
- [`upload_thread.hpp`][upload-thread-hpp]: The upload thread, which periodically reads batches of events from storage, passes them to the appropriate feature implementation for processing, then sends them to intake over HTTP.
- [`messaging_thread.hpp`][messaging-thread-hpp]: The messaging thread, where messages are routed and handled, allowing features to respond to state changes that have occurred in the Core or in other features.
- [`logging/`][impl-logging] allows an application to create loggers which will send messages to Datadog.
- [`rum/`][impl-rum] allows an application to keep track of application state and user interactions via Views, Actions, Resources, etc., sending RUM events to Datadog.
- [`crash_reporting/`][impl-crash-reporting] automatically detects application crashes and sends crash reports to Datadog as RUM Errors.
- Multiple crash-handling mechanisms are planned; currently only `DD_CRASH_MODE=inprocess` is supported.
- [`tests/`][tests]: Unit tests for code in `src/`, along with test-only support code.
- [`examples/`][examples] demonstrates usage of both C and C++ APIs.

Expand All @@ -97,14 +110,24 @@ ctest --test-dir build
[src-cpp]: ./src/datadog/cpp/
[src-impl]: ./src/datadog/impl/
[impl-core]: ./src/datadog/impl/core/
[core-util]: ./src/datadog/impl/core/util/
[core-attribute]: ./src/datadog/impl/core/attribute/
[core-json]: ./src/datadog/impl/core/json/
[core-events]: ./src/datadog/impl/core/events/
[core-feature-types]: ./src/datadog/impl/core/feature_types/
[core-storage]: ./src/datadog/impl/core/storage/
[core-platform]: ./src/datadog/impl/core/platform/
[core-hpp]: ./src/datadog/impl/core/core.hpp
[context-hpp]: ./src/datadog/impl/core/context.hpp
[feature-hpp]: ./src/datadog/impl/core/feature.hpp
[feature-scope-hpp]: ./src/datadog/impl/core/feature_scope.hpp
[context-thread-hpp]: ./src/datadog/impl/core/context_thread.hpp
[storage-thread-hpp]: ./src/datadog/impl/core/storage_thread.hpp
[upload-thread-hpp]: ./src/datadog/impl/core/upload_thread.hpp
[impl-feature-types]: ./src/datadog/impl/core/feature_types/
[impl-features]: ./src/datadog/impl/features/
[impl-logging]: ./src/datadog/impl/features/logging/
[impl-platform]: ./src/datadog/impl/platform/
[messaging-thread-hpp]: ./src/datadog/impl/core/messaging_thread.hpp
[impl-logging]: ./src/datadog/impl/logging/
[impl-rum]: ./src/datadog/impl/rum/
[impl-crash-reporting]: ./src/datadog/impl/crash_reporting/
[tests]: ./tests/
[examples]: ./examples/

Expand Down
103 changes: 52 additions & 51 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,63 +22,64 @@ add_library(dd_native ${DD_LIBRARY_TYPE}
datadog/cpp/rum.cpp
datadog/cpp/uuid.cpp
datadog/cpp/version.cpp
datadog/impl/attribute/cow.cpp
datadog/impl/attribute/merge.cpp
datadog/impl/core/
datadog/impl/core/attribute/cow.cpp
datadog/impl/core/attribute/merge.cpp
datadog/impl/core/json/primitives/bool.cpp
datadog/impl/core/json/primitives/float.cpp
datadog/impl/core/json/primitives/integer.cpp
datadog/impl/core/json/primitives/null.cpp
datadog/impl/core/json/primitives/string.cpp
datadog/impl/core/json/primitives/timestamp.cpp
datadog/impl/core/json/primitives/uuid.cpp
datadog/impl/core/json/attribute.cpp
datadog/impl/core/json/diagnostic_attribute.cpp
datadog/impl/core/util/diagnostics.cpp
datadog/impl/core/util/error_message.cpp
datadog/impl/core/util/validation.cpp
datadog/impl/core/context_thread.cpp
datadog/impl/core/context.cpp
datadog/impl/core/message_bus.cpp
datadog/impl/core/messaging_thread.cpp
datadog/impl/core/core.cpp
datadog/impl/core/feature_read.cpp
datadog/impl/core/feature_scope.cpp
datadog/impl/core/feature.cpp
datadog/impl/core/storage_write.cpp
datadog/impl/core/message_bus.cpp
datadog/impl/core/messaging_thread.cpp
datadog/impl/core/storage_queue.cpp
datadog/impl/core/storage_thread.cpp
datadog/impl/core/storage_write.cpp
datadog/impl/core/tlv.cpp
datadog/impl/core/upload_scheduler.cpp
datadog/impl/core/upload_thread.cpp
datadog/impl/core/writer.cpp
datadog/impl/features/logging/logger.cpp
datadog/impl/features/logging/logging.cpp
datadog/impl/features/crash_reporting/crash_reporting.cpp
datadog/impl/features/rum/containers/resource_map.cpp
datadog/impl/features/rum/containers/view_array.cpp
datadog/impl/features/rum/scopes/action.cpp
datadog/impl/features/rum/scopes/application.cpp
datadog/impl/features/rum/scopes/resource.cpp
datadog/impl/features/rum/scopes/session.cpp
datadog/impl/features/rum/scopes/view.cpp
datadog/impl/features/rum/context.cpp
datadog/impl/features/rum/rum.cpp
datadog/impl/features/rum/scope.cpp
datadog/impl/json/primitives/bool.cpp
datadog/impl/json/primitives/float.cpp
datadog/impl/json/primitives/integer.cpp
datadog/impl/json/primitives/null.cpp
datadog/impl/json/primitives/string.cpp
datadog/impl/json/primitives/timestamp.cpp
datadog/impl/json/primitives/uuid.cpp
datadog/impl/json/attribute.cpp
datadog/impl/json/diagnostic_attribute.cpp
datadog/impl/diagnostics.cpp
datadog/impl/error_message.cpp
datadog/impl/validation.cpp
datadog/impl/crash_reporting/crash_reporting.cpp
datadog/impl/logging/logger.cpp
datadog/impl/logging/logging.cpp
datadog/impl/rum/containers/resource_map.cpp
datadog/impl/rum/containers/view_array.cpp
datadog/impl/rum/context.cpp
datadog/impl/rum/rum.cpp
datadog/impl/rum/scope.cpp
datadog/impl/rum/scopes/action.cpp
datadog/impl/rum/scopes/application.cpp
datadog/impl/rum/scopes/resource.cpp
datadog/impl/rum/scopes/session.cpp
datadog/impl/rum/scopes/view.cpp
)

# impl/storage, with IFilesystem implementation determined per-platform
# core/storage, with IFilesystem implementation determined per-platform
target_sources(dd_native PRIVATE
datadog/impl/storage/artifact.cpp
datadog/impl/storage/feature_event.cpp
datadog/impl/storage/filesystem_wrapper.cpp
datadog/impl/storage/path.cpp
datadog/impl/storage/sdk.cpp
datadog/impl/storage/util.cpp
datadog/impl/core/storage/artifact.cpp
datadog/impl/core/storage/feature_event.cpp
datadog/impl/core/storage/filesystem_wrapper.cpp
datadog/impl/core/storage/path.cpp
datadog/impl/core/storage/sdk.cpp
datadog/impl/core/storage/util.cpp
)
if(WIN32)
target_sources(dd_native PRIVATE datadog/impl/storage/filesystem_windows.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/storage/filesystem_windows.cpp)
else()
target_sources(dd_native PRIVATE datadog/impl/storage/filesystem_posix.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/storage/filesystem_posix.cpp)
endif()

# Inject version number from CMake project config
Expand Down Expand Up @@ -154,7 +155,7 @@ endif()
# Platform-specific support for system clock functionality
option(DD_CLOCK_USE_DEFAULT "Use default clock implementation. If disabled, you must supply an implementation of platform/clock.hpp in a file specified as DD_CLOCK_SRC" ON)
if(DD_CLOCK_USE_DEFAULT)
target_sources(dd_native PRIVATE datadog/impl/platform/clock_std.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/platform/clock_std.cpp)
else()
set(DD_CLOCK_SRC "" CACHE STRING "Path to custom implementation of platform/clock.hpp")
if(DD_CLOCK_SRC)
Expand All @@ -174,7 +175,7 @@ if(DD_HTTP_USE_DEFAULT)
target_link_libraries(dd_native PRIVATE CURL::libcurl)
get_target_property(CURL_INCLUDE_DIRS CURL::libcurl INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(dd_native SYSTEM PRIVATE ${CURL_INCLUDE_DIRS})
target_sources(dd_native PRIVATE datadog/impl/platform/http_curl.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/platform/http_curl.cpp)
else()
set(DD_HTTP_SRC "" CACHE STRING "Path to custom implementation of platform/http.hpp")
if(DD_HTTP_SRC)
Expand All @@ -186,12 +187,12 @@ endif()
option(DD_SYSTEMINFO_USE_DEFAULT "Use default system info implementation. If disabled, you must supply an implementation of platform/system_info.hpp in a file specified as DD_SYSTEMINFO_SRC" ON)
if(DD_SYSTEMINFO_USE_DEFAULT)
if(WIN32)
target_sources(dd_native PRIVATE datadog/impl/platform/system_info_windows.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/platform/system_info_windows.cpp)
elseif(APPLE)
target_sources(dd_native PRIVATE datadog/impl/platform/system_info_macos.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/platform/system_info_macos.cpp)
target_link_libraries(dd_native PRIVATE "-framework CoreFoundation")
elseif(UNIX)
target_sources(dd_native PRIVATE datadog/impl/platform/system_info_linux.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/platform/system_info_linux.cpp)
endif()
else()
set(DD_SYSTEMINFO_SRC "" CACHE STRING "Path to custom implementation of platform/system_info.hpp")
Expand All @@ -202,24 +203,24 @@ endif()

# Crash handler implementation selection, based on DD_CRASH_MODE
if(DD_CRASH_MODE STREQUAL "noop")
target_sources(dd_native PRIVATE datadog/impl/platform/crash_handler_noop.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/platform/crash_handler_noop.cpp)
elseif(DD_CRASH_MODE STREQUAL "inprocess")
# Select platform-specific in-process crash handler implementation
if(WIN32)
target_sources(dd_native PRIVATE datadog/impl/platform/crash_handler_inprocess_windows.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/platform/crash_handler_inprocess_windows.cpp)
elseif(UNIX)
# Unified POSIX implementation for Linux and macOS
target_sources(dd_native PRIVATE datadog/impl/platform/crash_handler_inprocess_posix.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/platform/crash_handler_inprocess_posix.cpp)
target_compile_options(dd_native PRIVATE -fno-omit-frame-pointer)
else()
message(FATAL_ERROR "In-process crash handler not supported on this platform")
endif()

# In-process implementation needs to write crash report and context files
target_sources(dd_native PRIVATE
datadog/impl/platform/crash_context_write.cpp
datadog/impl/platform/crash_report_write.cpp
datadog/impl/platform/crash_handler_buildid_cache.cpp
datadog/impl/core/platform/crash_context_write.cpp
datadog/impl/core/platform/crash_report_write.cpp
datadog/impl/core/platform/crash_handler_buildid_cache.cpp
)
elseif(DD_CRASH_MODE STREQUAL "crashpad")
# If building with crashpad support, integrate crashpad as a dependency: this
Expand All @@ -228,7 +229,7 @@ elseif(DD_CRASH_MODE STREQUAL "crashpad")
# binary-compatible builds, this script must run after compile/link options for
# dd_native are fully configured.
include(${DD_SDK_ROOT_DIR}/cmake/crashpad.cmake)
target_sources(dd_native PRIVATE datadog/impl/platform/crash_handler_crashpad.cpp)
target_sources(dd_native PRIVATE datadog/impl/core/platform/crash_handler_crashpad.cpp)
else()
message(FATAL_ERROR "Invalid DD_CRASH_MODE: ${DD_CRASH_MODE}. Must be 'noop', 'inprocess', or 'crashpad'")
endif()
Expand Down
6 changes: 3 additions & 3 deletions src/datadog/c/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <cstring>
#include <memory>

#include "datadog/impl/assert.hpp"
#include "datadog/impl/attribute/cow.hpp"
#include "datadog/impl/attribute/types.hpp"
#include "datadog/impl/core/attribute/cow.hpp"
#include "datadog/impl/core/attribute/types.hpp"
#include "datadog/impl/core/util/assert.hpp"

// Defensively clamp the maximum array/object capacity to a reasonable upper limit at
// the API boundary, so that e.g. a call to `dd_attribute_array(-1)` (which would
Expand Down
2 changes: 1 addition & 1 deletion src/datadog/c/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#include "datadog/c/core_glue.hpp"
#include "datadog/impl/core/core.hpp"
#include "datadog/impl/core/platform/http.hpp"
#include "datadog/impl/core/types.hpp"
#include "datadog/impl/platform/http.hpp"

// NOLINTBEGIN(cppcoreguidelines-owning-memory)

Expand Down
2 changes: 1 addition & 1 deletion src/datadog/c/core_glue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <memory>

#include "datadog/impl/core/core.hpp"
#include "datadog/impl/diagnostics.hpp"
#include "datadog/impl/core/util/diagnostics.hpp"

struct dd_core {
std::unique_ptr<datadog::impl::Core> impl;
Expand Down
2 changes: 1 addition & 1 deletion src/datadog/c/crash_reporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "datadog/c/core_glue.hpp"
#include "datadog/c/crash_reporting_glue.hpp"
#include "datadog/impl/core/core.hpp"
#include "datadog/impl/features/crash_reporting/crash_reporting.hpp"
#include "datadog/impl/crash_reporting/crash_reporting.hpp"

static const uint32_t CRASH_REPORTING_CONFIG_VERSION = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/datadog/c/crash_reporting_glue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "datadog/crash_reporting.h"

#include "datadog/c/core_glue.hpp"
#include "datadog/impl/diagnostics.hpp"
#include "datadog/impl/core/util/diagnostics.hpp"

namespace datadog::impl {
class CrashReporting;
Expand Down
10 changes: 5 additions & 5 deletions src/datadog/c/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

#include "datadog/c/core_glue.hpp"
#include "datadog/c/logging_glue.hpp"
#include "datadog/impl/attribute/types.hpp"
#include "datadog/impl/core/attribute/types.hpp"
#include "datadog/impl/core/core.hpp"
#include "datadog/impl/features/logging/logger.hpp"
#include "datadog/impl/features/logging/logging.hpp"
#include "datadog/impl/features/logging/types.hpp"
#include "datadog/impl/platform/clock.hpp"
#include "datadog/impl/core/platform/clock.hpp"
#include "datadog/impl/logging/logger.hpp"
#include "datadog/impl/logging/logging.hpp"
#include "datadog/impl/logging/types.hpp"

static const uint32_t LOGGER_CONFIG_VERSION = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/datadog/c/logging_glue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "datadog/logging.h"
#include "datadog/logging.hpp"

#include "datadog/impl/diagnostics.hpp"
#include "datadog/impl/core/util/diagnostics.hpp"

namespace datadog::impl {
class Logger;
Expand Down
8 changes: 4 additions & 4 deletions src/datadog/c/rum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#include "datadog/c/core_glue.hpp"
#include "datadog/c/rum_glue.hpp"
#include "datadog/impl/attribute/types.hpp"
#include "datadog/impl/core/attribute/types.hpp"
#include "datadog/impl/core/core.hpp"
#include "datadog/impl/features/rum/rum.hpp"
#include "datadog/impl/features/rum/types.hpp"
#include "datadog/impl/validation.hpp"
#include "datadog/impl/core/util/validation.hpp"
#include "datadog/impl/rum/rum.hpp"
#include "datadog/impl/rum/types.hpp"

static const uint32_t RUM_CONFIG_VERSION = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/datadog/c/rum_glue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "datadog/rum.h"

#include "datadog/c/core_glue.hpp"
#include "datadog/impl/diagnostics.hpp"
#include "datadog/impl/core/util/diagnostics.hpp"

namespace datadog::impl {
class Rum;
Expand Down
2 changes: 1 addition & 1 deletion src/datadog/c/timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <cstring>

#include "datadog/impl/assert.hpp"
#include "datadog/impl/core/util/assert.hpp"

extern "C" {

Expand Down
2 changes: 1 addition & 1 deletion src/datadog/c/uuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "datadog/uuid.hpp"

#include "datadog/impl/assert.hpp"
#include "datadog/impl/core/util/assert.hpp"

extern "C" {

Expand Down
4 changes: 2 additions & 2 deletions src/datadog/cpp/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <cstring>
#include <iostream>

#include "datadog/impl/assert.hpp"
#include "datadog/impl/attribute/cow.hpp"
#include "datadog/impl/core/attribute/cow.hpp"
#include "datadog/impl/core/util/assert.hpp"

namespace datadog {

Expand Down
2 changes: 1 addition & 1 deletion src/datadog/cpp/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <limits>

#include "datadog/impl/core/core.hpp"
#include "datadog/impl/diagnostics.hpp"
#include "datadog/impl/core/util/diagnostics.hpp"

namespace datadog {

Expand Down
2 changes: 1 addition & 1 deletion src/datadog/cpp/crash_reporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "datadog/impl/core/core.hpp"
#include "datadog/impl/core/feature.hpp"
#include "datadog/impl/features/crash_reporting/crash_reporting.hpp"
#include "datadog/impl/crash_reporting/crash_reporting.hpp"

namespace datadog {

Expand Down
Loading