Skip to content

Commit 6dab714

Browse files
authored
feat: endpoint renaming (#260)
* Fix bin/format to work on mac os For reasons I didn't explore further, /mnt/host/Users is shown in the directory listing of /mnt/host, but can't be traversed * Implement endpoint guessing
1 parent 8d9d6ba commit 6dab714

23 files changed

+618
-63
lines changed

BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cc_library(
1717
"src/datadog/datadog_agent_config.cpp",
1818
"src/datadog/datadog_agent.cpp",
1919
"src/datadog/default_http_client_null.cpp",
20+
"src/datadog/endpoint_inferral.cpp",
2021
"src/datadog/environment.cpp",
2122
"src/datadog/error.cpp",
2223
"src/datadog/extraction_util.cpp",
@@ -60,6 +61,7 @@ cc_library(
6061
"src/datadog/datadog_agent.h",
6162
"src/datadog/default_http_client.h",
6263
"src/datadog/extracted_data.h",
64+
"src/datadog/endpoint_inferral.h",
6365
"src/datadog/extraction_util.h",
6466
"src/datadog/glob.h",
6567
"src/datadog/hex.h",
@@ -97,6 +99,7 @@ cc_library(
9799
"include/datadog/event_scheduler.h",
98100
"include/datadog/expected.h",
99101
"include/datadog/http_client.h",
102+
"include/datadog/http_endpoint_calculation_mode.h",
100103
"include/datadog/id_generator.h",
101104
"include/datadog/injection_options.h",
102105
"include/datadog/logger.h",

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ target_sources(dd-trace-cpp-objects
173173
src/datadog/collector_response.cpp
174174
src/datadog/datadog_agent_config.cpp
175175
src/datadog/datadog_agent.cpp
176+
src/datadog/endpoint_inferral.cpp
176177
src/datadog/environment.cpp
177178
src/datadog/error.cpp
178179
src/datadog/extraction_util.cpp

bin/format

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
set -e
44

5+
# Determine the script directory and repository root
6+
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
7+
REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
8+
59
# Go to the repository root directory.
6-
cd "$(dirname "$0")"/..
10+
cd "$REPO_ROOT"
711

812
# clang-format's behavior changes between versions, even given the same
913
# configuration.
@@ -41,16 +45,16 @@ if [ "$(docker image ls --quiet $image | wc -l)" -eq 0 ]; then
4145
esac
4246
fi
4347

44-
mount_path=/mnt/host
48+
mount_path=/mnt/repo
4549

46-
# File paths passed to the dockerized clang-format need to be resolved and
47-
# prefixed with the bind mount path.
50+
# File paths passed to the dockerized clang-format need to be relative to
51+
# the repository root and prefixed with the bind mount path.
4852
#
4953
# Non-path arguments (flags) are left alone.
5054
process_arg() {
5155
case "$1" in
5256
-*) printf '%s\0' "$1" ;;
53-
*) printf '%s/%s\0' "$mount_path" "$(realpath "$1")" ;;
57+
*) printf '%s/%s\0' "$mount_path" "$1" ;;
5458
esac
5559
}
5660

@@ -65,7 +69,7 @@ docker_clang_format() {
6569
--volume /etc/passwd:/etc/passwd:ro \
6670
--volume /etc/group:/etc/group:ro \
6771
--user "$(id -u):$(id -g)" \
68-
--mount "type=bind,source=/,destination=$mount_path" \
72+
--mount "type=bind,source=$REPO_ROOT,destination=$mount_path" \
6973
"$image" \
7074
clang-format $formatter_options
7175
}

include/datadog/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ enum class ConfigName : char {
2828
TRACE_BAGGAGE_MAX_BYTES,
2929
TRACE_BAGGAGE_MAX_ITEMS,
3030
APM_TRACING_ENABLED,
31+
TRACE_RESOURCE_RENAMING_ENABLED,
32+
TRACE_RESOURCE_RENAMING_ALWAYS_SIMPLIFIED_ENDPOINT,
3133
};
3234

3335
// Represents metadata for configuration parameters

include/datadog/environment.h

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,46 @@ namespace environment {
2323

2424
// To enforce correspondence between `enum Variable` and `variable_names`, the
2525
// preprocessor is used so that the DD_* symbols are listed exactly once.
26-
#define LIST_ENVIRONMENT_VARIABLES(MACRO) \
27-
MACRO(DD_AGENT_HOST) \
28-
MACRO(DD_ENV) \
29-
MACRO(DD_INSTRUMENTATION_TELEMETRY_ENABLED) \
30-
MACRO(DD_PROPAGATION_STYLE_EXTRACT) \
31-
MACRO(DD_PROPAGATION_STYLE_INJECT) \
32-
MACRO(DD_REMOTE_CONFIGURATION_ENABLED) \
33-
MACRO(DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS) \
34-
MACRO(DD_SERVICE) \
35-
MACRO(DD_SPAN_SAMPLING_RULES) \
36-
MACRO(DD_SPAN_SAMPLING_RULES_FILE) \
37-
MACRO(DD_TRACE_PROPAGATION_STYLE_EXTRACT) \
38-
MACRO(DD_TRACE_PROPAGATION_STYLE_INJECT) \
39-
MACRO(DD_TRACE_PROPAGATION_STYLE) \
40-
MACRO(DD_TAGS) \
41-
MACRO(DD_TRACE_AGENT_PORT) \
42-
MACRO(DD_TRACE_AGENT_URL) \
43-
MACRO(DD_TRACE_DEBUG) \
44-
MACRO(DD_TRACE_ENABLED) \
45-
MACRO(DD_TRACE_RATE_LIMIT) \
46-
MACRO(DD_TRACE_REPORT_HOSTNAME) \
47-
MACRO(DD_TRACE_SAMPLE_RATE) \
48-
MACRO(DD_TRACE_SAMPLING_RULES) \
49-
MACRO(DD_TRACE_STARTUP_LOGS) \
50-
MACRO(DD_TRACE_TAGS_PROPAGATION_MAX_LENGTH) \
51-
MACRO(DD_VERSION) \
52-
MACRO(DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED) \
53-
MACRO(DD_TELEMETRY_HEARTBEAT_INTERVAL) \
54-
MACRO(DD_TELEMETRY_METRICS_ENABLED) \
55-
MACRO(DD_TELEMETRY_METRICS_INTERVAL_SECONDS) \
56-
MACRO(DD_TELEMETRY_DEBUG) \
57-
MACRO(DD_TRACE_BAGGAGE_MAX_ITEMS) \
58-
MACRO(DD_TRACE_BAGGAGE_MAX_BYTES) \
59-
MACRO(DD_TELEMETRY_LOG_COLLECTION_ENABLED) \
60-
MACRO(DD_INSTRUMENTATION_INSTALL_ID) \
61-
MACRO(DD_INSTRUMENTATION_INSTALL_TYPE) \
62-
MACRO(DD_INSTRUMENTATION_INSTALL_TIME) \
63-
MACRO(DD_APM_TRACING_ENABLED) \
26+
#define LIST_ENVIRONMENT_VARIABLES(MACRO) \
27+
MACRO(DD_AGENT_HOST) \
28+
MACRO(DD_ENV) \
29+
MACRO(DD_INSTRUMENTATION_TELEMETRY_ENABLED) \
30+
MACRO(DD_PROPAGATION_STYLE_EXTRACT) \
31+
MACRO(DD_PROPAGATION_STYLE_INJECT) \
32+
MACRO(DD_REMOTE_CONFIGURATION_ENABLED) \
33+
MACRO(DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS) \
34+
MACRO(DD_SERVICE) \
35+
MACRO(DD_SPAN_SAMPLING_RULES) \
36+
MACRO(DD_SPAN_SAMPLING_RULES_FILE) \
37+
MACRO(DD_TRACE_PROPAGATION_STYLE_EXTRACT) \
38+
MACRO(DD_TRACE_PROPAGATION_STYLE_INJECT) \
39+
MACRO(DD_TRACE_PROPAGATION_STYLE) \
40+
MACRO(DD_TAGS) \
41+
MACRO(DD_TRACE_AGENT_PORT) \
42+
MACRO(DD_TRACE_AGENT_URL) \
43+
MACRO(DD_TRACE_DEBUG) \
44+
MACRO(DD_TRACE_ENABLED) \
45+
MACRO(DD_TRACE_RATE_LIMIT) \
46+
MACRO(DD_TRACE_REPORT_HOSTNAME) \
47+
MACRO(DD_TRACE_SAMPLE_RATE) \
48+
MACRO(DD_TRACE_SAMPLING_RULES) \
49+
MACRO(DD_TRACE_STARTUP_LOGS) \
50+
MACRO(DD_TRACE_TAGS_PROPAGATION_MAX_LENGTH) \
51+
MACRO(DD_VERSION) \
52+
MACRO(DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED) \
53+
MACRO(DD_TELEMETRY_HEARTBEAT_INTERVAL) \
54+
MACRO(DD_TELEMETRY_METRICS_ENABLED) \
55+
MACRO(DD_TELEMETRY_METRICS_INTERVAL_SECONDS) \
56+
MACRO(DD_TELEMETRY_DEBUG) \
57+
MACRO(DD_TRACE_BAGGAGE_MAX_ITEMS) \
58+
MACRO(DD_TRACE_BAGGAGE_MAX_BYTES) \
59+
MACRO(DD_TELEMETRY_LOG_COLLECTION_ENABLED) \
60+
MACRO(DD_INSTRUMENTATION_INSTALL_ID) \
61+
MACRO(DD_INSTRUMENTATION_INSTALL_TYPE) \
62+
MACRO(DD_INSTRUMENTATION_INSTALL_TIME) \
63+
MACRO(DD_APM_TRACING_ENABLED) \
64+
MACRO(DD_TRACE_RESOURCE_RENAMING_ENABLED) \
65+
MACRO(DD_TRACE_RESOURCE_RENAMING_ALWAYS_SIMPLIFIED_ENDPOINT) \
6466
MACRO(DD_EXTERNAL_ENV)
6567

6668
#define WITH_COMMA(ARG) ARG,

include/datadog/http_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class HTTPClient {
2626
std::string scheme; // http, https, or unix
2727
std::string authority; // domain:port or /path/to/socket
2828
std::string path; // resource, e.g. /v0.4/traces
29+
std::string query; // query string without '?'
2930

3031
static Expected<HTTPClient::URL> parse(StringView input);
3132
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
// This component provides an enumeration that controls how the http.endpoint
4+
// tag is calculated for HTTP spans.
5+
6+
#include <cstdint>
7+
8+
namespace datadog {
9+
namespace tracing {
10+
11+
// `HttpEndpointCalculationMode` determines when and how the http.endpoint tag
12+
// is inferred from http.url for HTTP spans.
13+
//
14+
// The http.endpoint tag provides a normalized, parameterized version of the
15+
// HTTP path (e.g., "/users/{param:int}" instead of "/users/123"). This helps
16+
// aggregate similar requests and reduce cardinality in monitoring systems.
17+
enum class HttpEndpointCalculationMode : std::uint8_t {
18+
// Do not calculate http.endpoint. The tag will not be set unless explicitly
19+
// provided by the user.
20+
DISABLED,
21+
22+
// Calculate http.endpoint from http.url only when http.route is not present.
23+
// This mode acts as a fallback - if instrumentation provides http.route,
24+
// use that; otherwise, infer http.endpoint from the URL path.
25+
FALLBACK,
26+
27+
// Always calculate http.endpoint from http.url, even when http.route is
28+
// present. Both tags will be set, allowing for comparison between
29+
// user-provided routes and automatically inferred endpoints.
30+
ALWAYS_CALCULATE,
31+
};
32+
33+
} // namespace tracing
34+
} // namespace datadog

include/datadog/trace_segment.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "runtime_id.h"
3838
#include "sampling_decision.h"
3939
#include "sampling_priority.h"
40+
#include "tracer_config.h"
4041

4142
namespace datadog {
4243
namespace telemetry {
@@ -79,6 +80,8 @@ class TraceSegment {
7980

8081
std::shared_ptr<ConfigManager> config_manager_;
8182

83+
HttpEndpointCalculationMode resource_renaming_mode_;
84+
8285
bool tracing_enabled_;
8386

8487
public:
@@ -97,6 +100,7 @@ class TraceSegment {
97100
Optional<std::string> additional_w3c_tracestate,
98101
Optional<std::string> additional_datadog_w3c_tracestate,
99102
std::unique_ptr<SpanData> local_root,
103+
HttpEndpointCalculationMode resource_renaming_mode,
100104
bool tracing_enabled = true);
101105

102106
const SpanDefaults& defaults() const;

include/datadog/tracer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Tracer {
5555
bool baggage_injection_enabled_;
5656
bool baggage_extraction_enabled_;
5757
bool tracing_enabled_;
58+
HttpEndpointCalculationMode resource_renaming_mode_;
5859

5960
public:
6061
// Create a tracer configured using the specified `config`, and optionally:

include/datadog/tracer_config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "clock.h"
1616
#include "datadog_agent_config.h"
1717
#include "expected.h"
18+
#include "http_endpoint_calculation_mode.h"
1819
#include "propagation_style.h"
1920
#include "runtime_id.h"
2021
#include "span_defaults.h"
@@ -178,6 +179,15 @@ struct TracerConfig {
178179
/// Overridden by the `DD_APM_TRACING_ENABLED` environment variable. Defaults
179180
/// to `true`.
180181
Optional<bool> tracing_enabled;
182+
183+
// Whether generation of http.endpoint is enabled. This is disabled by
184+
// default.
185+
Optional<bool> resource_renaming_enabled;
186+
187+
// Whether http.endpoint is always calculated, even when http.route is
188+
// present. This is disabled by default.
189+
// This option is ignored if `resource_renaming_enabled` is not `true`.
190+
Optional<bool> resource_renaming_always_simplified_endpoint;
181191
};
182192

183193
// `FinalizedTracerConfig` contains `Tracer` implementation details derived from
@@ -218,6 +228,7 @@ class FinalizedTracerConfig final {
218228
std::shared_ptr<EventScheduler> event_scheduler;
219229
std::shared_ptr<HTTPClient> http_client;
220230
bool tracing_enabled;
231+
HttpEndpointCalculationMode resource_renaming_mode;
221232
};
222233

223234
// Return a `FinalizedTracerConfig` from the specified `config` and from any

0 commit comments

Comments
 (0)