From 204556489f16be24b0bd586b231fec75b08f162d Mon Sep 17 00:00:00 2001 From: David Sanchez <838104+sanchda@users.noreply.github.com> Date: Wed, 14 Aug 2024 12:08:31 -0700 Subject: [PATCH] chore(crashtracker): add required backend tags (#10199) This adds two new tags to the crashtracker. These tags will not be required in an upcoming version of libdatadog, but that version doesn't exist yet, so here we are. There's no need to document anything in a changelog since this feature isn't customer-impacting. It just makes it easier for us to build dashboards on the backend. :) [PROF-10357] ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --- .../dd_wrapper/include/constants.hpp | 4 ++ .../dd_wrapper/include/libdatadog_helpers.hpp | 4 +- .../profiling/dd_wrapper/src/crashtracker.cpp | 2 + .../crashtracker/test_crashtracker.py | 39 +++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/ddtrace/internal/datadog/profiling/dd_wrapper/include/constants.hpp b/ddtrace/internal/datadog/profiling/dd_wrapper/include/constants.hpp index 2aa3dc7c89e..1467ac6248d 100644 --- a/ddtrace/internal/datadog/profiling/dd_wrapper/include/constants.hpp +++ b/ddtrace/internal/datadog/profiling/dd_wrapper/include/constants.hpp @@ -26,3 +26,7 @@ constexpr std::string_view g_language_name = "python"; // Name of the library constexpr std::string_view g_library_name = "dd-trace-py"; + +// These are default settings for crashtracker tags. These will be moved internally to crashtracker in the near future. +constexpr std::string_view g_crashtracker_is_crash = "true"; +constexpr std::string_view g_crashtracker_severity = "crash"; diff --git a/ddtrace/internal/datadog/profiling/dd_wrapper/include/libdatadog_helpers.hpp b/ddtrace/internal/datadog/profiling/dd_wrapper/include/libdatadog_helpers.hpp index 552e461cc8a..cf125799216 100644 --- a/ddtrace/internal/datadog/profiling/dd_wrapper/include/libdatadog_helpers.hpp +++ b/ddtrace/internal/datadog/profiling/dd_wrapper/include/libdatadog_helpers.hpp @@ -28,7 +28,9 @@ namespace Datadog { X(runtime_id, "runtime-id") \ X(profiler_version, "profiler_version") \ X(library_version, "library_version") \ - X(profile_seq, "profile_seq") + X(profile_seq, "profile_seq") \ + X(is_crash, "is_crash") \ + X(severity, "severity") // Here there are two columns because the Datadog backend expects these labels // to have spaces in the names. diff --git a/ddtrace/internal/datadog/profiling/dd_wrapper/src/crashtracker.cpp b/ddtrace/internal/datadog/profiling/dd_wrapper/src/crashtracker.cpp index 49c1263071a..f707573a65d 100644 --- a/ddtrace/internal/datadog/profiling/dd_wrapper/src/crashtracker.cpp +++ b/ddtrace/internal/datadog/profiling/dd_wrapper/src/crashtracker.cpp @@ -156,6 +156,8 @@ Datadog::Crashtracker::get_tags() { ExportTagKey::runtime_id, runtime_id }, { ExportTagKey::runtime_version, runtime_version }, { ExportTagKey::library_version, library_version }, + { ExportTagKey::is_crash, g_crashtracker_is_crash }, + { ExportTagKey::severity, g_crashtracker_severity }, }; // Add system tags diff --git a/tests/internal/crashtracker/test_crashtracker.py b/tests/internal/crashtracker/test_crashtracker.py index 57a22f945c5..26dab08381b 100644 --- a/tests/internal/crashtracker/test_crashtracker.py +++ b/tests/internal/crashtracker/test_crashtracker.py @@ -414,6 +414,45 @@ def test_crashtracker_auto_disabled(run_python_code_in_subprocess): assert not conn +@pytest.mark.skipif(not sys.platform.startswith("linux"), reason="Linux only") +@pytest.mark.subprocess() +def test_crashtracker_tags_required(): + # Tests tag ingestion in the core API + import ctypes + import os + + import tests.internal.crashtracker.utils as utils + + port, sock = utils.crashtracker_receiver_bind() + assert port + assert sock + + pid = os.fork() + if pid == 0: + assert utils.start_crashtracker(port) + stdout_msg, stderr_msg = utils.read_files(["stdout.log", "stderr.log"]) + assert not stdout_msg + assert not stderr_msg + + ctypes.string_at(0) + exit(-1) + + conn = utils.listen_get_conn(sock) + assert conn + data = utils.conn_to_bytes(conn) + conn.close() + assert b"string_at" in data + + # Now check for the tags + tags = { + "is_crash": "true", + "severity": "crash", + } + for k, v in tags.items(): + assert k.encode() in data, k + assert v.encode() in data, v + + @pytest.mark.skipif(not sys.platform.startswith("linux"), reason="Linux only") def test_crashtracker_user_tags_envvar(run_python_code_in_subprocess): # Setup the listening socket before we open ddtrace