Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crashtracker] Move FFI to its own crate #551

Merged
merged 32 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b83f477
[crashtracker] Move FFI into its own library
danielsn Jul 24, 2024
35981b0
crashtracker in its own ffi library
danielsn Jul 24, 2024
fc2aed2
ddcommon endpoint explicit
danielsn Jul 24, 2024
930758b
use the common endpoint
danielsn Jul 26, 2024
6d9c7d5
builds as its own crate
danielsn Jul 26, 2024
6537e94
Actually seems to work
danielsn Jul 26, 2024
459311f
fix the dockerfile
danielsn Jul 26, 2024
995abe4
trailing newline
danielsn Jul 26, 2024
0411e84
don't use unnecessart quantification
danielsn Jul 26, 2024
6a42ab9
fix doctest
danielsn Jul 29, 2024
4e9056a
Update crashtracker-ffi/src/collector/mod.rs
danielsn Jul 31, 2024
41e081c
[Serverless Mini Agent] Add _dd.mini_agent_version tag to all spans f…
duncanpharvey Jul 31, 2024
78f337f
[Serverless Mini Agent] Run in Azure Spring Apps (#547)
duncanpharvey Jul 31, 2024
c3548ee
bump datadog-serverless-trace-mini-agent version to 0.6.0 (#555)
duncanpharvey Jul 31, 2024
20067fd
rename to datadog-crashtracker-ffi
danielsn Jul 31, 2024
85a08ae
go with lib for the ffi crate
danielsn Jul 31, 2024
b9ee3d5
_crasht_
danielsn Jul 31, 2024
7506a74
_crasht_
danielsn Jul 31, 2024
48de740
function name
danielsn Jul 31, 2024
ae8798e
format
danielsn Jul 31, 2024
f2ecfa2
Option_U32
danielsn Jul 31, 2024
019f250
licence
danielsn Jul 31, 2024
9ad69bf
Timespec
danielsn Jul 31, 2024
b1e45cf
Config
danielsn Jul 31, 2024
edbc777
Merge branch 'main' into dsn/crashtrack-own-ffi
danielsn Jul 31, 2024
ff47bd4
added timespec file for real
danielsn Jul 31, 2024
cc6c922
put back toml change
danielsn Jul 31, 2024
52bde76
chrono needed the std feature to compile ddcommon-ffi
danielsn Jul 31, 2024
8b18343
try a different format to see if msvc is happy
danielsn Jul 31, 2024
a1ad98a
Update crashtracker-ffi/Cargo.toml
danielsn Aug 1, 2024
091f4d9
demangle feature and naming
danielsn Aug 1, 2024
4cc2207
fix readme
danielsn Aug 1, 2024
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
17 changes: 16 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
members = [
"alloc",
"crashtracker",
"crashtracker-ffi",
"profiling",
"profiling-ffi",
"profiling-replayer",
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-3rdparty.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
root_name: datadog-alloc, datadog-crashtracker, ddcommon, ddtelemetry, datadog-ddsketch, datadog-profiling, datadog-profiling-ffi, data-pipeline-ffi, data-pipeline, datadog-trace-normalization, datadog-trace-protobuf, datadog-trace-utils, ddcommon-ffi, build_common, ddtelemetry-ffi, symbolizer-ffi, datadog-profiling-replayer, tools, datadog-ipc, datadog-ipc-macros, tarpc, tarpc-plugins, spawn_worker, cc_utils, datadog-sidecar, datadog-sidecar-macros, datadog-sidecar-ffi, sidecar_mockgen, datadog-trace-obfuscation, test_spawn_from_lib, datadog-serverless-trace-mini-agent, datadog-trace-mini-agent
root_name: datadog-alloc, datadog-crashtracker, ddcommon, ddtelemetry, datadog-ddsketch, crashtracker-ffi, ddcommon-ffi, build_common, datadog-profiling, datadog-profiling-ffi, data-pipeline-ffi, data-pipeline, datadog-trace-normalization, datadog-trace-protobuf, datadog-trace-utils, ddtelemetry-ffi, symbolizer-ffi, datadog-profiling-replayer, tools, datadog-ipc, datadog-ipc-macros, tarpc, tarpc-plugins, spawn_worker, cc_utils, datadog-sidecar, datadog-sidecar-macros, datadog-sidecar-ffi, sidecar_mockgen, datadog-trace-obfuscation, test_spawn_from_lib, datadog-serverless-trace-mini-agent, datadog-trace-mini-agent
third_party_libraries:
- package_name: addr2line
package_version: 0.21.0
Expand Down
2 changes: 1 addition & 1 deletion build-profiling-ffi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ DESTDIR=$destdir cargo build --package tools --bins

echo "Generating $destdir/include/libdatadog headers..."
# ADD headers based on selected features.
HEADERS="$destdir/include/datadog/common.h $destdir/include/datadog/profiling.h $destdir/include/datadog/telemetry.h"
HEADERS="$destdir/include/datadog/common.h $destdir/include/datadog/profiling.h $destdir/include/datadog/telemetry.h $destdir/include/datadog/crashtracker.h"
case $ARG_FEATURES in
*data-pipeline-ffi*)
HEADERS="$HEADERS $destdir/include/datadog/data-pipeline.h"
Expand Down
34 changes: 34 additions & 0 deletions crashtracker-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
# SPDX-License-Identifier: Apache-2.0

[package]
name = "crashtracker-ffi"
danielsn marked this conversation as resolved.
Show resolved Hide resolved
edition.workspace = true
version.workspace = true
rust-version.workspace = true
license.workspace = true

[lib]
#FIXME: should this be like profiling-ffi or like ddcommon-ffi?
danielsn marked this conversation as resolved.
Show resolved Hide resolved
bench =false
danielsn marked this conversation as resolved.
Show resolved Hide resolved

[features]
default = ["cbindgen", "collector", "receiver"]
cbindgen = ["build_common/cbindgen"]
# Enables the in-process collection of crash-info
collector = []
# Enables the use of this library to receiver crash-info from a suitable collector
receiver = []

[build-dependencies]
build_common = { path = "../build-common" }

[dependencies]
anyhow = "1.0"
chrono = {version = "0.4", default-features = false }
datadog-crashtracker = { path = "../crashtracker" }
ddcommon = { path = "../ddcommon" }
ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false }
hyper = {version = "0.14", default-features = false}
symbolic-demangle = { version = "12.8.0", default-features = false, features = ["rust", "cpp", "msvc"] }
symbolic-common = "12.8.0"
10 changes: 10 additions & 0 deletions crashtracker-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0
extern crate build_common;

use build_common::generate_and_configure_header;

fn main() {
let header_name = "crashtracker.h";
generate_and_configure_header(header_name);
}
50 changes: 50 additions & 0 deletions crashtracker-ffi/cbindgen.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
# SPDX-License-Identifier: Apache-2.0

language = "C"
cpp_compat = true
tab_width = 2
header = """// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0
"""
include_guard = "DDOG_CRASHTRACKER_H"
style = "both"
pragma_once = true

no_includes = true
sys_includes = ["stdbool.h", "stddef.h", "stdint.h"]
includes = ["common.h"]

[export]
prefix = "ddog_crashtracker_"
renaming_overrides_prefixing = true

[export.rename]
"ByteSlice" = "ddog_ByteSlice"
"CancellationToken" = "ddog_CancellationToken"
"CharSlice" = "ddog_CharSlice"
"Endpoint" = "ddog_Endpoint"
"Error" = "ddog_Error"
"HttpStatus" = "ddog_HttpStatus"
"Slice_CChar" = "ddog_Slice_CChar"
"Slice_I64" = "ddog_Slice_I64"
"Slice_U8" = "ddog_Slice_U8"
"Tag" = "ddog_Tag"
"Timespec" = "ddog_Timespec"
"Vec_Tag" = "ddog_Vec_Tag"
"Vec_U8" = "ddog_Vec_U8"

[export.mangle]
rename_types = "PascalCase"

[enum]
prefix_with_name = true
rename_variants = "ScreamingSnakeCase"

[fn]
must_use = "DDOG_CHECK_RETURN"

[parse]
parse_deps = true
include = ["ddcommon", "ddcommon-ffi", "datadog-crashtracker", "ux"]

danielsn marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use super::datatypes::ProfilingOpTypes;
use crate::crashtracker::datatypes::*;
use crate::Result;
use anyhow::Context;

/// Resets all counters to 0.
Expand All @@ -15,9 +15,9 @@ use anyhow::Context;
/// No safety concerns.
#[no_mangle]
#[must_use]
pub unsafe extern "C" fn ddog_prof_Crashtracker_reset_counters() -> CrashtrackerResult {
pub unsafe extern "C" fn ddog_crashtracker_reset_counters() -> Result {
datadog_crashtracker::reset_counters()
.context("ddog_prof_Crashtracker_begin_profiling_op failed")
.context("ddog_crashtracker_begin_profiling_op failed")
danielsn marked this conversation as resolved.
Show resolved Hide resolved
.into()
}

Expand All @@ -28,11 +28,9 @@ pub unsafe extern "C" fn ddog_prof_Crashtracker_reset_counters() -> Crashtracker
///
/// # Safety
/// No safety concerns.
pub unsafe extern "C" fn ddog_prof_Crashtracker_begin_profiling_op(
op: ProfilingOpTypes,
) -> CrashtrackerResult {
pub unsafe extern "C" fn ddog_crashtracker_begin_profiling_op(op: ProfilingOpTypes) -> Result {
datadog_crashtracker::begin_profiling_op(op)
.context("ddog_prof_Crashtracker_begin_profiling_op failed")
.context("ddog_crashtracker_begin_profiling_op failed")
.into()
}

Expand All @@ -43,10 +41,8 @@ pub unsafe extern "C" fn ddog_prof_Crashtracker_begin_profiling_op(
///
/// # Safety
/// No safety concerns.
pub unsafe extern "C" fn ddog_prof_Crashtracker_end_profiling_op(
op: ProfilingOpTypes,
) -> CrashtrackerResult {
pub unsafe extern "C" fn ddog_crashtracker_end_profiling_op(op: ProfilingOpTypes) -> Result {
datadog_crashtracker::end_profiling_op(op)
.context("ddog_prof_Crashtracker_end_profiling_op failed")
.context("ddog_crashtracker_end_profiling_op failed")
.into()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use crate::option_from_char_slice;
pub use datadog_crashtracker::{ProfilingOpTypes, StacktraceCollection};
use ddcommon::Endpoint;
use ddcommon_ffi::slice::{AsBytes, CharSlice};
use ddcommon_ffi::{Error, Slice};

Expand All @@ -13,7 +14,7 @@ pub struct EnvVar<'a> {
}

#[repr(C)]
pub struct CrashtrackerReceiverConfig<'a> {
pub struct ReceiverConfig<'a> {
pub args: Slice<'a, CharSlice<'a>>,
pub env: Slice<'a, EnvVar<'a>>,
pub path_to_receiver_binary: CharSlice<'a>,
Expand All @@ -23,11 +24,9 @@ pub struct CrashtrackerReceiverConfig<'a> {
pub optional_stdout_filename: CharSlice<'a>,
}

impl<'a> TryFrom<CrashtrackerReceiverConfig<'a>>
for datadog_crashtracker::CrashtrackerReceiverConfig
{
impl<'a> TryFrom<ReceiverConfig<'a>> for datadog_crashtracker::CrashtrackerReceiverConfig {
type Error = anyhow::Error;
fn try_from(value: CrashtrackerReceiverConfig<'a>) -> anyhow::Result<Self> {
fn try_from(value: ReceiverConfig<'a>) -> anyhow::Result<Self> {
let args = {
let mut vec = Vec::with_capacity(value.args.len());
for x in value.args.iter() {
Expand Down Expand Up @@ -59,24 +58,20 @@ impl<'a> TryFrom<CrashtrackerReceiverConfig<'a>>
}

#[repr(C)]
pub struct CrashtrackerConfiguration<'a> {
pub struct Configuration<'a> {
pub additional_files: Slice<'a, CharSlice<'a>>,
pub create_alt_stack: bool,
/// The endpoint to send the crash report to (can be a file://)
///
/// If ProfilingEndpoint is left to a zero value (enum value for Agent + empty charslice),
/// the crashtracker will infer the agent host from env variables.
pub endpoint: Option<&'a ddcommon::Endpoint>,
/// The endpoint to send the crash report to (can be a file://).
/// If None, the crashtracker will infer the agent host from env variables.
pub endpoint: Option<&'a Endpoint>,
pub resolve_frames: StacktraceCollection,
pub timeout_secs: u64,
pub wait_for_receiver: bool,
}

impl<'a> TryFrom<CrashtrackerConfiguration<'a>>
for datadog_crashtracker::CrashtrackerConfiguration
{
impl<'a> TryFrom<Configuration<'a>> for datadog_crashtracker::CrashtrackerConfiguration {
type Error = anyhow::Error;
fn try_from(value: CrashtrackerConfiguration<'a>) -> anyhow::Result<Self> {
fn try_from(value: Configuration<'a>) -> anyhow::Result<Self> {
let additional_files = {
let mut vec = Vec::with_capacity(value.additional_files.len());
for x in value.additional_files.iter() {
Expand All @@ -99,13 +94,13 @@ impl<'a> TryFrom<CrashtrackerConfiguration<'a>>
}

#[repr(C)]
pub enum CrashtrackerUsizeResult {
pub enum UsizeResult {
Ok(usize),
#[allow(dead_code)]
Err(Error),
}

impl From<anyhow::Result<usize>> for CrashtrackerUsizeResult {
impl From<anyhow::Result<usize>> for UsizeResult {
fn from(value: anyhow::Result<usize>) -> Self {
match value {
Ok(x) => Self::Ok(x),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ mod counters;
mod datatypes;
mod spans;

use super::crash_info::CrashtrackerMetadata;
use crate::crashtracker::datatypes::*;
use super::crash_info::Metadata;
use crate::Result;
use anyhow::Context;
pub use counters::*;
pub use datatypes::*;
Expand All @@ -28,9 +28,9 @@ pub use spans::*;
/// # Atomicity
/// This function is not atomic. A crash during its execution may lead to
/// unexpected crash-handling behaviour.
pub unsafe extern "C" fn ddog_prof_Crashtracker_shutdown() -> CrashtrackerResult {
pub unsafe extern "C" fn ddog_crashtracker_shutdown() -> Result {
datadog_crashtracker::shutdown_crash_handler()
.context("ddog_prof_Crashtracker_shutdown failed")
.context("ddog_crashtracker_shutdown failed")
.into()
}

Expand All @@ -54,18 +54,18 @@ pub unsafe extern "C" fn ddog_prof_Crashtracker_shutdown() -> CrashtrackerResult
/// # Atomicity
/// This function is not atomic. A crash during its execution may lead to
/// unexpected crash-handling behaviour.
pub unsafe extern "C" fn ddog_prof_Crashtracker_update_on_fork(
config: CrashtrackerConfiguration,
receiver_config: CrashtrackerReceiverConfig,
metadata: CrashtrackerMetadata,
) -> CrashtrackerResult {
pub unsafe extern "C" fn ddog_crashtracker_update_on_fork(
config: Configuration,
receiver_config: ReceiverConfig,
metadata: Metadata,
) -> Result {
danielsn marked this conversation as resolved.
Show resolved Hide resolved
(|| {
let config = config.try_into()?;
let receiver_config = receiver_config.try_into()?;
let metadata = metadata.try_into()?;
datadog_crashtracker::on_fork(config, receiver_config, metadata)
})()
.context("ddog_prof_Crashtracker_update_on_fork failed")
.context("ddog_crashtracker_update_on_fork failed")
.into()
}

Expand All @@ -81,17 +81,17 @@ pub unsafe extern "C" fn ddog_prof_Crashtracker_update_on_fork(
/// # Atomicity
/// This function is not atomic. A crash during its execution may lead to
/// unexpected crash-handling behaviour.
pub unsafe extern "C" fn ddog_prof_Crashtracker_init_with_receiver(
config: CrashtrackerConfiguration,
receiver_config: CrashtrackerReceiverConfig,
metadata: CrashtrackerMetadata,
) -> CrashtrackerResult {
pub unsafe extern "C" fn ddog_crashtracker_init_with_receiver(
config: Configuration,
receiver_config: ReceiverConfig,
metadata: Metadata,
) -> Result {
(|| {
let config = config.try_into()?;
let receiver_config = receiver_config.try_into()?;
let metadata = metadata.try_into()?;
datadog_crashtracker::init_with_receiver(config, receiver_config, metadata)
})()
.context("ddog_prof_Crashtracker_init failed")
.context("ddog_crashtracker_init failed")
danielsn marked this conversation as resolved.
Show resolved Hide resolved
.into()
}
Loading
Loading