Skip to content

feat(logging): logging in libdatadog #1018

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

Merged
merged 4 commits into from
Jun 5, 2025
Merged

Conversation

ganeshnj
Copy link
Contributor

@ganeshnj ganeshnj commented Apr 11, 2025

What does this PR do?

This pull request includes several changes to add new logging functionality and update dependencies across multiple files. The most important changes include adding new datadog-log and datadog-log-ffi crates, updating dependencies to use tracing instead of log.

Check the RFC for more details included in the PR.

Done

  • Implement basic file and std based logging

Remaining work

  • Implement rate limiting (upcoming PR)
  • Implement file rotation (upcoming PR)

Motivation

Fixes https://datadoghq.atlassian.net/browse/APMSP-1835

This is part of bigger effort to allow language integration access to the logs happening in the libdatadog.

Note

This is blocking issue for data-pipeline .NET integration.

Why separate crate?
Holistically speaking, this functionality not only works for data-pipeline but for any integration. Hence, I decided to move to its own crate just like telemetry. This also gives a place to start adding any other additional crate agnostic logging logic.

Additional Notes

How to test the change?

  • Using the example app which is also updated in the PR.

@codecov-commenter
Copy link

codecov-commenter commented Apr 11, 2025

Codecov Report

Attention: Patch coverage is 64.62963% with 191 lines in your changes missing coverage. Please review.

Project coverage is 70.85%. Comparing base (98a069a) to head (c790b1b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1018      +/-   ##
==========================================
- Coverage   70.88%   70.85%   -0.04%     
==========================================
  Files         331      334       +3     
  Lines       49957    50481     +524     
==========================================
+ Hits        35414    35769     +355     
- Misses      14543    14712     +169     
Components Coverage Δ
datadog-crashtracker 42.41% <ø> (ø)
datadog-crashtracker-ffi 6.03% <ø> (ø)
datadog-alloc 98.73% <ø> (ø)
data-pipeline 90.43% <42.85%> (-0.19%) ⬇️
data-pipeline-ffi 89.26% <ø> (ø)
ddcommon 79.07% <ø> (ø)
ddcommon-ffi 68.64% <ø> (ø)
ddtelemetry 60.56% <ø> (ø)
ddtelemetry-ffi 21.32% <ø> (ø)
dogstatsd-client 83.26% <0.00%> (ø)
datadog-ipc 82.68% <ø> (ø)
datadog-profiling 77.17% <ø> (ø)
datadog-profiling-ffi 62.12% <ø> (ø)
datadog-sidecar 42.32% <ø> (+0.16%) ⬆️
datdog-sidecar-ffi 10.36% <ø> (+1.31%) ⬆️
spawn-worker 55.35% <ø> (ø)
tinybytes 90.96% <ø> (ø)
datadog-trace-normalization 98.24% <ø> (ø)
datadog-trace-obfuscation 94.16% <ø> (ø)
datadog-trace-protobuf 77.10% <ø> (ø)
datadog-trace-utils 89.44% <0.00%> (+0.16%) ⬆️
datadog-log 66.15% <66.15%> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pr-commenter
Copy link

pr-commenter bot commented Apr 11, 2025

Benchmarks

Comparison

Benchmark execution time: 2025-06-05 16:28:29

Comparing candidate commit 7d9f841 in PR branch ganeshnj/feat/logging-ffi with baseline commit 98a069a in branch main.

Found 0 performance improvements and 2 performance regressions! Performance is the same for 50 metrics, 2 unstable metrics.

scenario:benching string interning on wordpress profile

  • 🟥 execution_time [+7.613µs; +7.780µs] or [+5.327%; +5.445%]

scenario:sql/obfuscate_sql_string

  • 🟥 execution_time [+3.960µs; +4.055µs] or [+4.602%; +4.711%]

@r1viollet
Copy link
Contributor

r1viollet commented Apr 11, 2025

Artifact Size Benchmark Report

aarch64-alpine-linux-musl
Artifact Baseline Commit Change
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 8.26 MB 9.25 MB +11.92% (+1009.43 KB) 🚨
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 68.05 MB 73.51 MB +8.01% (+5.45 MB) 🚨
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so.debug 21.15 MB 23.17 MB +9.56% (+2.02 MB) 🚨
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so.debug 23.69 MB 25.85 MB +9.09% (+2.15 MB) 🚨
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 74.98 MB 80.80 MB +7.75% (+5.81 MB) 🚨
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 8.30 MB 9.23 MB +11.15% (+948.46 KB) 🚨
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 16.70 MB 16.72 MB +.11% (+20.00 KB) 🔍
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 62.65 KB 62.65 KB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 112.66 MB 112.76 MB +.08% (+96.00 KB) 🔍
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 632.41 MB 633.40 MB +.15% (+1012.43 KB) 🔍
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 4.98 MB 4.99 MB +.01% (+1.00 KB) 🔍
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 62.65 KB 62.65 KB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 15.85 MB 15.86 MB +.04% (+8.00 KB) 🔍
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 26.38 MB 26.39 MB +.01% (+4.99 KB) 🔍
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 14.15 MB 14.17 MB +.14% (+21.00 KB) 🔍
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 63.60 KB 63.60 KB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 114.55 MB 114.66 MB +.09% (+112.00 KB) 🔍
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 624.68 MB 626.09 MB +.22% (+1.41 MB) 🔍
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 3.77 MB 3.78 MB +.10% (+4.00 KB) 🔍
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 63.60 KB 63.60 KB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 16.48 MB 16.48 MB +.04% (+8.00 KB) 🔍
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 24.30 MB 24.32 MB +.05% (+13.65 KB) 🔍
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 59.32 MB 64.15 MB +8.13% (+4.82 MB) 🚨
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 8.69 MB 9.63 MB +10.76% (+958.59 KB) 🚨
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so.debug 19.47 MB 21.27 MB +9.21% (+1.79 MB) 🚨
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 70.67 MB 75.85 MB +7.33% (+5.18 MB) 🚨
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 8.70 MB 9.65 MB +10.87% (+969.90 KB) 🚨
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so.debug 21.78 MB 23.71 MB +8.87% (+1.93 MB) 🚨

@github-actions github-actions bot added profiling Relates to the profiling* modules. ci-build labels Apr 11, 2025
@ganeshnj ganeshnj changed the title feat(data-pipeline): logging ffi feat(data-pipeline): Cross-Language Logging Integration Apr 14, 2025
@ganeshnj ganeshnj marked this pull request as ready for review April 14, 2025 12:04
@ganeshnj ganeshnj requested review from a team as code owners April 14, 2025 12:04
@morrisonlevi
Copy link
Contributor

morrisonlevi commented Apr 14, 2025

The symbol prefixes I know are already in use are:

  • ddog_prof_*
  • ddog_crasht_*
  • ddog_trace_exporter_*
  • ddog_sidecar_*
  • ddog_telemetry_*

Can we name this ddog_log_* instead of ddlog_*?

@ganeshnj
Copy link
Contributor Author

The symbol prefixes I know are already in use are:

  • ddog_prof_*
  • ddog_crasht_*
  • ddog_trace_exporter_*
  • ddog_sidecar_*
  • ddog_telemetry_*

Can we name this ddog_log_* instead of ddlog_*?

actually this threw me off a few times, currently we have all sort of prefixes depending on the context (crate name vs dir name vs rust type name vs ffi method names)

do you mean anything specific like FFI methods or in general?

I agree that atleast ffi methods should be ddog_log_ since this is only way to namespace them.

@morrisonlevi
Copy link
Contributor

morrisonlevi commented Apr 15, 2025

There are conventions for the full name too, but they are less standardized. I was specifically talking about the FFI symbol prefixes with this comment. Within a package, you should be consistent with the FFI casing, types, etc, but across packages, I want to be consistent with ddog_$package_*, where $package is some shortened name of the crate.

And also I would prefer datadog-log or log for the directory name, with datadog-log for the package name. The ddblah convention is something I'd personally avoid, there's just two-ish (and their FFI crates) following that instead of datadog-blah.

@ganeshnj
Copy link
Contributor Author

There are conventions for the full name too,

A lot of cognitive load... but anyway I would stick to what we have already.

crate name: datadog-log and datadog-log-ffi
dir name: log and log-ffi
prefix: ddog_log_

@ganeshnj ganeshnj marked this pull request as draft May 30, 2025 14:34
@ganeshnj ganeshnj force-pushed the ganeshnj/feat/logging-ffi branch from e0e5c8a to 4c05b2f Compare May 30, 2025 15:04
@ganeshnj ganeshnj changed the title feat(data-pipeline): Cross-Language Logging Integration feat(logging): logging in libdatadog May 30, 2025
@ganeshnj ganeshnj force-pushed the ganeshnj/feat/logging-ffi branch 2 times, most recently from 3621f13 to 3b0b46b Compare May 30, 2025 15:11
@ganeshnj ganeshnj requested review from ekump and morrisonlevi May 30, 2025 22:08
@ganeshnj ganeshnj force-pushed the ganeshnj/feat/logging-ffi branch 2 times, most recently from fb63772 to bd9ab62 Compare June 2, 2025 16:44
.event_format(format)
.with_writer(dynamic_writer.clone());

tracing_subscriber::registry()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What, if anything will happen when libdatadog crates are used in other crates, like dd-trace-rs? I assume if the other crate registers a subscriber then it should just work? No need to use this logger crate?

Copy link
Contributor Author

@ganeshnj ganeshnj Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they must not call into logger, this is exclusively made for the hosted languages.

when comes to other rust libraries, they should follow the practice of allowing apps to setup the tracing subscriber.

TLDR; a rust library should never setup a global subscriber like this but here our use case is FFI based integrations which is fair usage.

@ganeshnj ganeshnj force-pushed the ganeshnj/feat/logging-ffi branch from bd9ab62 to fc42932 Compare June 2, 2025 22:12
@ganeshnj ganeshnj force-pushed the ganeshnj/feat/logging-ffi branch 2 times, most recently from af9b0d6 to 9c8bb42 Compare June 4, 2025 08:38
@ganeshnj ganeshnj force-pushed the ganeshnj/feat/logging-ffi branch 6 times, most recently from 059c87f to 1c04b9e Compare June 5, 2025 16:13
@ganeshnj ganeshnj force-pushed the ganeshnj/feat/logging-ffi branch from 1c04b9e to 997bcf2 Compare June 5, 2025 16:14
@ganeshnj ganeshnj merged commit e029911 into main Jun 5, 2025
44 of 46 checks passed
@ganeshnj ganeshnj deleted the ganeshnj/feat/logging-ffi branch June 5, 2025 17:24
andrewlock added a commit to DataDog/dd-trace-dotnet that referenced this pull request Jul 2, 2025
## Summary of changes

Fixes https://datadoghq.atlassian.net/browse/APMSP-1835

This PR adds enabling the file based logging for libdatadog, ie we start
to write the logs to the configured file as it happens.

## Reason for change

This is missing feature in the native exporter and must have for
troubleshooting.

## Implementation details

This PR DataDog/libdatadog#1018 does the bulk of
the logging setup. In this, we are only calling the exposed APIs.

## Test coverage

Since all the coverage is done in libdatadog there nothing to test in
CI, however I verified manually that log file is created and written.

## Other details
<!-- Fixes #{issue} -->

We will need DataDog/libdatadog#1088 for fully
support the file based logging practices.

Also, we will need a release of libdatadog to pass the CI.

<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->

---------

Co-authored-by: Andrew Lock <[email protected]>
Co-authored-by: Steven Bouwkamp <[email protected]>
chojomok pushed a commit to DataDog/dd-trace-dotnet that referenced this pull request Jul 15, 2025
## Summary of changes

Fixes https://datadoghq.atlassian.net/browse/APMSP-1835

This PR adds enabling the file based logging for libdatadog, ie we start
to write the logs to the configured file as it happens.

## Reason for change

This is missing feature in the native exporter and must have for
troubleshooting.

## Implementation details

This PR DataDog/libdatadog#1018 does the bulk of
the logging setup. In this, we are only calling the exposed APIs.

## Test coverage

Since all the coverage is done in libdatadog there nothing to test in
CI, however I verified manually that log file is created and written.

## Other details
<!-- Fixes #{issue} -->

We will need DataDog/libdatadog#1088 for fully
support the file based logging practices.

Also, we will need a release of libdatadog to pass the CI.

<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->

---------

Co-authored-by: Andrew Lock <[email protected]>
Co-authored-by: Steven Bouwkamp <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants