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
3 changes: 3 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cc_library(
"src/datadog/datadog_agent_config.cpp",
"src/datadog/datadog_agent.cpp",
"src/datadog/default_http_client_null.cpp",
"src/datadog/endpoint_inferral.cpp",
"src/datadog/environment.cpp",
"src/datadog/error.cpp",
"src/datadog/extraction_util.cpp",
Expand Down Expand Up @@ -60,6 +61,7 @@ cc_library(
"src/datadog/datadog_agent.h",
"src/datadog/default_http_client.h",
"src/datadog/extracted_data.h",
"src/datadog/endpoint_inferral.h",
"src/datadog/extraction_util.h",
"src/datadog/glob.h",
"src/datadog/hex.h",
Expand Down Expand Up @@ -97,6 +99,7 @@ cc_library(
"include/datadog/event_scheduler.h",
"include/datadog/expected.h",
"include/datadog/http_client.h",
"include/datadog/http_endpoint_calculation_mode.h",
"include/datadog/id_generator.h",
"include/datadog/injection_options.h",
"include/datadog/logger.h",
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ target_sources(dd-trace-cpp-objects
src/datadog/collector_response.cpp
src/datadog/datadog_agent_config.cpp
src/datadog/datadog_agent.cpp
src/datadog/endpoint_inferral.cpp
src/datadog/environment.cpp
src/datadog/error.cpp
src/datadog/extraction_util.cpp
Expand Down
16 changes: 10 additions & 6 deletions bin/format
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you provide some context on why this change is needed and what problem it aims to solve?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's described in the commit message. Essentially, it doesn't work correctly on Docker desktop on mac os

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

set -e

# Determine the script directory and repository root
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)

# Go to the repository root directory.
cd "$(dirname "$0")"/..
cd "$REPO_ROOT"

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

mount_path=/mnt/host
mount_path=/mnt/repo

# File paths passed to the dockerized clang-format need to be resolved and
# prefixed with the bind mount path.
# File paths passed to the dockerized clang-format need to be relative to
# the repository root and prefixed with the bind mount path.
#
# Non-path arguments (flags) are left alone.
process_arg() {
case "$1" in
-*) printf '%s\0' "$1" ;;
*) printf '%s/%s\0' "$mount_path" "$(realpath "$1")" ;;
*) printf '%s/%s\0' "$mount_path" "$1" ;;
esac
}

Expand All @@ -65,7 +69,7 @@ docker_clang_format() {
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--user "$(id -u):$(id -g)" \
--mount "type=bind,source=/,destination=$mount_path" \
--mount "type=bind,source=$REPO_ROOT,destination=$mount_path" \
"$image" \
clang-format $formatter_options
}
Expand Down
2 changes: 2 additions & 0 deletions include/datadog/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ enum class ConfigName : char {
TRACE_BAGGAGE_MAX_BYTES,
TRACE_BAGGAGE_MAX_ITEMS,
APM_TRACING_ENABLED,
TRACE_RESOURCE_RENAMING_ENABLED,
TRACE_RESOURCE_RENAMING_ALWAYS_SIMPLIFIED_ENDPOINT,
};

// Represents metadata for configuration parameters
Expand Down
78 changes: 40 additions & 38 deletions include/datadog/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,46 @@ namespace environment {

// To enforce correspondence between `enum Variable` and `variable_names`, the
// preprocessor is used so that the DD_* symbols are listed exactly once.
#define LIST_ENVIRONMENT_VARIABLES(MACRO) \
MACRO(DD_AGENT_HOST) \
MACRO(DD_ENV) \
MACRO(DD_INSTRUMENTATION_TELEMETRY_ENABLED) \
MACRO(DD_PROPAGATION_STYLE_EXTRACT) \
MACRO(DD_PROPAGATION_STYLE_INJECT) \
MACRO(DD_REMOTE_CONFIGURATION_ENABLED) \
MACRO(DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS) \
MACRO(DD_SERVICE) \
MACRO(DD_SPAN_SAMPLING_RULES) \
MACRO(DD_SPAN_SAMPLING_RULES_FILE) \
MACRO(DD_TRACE_PROPAGATION_STYLE_EXTRACT) \
MACRO(DD_TRACE_PROPAGATION_STYLE_INJECT) \
MACRO(DD_TRACE_PROPAGATION_STYLE) \
MACRO(DD_TAGS) \
MACRO(DD_TRACE_AGENT_PORT) \
MACRO(DD_TRACE_AGENT_URL) \
MACRO(DD_TRACE_DEBUG) \
MACRO(DD_TRACE_ENABLED) \
MACRO(DD_TRACE_RATE_LIMIT) \
MACRO(DD_TRACE_REPORT_HOSTNAME) \
MACRO(DD_TRACE_SAMPLE_RATE) \
MACRO(DD_TRACE_SAMPLING_RULES) \
MACRO(DD_TRACE_STARTUP_LOGS) \
MACRO(DD_TRACE_TAGS_PROPAGATION_MAX_LENGTH) \
MACRO(DD_VERSION) \
MACRO(DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED) \
MACRO(DD_TELEMETRY_HEARTBEAT_INTERVAL) \
MACRO(DD_TELEMETRY_METRICS_ENABLED) \
MACRO(DD_TELEMETRY_METRICS_INTERVAL_SECONDS) \
MACRO(DD_TELEMETRY_DEBUG) \
MACRO(DD_TRACE_BAGGAGE_MAX_ITEMS) \
MACRO(DD_TRACE_BAGGAGE_MAX_BYTES) \
MACRO(DD_TELEMETRY_LOG_COLLECTION_ENABLED) \
MACRO(DD_INSTRUMENTATION_INSTALL_ID) \
MACRO(DD_INSTRUMENTATION_INSTALL_TYPE) \
MACRO(DD_INSTRUMENTATION_INSTALL_TIME) \
MACRO(DD_APM_TRACING_ENABLED) \
#define LIST_ENVIRONMENT_VARIABLES(MACRO) \
MACRO(DD_AGENT_HOST) \
MACRO(DD_ENV) \
MACRO(DD_INSTRUMENTATION_TELEMETRY_ENABLED) \
MACRO(DD_PROPAGATION_STYLE_EXTRACT) \
MACRO(DD_PROPAGATION_STYLE_INJECT) \
MACRO(DD_REMOTE_CONFIGURATION_ENABLED) \
MACRO(DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS) \
MACRO(DD_SERVICE) \
MACRO(DD_SPAN_SAMPLING_RULES) \
MACRO(DD_SPAN_SAMPLING_RULES_FILE) \
MACRO(DD_TRACE_PROPAGATION_STYLE_EXTRACT) \
MACRO(DD_TRACE_PROPAGATION_STYLE_INJECT) \
MACRO(DD_TRACE_PROPAGATION_STYLE) \
MACRO(DD_TAGS) \
MACRO(DD_TRACE_AGENT_PORT) \
MACRO(DD_TRACE_AGENT_URL) \
MACRO(DD_TRACE_DEBUG) \
MACRO(DD_TRACE_ENABLED) \
MACRO(DD_TRACE_RATE_LIMIT) \
MACRO(DD_TRACE_REPORT_HOSTNAME) \
MACRO(DD_TRACE_SAMPLE_RATE) \
MACRO(DD_TRACE_SAMPLING_RULES) \
MACRO(DD_TRACE_STARTUP_LOGS) \
MACRO(DD_TRACE_TAGS_PROPAGATION_MAX_LENGTH) \
MACRO(DD_VERSION) \
MACRO(DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED) \
MACRO(DD_TELEMETRY_HEARTBEAT_INTERVAL) \
MACRO(DD_TELEMETRY_METRICS_ENABLED) \
MACRO(DD_TELEMETRY_METRICS_INTERVAL_SECONDS) \
MACRO(DD_TELEMETRY_DEBUG) \
MACRO(DD_TRACE_BAGGAGE_MAX_ITEMS) \
MACRO(DD_TRACE_BAGGAGE_MAX_BYTES) \
MACRO(DD_TELEMETRY_LOG_COLLECTION_ENABLED) \
MACRO(DD_INSTRUMENTATION_INSTALL_ID) \
MACRO(DD_INSTRUMENTATION_INSTALL_TYPE) \
MACRO(DD_INSTRUMENTATION_INSTALL_TIME) \
MACRO(DD_APM_TRACING_ENABLED) \
MACRO(DD_TRACE_RESOURCE_RENAMING_ENABLED) \
MACRO(DD_TRACE_RESOURCE_RENAMING_ALWAYS_SIMPLIFIED_ENDPOINT) \
MACRO(DD_EXTERNAL_ENV)

#define WITH_COMMA(ARG) ARG,
Expand Down
1 change: 1 addition & 0 deletions include/datadog/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class HTTPClient {
std::string scheme; // http, https, or unix
std::string authority; // domain:port or /path/to/socket
std::string path; // resource, e.g. /v0.4/traces
std::string query; // query string without '?'

static Expected<HTTPClient::URL> parse(StringView input);
};
Expand Down
34 changes: 34 additions & 0 deletions include/datadog/http_endpoint_calculation_mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

// This component provides an enumeration that controls how the http.endpoint
// tag is calculated for HTTP spans.

#include <cstdint>

namespace datadog {
namespace tracing {

// `HttpEndpointCalculationMode` determines when and how the http.endpoint tag
// is inferred from http.url for HTTP spans.
//
// The http.endpoint tag provides a normalized, parameterized version of the
// HTTP path (e.g., "/users/{param:int}" instead of "/users/123"). This helps
// aggregate similar requests and reduce cardinality in monitoring systems.
enum class HttpEndpointCalculationMode : std::uint8_t {
// Do not calculate http.endpoint. The tag will not be set unless explicitly
// provided by the user.
DISABLED,

// Calculate http.endpoint from http.url only when http.route is not present.
// This mode acts as a fallback - if instrumentation provides http.route,
// use that; otherwise, infer http.endpoint from the URL path.
FALLBACK,

// Always calculate http.endpoint from http.url, even when http.route is
// present. Both tags will be set, allowing for comparison between
// user-provided routes and automatically inferred endpoints.
ALWAYS_CALCULATE,
};

} // namespace tracing
} // namespace datadog
4 changes: 4 additions & 0 deletions include/datadog/trace_segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "runtime_id.h"
#include "sampling_decision.h"
#include "sampling_priority.h"
#include "tracer_config.h"

namespace datadog {
namespace telemetry {
Expand Down Expand Up @@ -79,6 +80,8 @@ class TraceSegment {

std::shared_ptr<ConfigManager> config_manager_;

HttpEndpointCalculationMode resource_renaming_mode_;

bool tracing_enabled_;

public:
Expand All @@ -97,6 +100,7 @@ class TraceSegment {
Optional<std::string> additional_w3c_tracestate,
Optional<std::string> additional_datadog_w3c_tracestate,
std::unique_ptr<SpanData> local_root,
HttpEndpointCalculationMode resource_renaming_mode,
bool tracing_enabled = true);

const SpanDefaults& defaults() const;
Expand Down
1 change: 1 addition & 0 deletions include/datadog/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Tracer {
bool baggage_injection_enabled_;
bool baggage_extraction_enabled_;
bool tracing_enabled_;
HttpEndpointCalculationMode resource_renaming_mode_;

public:
// Create a tracer configured using the specified `config`, and optionally:
Expand Down
11 changes: 11 additions & 0 deletions include/datadog/tracer_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "clock.h"
#include "datadog_agent_config.h"
#include "expected.h"
#include "http_endpoint_calculation_mode.h"
#include "propagation_style.h"
#include "runtime_id.h"
#include "span_defaults.h"
Expand Down Expand Up @@ -178,6 +179,15 @@ struct TracerConfig {
/// Overridden by the `DD_APM_TRACING_ENABLED` environment variable. Defaults
/// to `true`.
Optional<bool> tracing_enabled;

// Whether generation of http.endpoint is enabled. This is disabled by
// default.
Optional<bool> resource_renaming_enabled;

// Whether http.endpoint is always calculated, even when http.route is
// present. This is disabled by default.
// This option is ignored if `resource_renaming_enabled` is not `true`.
Optional<bool> resource_renaming_always_simplified_endpoint;
};

// `FinalizedTracerConfig` contains `Tracer` implementation details derived from
Expand Down Expand Up @@ -218,6 +228,7 @@ class FinalizedTracerConfig final {
std::shared_ptr<EventScheduler> event_scheduler;
std::shared_ptr<HTTPClient> http_client;
bool tracing_enabled;
HttpEndpointCalculationMode resource_renaming_mode;
};

// Return a `FinalizedTracerConfig` from the specified `config` and from any
Expand Down
Loading