Skip to content

feat(tracer): add whole trace id to pprof labels and enable them with appsec#5064

Open
eliottness wants to merge 2 commits into
mainfrom
eliottness/pprof-propagation
Open

feat(tracer): add whole trace id to pprof labels and enable them with appsec#5064
eliottness wants to merge 2 commits into
mainfrom
eliottness/pprof-propagation

Conversation

@eliottness

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds the full 128-bit trace ID as a new trace id pprof label so the continuous
profiler can correlate samples with the whole trace, not just the local root span.

  • New label constant traceprof.TraceID = "trace id", encoded as the whole
    128-bit trace ID in 32-character lowercase hex (unlike the existing 64-bit
    decimal span id / local root span id).
  • trace id and local root span id are now emitted for code hotspots and
    whenever AppSec is enabled, so AppSec can correlate security events with
    traces/profiles. span id stays gated behind code hotspots and trace endpoint
    behind endpoint profiling.
  • The gate was moved into applyPPROFLabels so appsec.Enabled() is evaluated at
    most once per span start (and not at all in the default hotspots-on path, thanks
    to short-circuiting). Label keys remain in alphabetical order for the go1.24
    label optimization.

Motivation

Today the pprof labels emitted by the tracer only carry the 64-bit span id and
local root span id. With 128-bit trace IDs, profiler samples cannot be tied to
the whole trace ID, and AppSec has no trace-correlation labels unless the
profiler's code-hotspots feature happens to be enabled. This change makes the full
trace ID available and ensures the correlation labels are present when AppSec is
on.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running make lint locally.
  • New code doesn't break existing tests. You can check this by running make test locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • All generated files are up to date. You can check this by running make generate locally.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running make fix-modules locally.

Note

No new/proven backend pprof contract exists yet for a trace id label across
Datadog tracers; the profiler backend must be set up to read trace id before
relying on it for correlation. Value is high-cardinality (unique per trace),
emitted only under the same gates as the existing correlation labels.

Emit the full 128-bit trace id (32-char lowercase hex) as a new "trace id"
pprof label so profiler samples can be correlated with the whole trace, not
just the local root span.

The "trace id" and "local root span id" labels are now emitted for code
hotspots and whenever AppSec is enabled, so AppSec can correlate security
events with traces/profiles. "span id" stays gated behind code hotspots and
"trace endpoint" behind endpoint profiling.
@github-actions

Copy link
Copy Markdown
Contributor

Config Audit

PACKAGE: contrib/cloud.google.com/go/pubsubtrace
  STATUS      CONFIG                                            CALL_SITES
  UNMIGRATED  DD_GOOGLE_CLOUD_PUBSUB_PROPAGATION_AS_SPAN_LINKS  1

PACKAGE: contrib/confluentinc/confluent-kafka-go/kafkatrace
  STATUS      CONFIG                            CALL_SITES
  UNMIGRATED  DD_TRACE_KAFKA_ANALYTICS_ENABLED  1

PACKAGE: ddtrace/opentelemetry/log
  STATUS      CONFIG                            CALL_SITES
  STILL_READ  DD_AGENT_HOST                     2
  STILL_READ  DD_ENV                            1
  STILL_READ  DD_SERVICE                        1
  STILL_READ  DD_TAGS                           1
  STILL_READ  DD_TRACE_AGENT_URL                2
  STILL_READ  DD_TRACE_REPORT_HOSTNAME          1
  STILL_READ  DD_VERSION                        1
  STILL_READ  OTEL_EXPORTER_OTLP_ENDPOINT       4
  STILL_READ  OTEL_EXPORTER_OTLP_HEADERS        2
  UNMIGRATED  DD_HOSTNAME                       1
  UNMIGRATED  OTEL_BLRP_EXPORT_TIMEOUT          1
  UNMIGRATED  OTEL_BLRP_MAX_EXPORT_BATCH_SIZE   1
  UNMIGRATED  OTEL_BLRP_MAX_QUEUE_SIZE          1
  UNMIGRATED  OTEL_BLRP_SCHEDULE_DELAY          1
  UNMIGRATED  OTEL_EXPORTER_OTLP_LOGS_ENDPOINT  4
  UNMIGRATED  OTEL_EXPORTER_OTLP_LOGS_HEADERS   2
  UNMIGRATED  OTEL_EXPORTER_OTLP_LOGS_PROTOCOL  2
  UNMIGRATED  OTEL_EXPORTER_OTLP_LOGS_TIMEOUT   1
  UNMIGRATED  OTEL_EXPORTER_OTLP_PROTOCOL       2
  UNMIGRATED  OTEL_EXPORTER_OTLP_TIMEOUT        1
  UNMIGRATED  OTEL_RESOURCE_ATTRIBUTES          1

PACKAGE: ddtrace/opentelemetry/metric
  STATUS      CONFIG                                             CALL_SITES
  STILL_READ  DD_AGENT_HOST                                      2
  STILL_READ  DD_ENV                                             1
  STILL_READ  DD_METRICS_OTEL_ENABLED                            1
  STILL_READ  DD_SERVICE                                         1
  STILL_READ  DD_TAGS                                            1
  STILL_READ  DD_TRACE_AGENT_URL                                 2
  STILL_READ  DD_TRACE_REPORT_HOSTNAME                           1
  STILL_READ  DD_VERSION                                         1
  STILL_READ  OTEL_EXPORTER_OTLP_ENDPOINT                        2
  STILL_READ  OTEL_EXPORTER_OTLP_HEADERS                         1
  STILL_READ  OTEL_EXPORTER_OTLP_METRICS_ENDPOINT                2
  STILL_READ  OTEL_EXPORTER_OTLP_METRICS_HEADERS                 1
  STILL_READ  OTEL_METRICS_EXPORTER                              1
  UNMIGRATED  DD_HOSTNAME                                        1
  UNMIGRATED  OTEL_EXPORTER_OTLP_METRICS_PROTOCOL                2
  UNMIGRATED  OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE  1
  UNMIGRATED  OTEL_EXPORTER_OTLP_PROTOCOL                        2
  UNMIGRATED  OTEL_EXPORTER_OTLP_TIMEOUT                         1
  UNMIGRATED  OTEL_RESOURCE_ATTRIBUTES                           1
  UNMIGRATED  OTEL_SERVICE_NAME                                  1

PACKAGE: ddtrace/tracer
  STATUS      CONFIG                                    CALL_SITES
  STILL_READ  DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT     1
  STILL_READ  DD_TRACE_PROPAGATION_EXTRACT_FIRST        1
  STILL_READ  DD_TRACE_PROPAGATION_STYLE_EXTRACT        1
  STILL_READ  DD_TRACE_PROPAGATION_STYLE_INJECT         1
  UNMIGRATED  DD_APM_TRACING_ENABLED                    1
  UNMIGRATED  DD_LLMOBS_AGENTLESS_ENABLED               1
  UNMIGRATED  DD_LLMOBS_ENABLED                         1
  UNMIGRATED  DD_LLMOBS_ML_APP                          1
  UNMIGRATED  DD_LLMOBS_PROJECT_NAME                    1
  UNMIGRATED  DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED  1
  UNMIGRATED  DD_TRACE_DEBUG_SEELOG_WORKAROUND          1
  UNMIGRATED  OTEL_TRACES_SAMPLER_ARG                   1

PACKAGE: instrumentation
  STATUS      CONFIG                                       CALL_SITES
  STILL_READ  DD_DATA_STREAMS_ENABLED                      1
  UNMIGRATED  DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED  1

PACKAGE: instrumentation/graphql
  STATUS      CONFIG                             CALL_SITES
  UNMIGRATED  DD_TRACE_GRAPHQL_ERROR_EXTENSIONS  1

PACKAGE: instrumentation/httptrace
  STATUS      CONFIG                                                 CALL_SITES
  UNMIGRATED  DD_GOOGLE_CLOUD_PUBSUB_PROPAGATION_AS_SPAN_LINKS       1
  UNMIGRATED  DD_TRACE_BAGGAGE_TAG_KEYS                              1
  UNMIGRATED  DD_TRACE_CLIENT_IP_ENABLED                             1
  UNMIGRATED  DD_TRACE_HTTP_SERVER_ERROR_STATUSES                    1
  UNMIGRATED  DD_TRACE_HTTP_URL_QUERY_STRING_ALLOWLIST               1
  UNMIGRATED  DD_TRACE_HTTP_URL_QUERY_STRING_ALLOWLIST_CLIENT        1
  UNMIGRATED  DD_TRACE_HTTP_URL_QUERY_STRING_ALLOWLIST_SERVER        1
  UNMIGRATED  DD_TRACE_HTTP_URL_QUERY_STRING_DISABLED                1
  UNMIGRATED  DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED               1
  UNMIGRATED  DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP               2
  UNMIGRATED  DD_TRACE_RESOURCE_RENAMING_ALWAYS_SIMPLIFIED_ENDPOINT  1
  UNMIGRATED  DD_TRACE_RESOURCE_RENAMING_ENABLED                     1

PACKAGE: instrumentation/internal/namingschema
  STATUS      CONFIG                                             CALL_SITES
  STILL_READ  DD_SERVICE                                         1
  STILL_READ  DD_TRACE_SPAN_ATTRIBUTE_SCHEMA                     1
  UNMIGRATED  DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED  1

PACKAGE: internal
  STATUS      CONFIG                         CALL_SITES
  STILL_READ  DD_AGENT_HOST                  1
  STILL_READ  DD_TAGS                        1
  STILL_READ  DD_TRACE_AGENT_PORT            1
  STILL_READ  DD_TRACE_AGENT_URL             1
  UNMIGRATED  DD_EXTERNAL_ENV                1
  UNMIGRATED  DD_GIT_COMMIT_SHA              1
  UNMIGRATED  DD_GIT_REPOSITORY_URL          1
  UNMIGRATED  DD_TRACE_GIT_METADATA_ENABLED  1

PACKAGE: internal/appsec
  STATUS      CONFIG           CALL_SITES
  UNMIGRATED  DD_APPSEC_RULES  1

PACKAGE: internal/appsec/config
  STATUS      CONFIG                                                CALL_SITES
  UNMIGRATED  DD_API_SECURITY_DOWNSTREAM_BODY_ANALYSIS_SAMPLE_RATE  1
  UNMIGRATED  DD_API_SECURITY_ENABLED                               1
  UNMIGRATED  DD_API_SECURITY_MAX_DOWNSTREAM_REQUEST_BODY_ANALYSIS  1
  UNMIGRATED  DD_API_SECURITY_PROXY_SAMPLE_RATE                     1
  UNMIGRATED  DD_API_SECURITY_REQUEST_SAMPLE_RATE                   1
  UNMIGRATED  DD_API_SECURITY_SAMPLE_DELAY                          1
  UNMIGRATED  DD_APM_TRACING_ENABLED                                1
  UNMIGRATED  DD_APPSEC_AGENTIC_ONBOARDING                          1
  UNMIGRATED  DD_APPSEC_ENABLED                                     1
  UNMIGRATED  DD_APPSEC_RASP_ENABLED                                1
  UNMIGRATED  DD_APPSEC_RULES                                       1
  UNMIGRATED  DD_APPSEC_SCA_ENABLED                                 1
  UNMIGRATED  DD_APPSEC_TRACE_RATE_LIMIT                            1
  UNMIGRATED  DD_APPSEC_WAF_TIMEOUT                                 1

PACKAGE: internal/appsec/listener/httpsec
  STATUS      CONFIG                     CALL_SITES
  UNMIGRATED  DD_TRACE_CLIENT_IP_HEADER  1

PACKAGE: internal/bazel
  STATUS      CONFIG                                  CALL_SITES
  UNMIGRATED  DD_TEST_OPTIMIZATION_MANIFEST_FILE      1
  UNMIGRATED  DD_TEST_OPTIMIZATION_PAYLOADS_IN_FILES  1

PACKAGE: internal/civisibility/envconfig
  STATUS      CONFIG                   CALL_SITES
  STILL_READ  DD_CIVISIBILITY_ENABLED  1

PACKAGE: internal/civisibility/integrations
  STATUS      CONFIG                                               CALL_SITES
  STILL_READ  DD_SERVICE                                           1
  STILL_READ  DD_TRACE_DEBUG                                       1
  UNMIGRATED  DD_CIVISIBILITY_CODE_COVERAGE_REPORT_UPLOAD_ENABLED  1
  UNMIGRATED  DD_CIVISIBILITY_FLAKY_RETRY_COUNT                    1
  UNMIGRATED  DD_CIVISIBILITY_FLAKY_RETRY_ENABLED                  1
  UNMIGRATED  DD_CIVISIBILITY_GIT_UPLOAD_ENABLED                   1
  UNMIGRATED  DD_CIVISIBILITY_IMPACTED_TESTS_DETECTION_ENABLED     1
  UNMIGRATED  DD_CIVISIBILITY_SUBTEST_FEATURES_ENABLED             1
  UNMIGRATED  DD_CIVISIBILITY_TOTAL_FLAKY_RETRY_COUNT              1
  UNMIGRATED  DD_TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES            1
  UNMIGRATED  DD_TEST_MANAGEMENT_ENABLED                           1

PACKAGE: internal/civisibility/integrations/gotesting
  STATUS      CONFIG                                                           CALL_SITES
  UNMIGRATED  DD_CIVISIBILITY_INTERNAL_PARALLEL_EARLY_FLAKE_DETECTION_ENABLED  1
  UNMIGRATED  DD_TEST_MANAGEMENT_ENABLED                                       1

PACKAGE: internal/civisibility/integrations/logs
  STATUS      CONFIG                        CALL_SITES
  UNMIGRATED  DD_CIVISIBILITY_LOGS_ENABLED  1

PACKAGE: internal/civisibility/utils
  STATUS      CONFIG                              CALL_SITES
  STILL_READ  DD_SERVICE                          1
  UNMIGRATED  DD_ACTION_EXECUTION_ID              1
  UNMIGRATED  DD_PIPELINE_EXECUTION_ID            1
  UNMIGRATED  DD_TEST_OPTIMIZATION_ENV_DATA_FILE  1
  UNMIGRATED  DD_TEST_SESSION_NAME                1

PACKAGE: internal/civisibility/utils/net
  STATUS      CONFIG                             CALL_SITES
  STILL_READ  DD_API_KEY                         1
  STILL_READ  DD_CIVISIBILITY_AGENTLESS_ENABLED  1
  STILL_READ  DD_CIVISIBILITY_AGENTLESS_URL      1
  STILL_READ  DD_ENV                             1
  STILL_READ  DD_SERVICE                         1
  STILL_READ  DD_SITE                            1
  STILL_READ  DD_TAGS                            1
  STILL_READ  DD_VERSION                         1
  UNMIGRATED  DD_CODE_COVERAGE_FLAGS             1

PACKAGE: internal/civisibility/utils/telemetry
  STATUS      CONFIG                                         CALL_SITES
  UNMIGRATED  DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER  1

PACKAGE: internal/globalconfig
  STATUS      CONFIG                           CALL_SITES
  UNMIGRATED  DD_INSTRUMENTATION_INSTALL_ID    1
  UNMIGRATED  DD_INSTRUMENTATION_INSTALL_TIME  1
  UNMIGRATED  DD_INSTRUMENTATION_INSTALL_TYPE  1

PACKAGE: internal/hostname
  STATUS      CONFIG       CALL_SITES
  UNMIGRATED  DD_HOSTNAME  1

PACKAGE: internal/namingschema
  STATUS      CONFIG                                             CALL_SITES
  STILL_READ  DD_SERVICE                                         1
  STILL_READ  DD_TRACE_SPAN_ATTRIBUTE_SCHEMA                     1
  UNMIGRATED  DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED  1

PACKAGE: internal/processtags
  STATUS      CONFIG                                          CALL_SITES
  UNMIGRATED  DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED  1

PACKAGE: internal/remoteconfig
  STATUS      CONFIG                                  CALL_SITES
  STILL_READ  DD_ENV                                  1
  UNMIGRATED  DD_RC_TUF_ROOT                          1
  UNMIGRATED  DD_REMOTE_CONFIGURATION_ENABLED         1
  UNMIGRATED  DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS  1

PACKAGE: internal/stacktrace
  STATUS      CONFIG                           CALL_SITES
  UNMIGRATED  DD_APPSEC_MAX_STACK_TRACE_DEPTH  1
  UNMIGRATED  DD_APPSEC_STACK_TRACE_ENABLED    1

PACKAGE: internal/telemetry
  STATUS      CONFIG                                             CALL_SITES
  STILL_READ  DD_API_KEY                                         1
  STILL_READ  DD_SITE                                            1
  UNMIGRATED  DD_API_SECURITY_ENDPOINT_COLLECTION_MESSAGE_LIMIT  1
  UNMIGRATED  DD_INSTRUMENTATION_TELEMETRY_ENABLED               1
  UNMIGRATED  DD_TELEMETRY_DEBUG                                 1
  UNMIGRATED  DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED         1
  UNMIGRATED  DD_TELEMETRY_EXTENDED_HEARTBEAT_INTERVAL           1
  UNMIGRATED  DD_TELEMETRY_HEARTBEAT_INTERVAL                    1
  UNMIGRATED  DD_TELEMETRY_LOG_COLLECTION_ENABLED                1
  UNMIGRATED  DD_TELEMETRY_METRICS_ENABLED                       1

PACKAGE: openfeature
  STATUS      CONFIG                                                     CALL_SITES
  STILL_READ  DD_ENV                                                     2
  STILL_READ  DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED                  1
  STILL_READ  DD_SERVICE                                                 2
  STILL_READ  DD_VERSION                                                 2
  UNMIGRATED  DD_EXPERIMENTAL_FLAGGING_PROVIDER_SPAN_ENRICHMENT_ENABLED  1
  UNMIGRATED  DD_FLAGGING_EVALUATION_COUNTS_ENABLED                      1

PACKAGE: profiler
  STATUS      CONFIG                                    CALL_SITES
  STILL_READ  DD_API_KEY                                1
  STILL_READ  DD_ENV                                    1
  STILL_READ  DD_SERVICE                                1
  STILL_READ  DD_SITE                                   1
  STILL_READ  DD_TAGS                                   1
  STILL_READ  DD_TRACE_STARTUP_LOGS                     1
  STILL_READ  DD_VERSION                                1
  UNMIGRATED  DD_PROFILING_AGENTLESS                    1
  UNMIGRATED  DD_PROFILING_DEBUG_COMPRESSION_SETTINGS   1
  UNMIGRATED  DD_PROFILING_DELTA                        1
  UNMIGRATED  DD_PROFILING_ENABLED                      3
  UNMIGRATED  DD_PROFILING_ENDPOINT_COUNT_ENABLED       1
  UNMIGRATED  DD_PROFILING_EXECUTION_TRACE_ENABLED      1
  UNMIGRATED  DD_PROFILING_EXECUTION_TRACE_LIMIT_BYTES  1
  UNMIGRATED  DD_PROFILING_EXECUTION_TRACE_PERIOD       1
  UNMIGRATED  DD_PROFILING_FLUSH_ON_EXIT                1
  UNMIGRATED  DD_PROFILING_OUTPUT_DIR                   1
  UNMIGRATED  DD_PROFILING_UPLOAD_TIMEOUT               1
  UNMIGRATED  DD_PROFILING_URL                          1

@datadog-official

datadog-official Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 62.86% (+11.45%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 679beae | Docs | Datadog PR Page | Give us feedback!

@pr-commenter

pr-commenter Bot commented Jul 24, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-24 11:35:06

Comparing candidate commit 679beae in PR branch eliottness/pprof-propagation with baseline commit 0923b84 in branch main.

Found 2 performance improvements and 18 performance regressions! Performance is the same for 306 metrics, 0 unstable metrics, 1 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:BenchmarkHttpServeTraceQueryObfuscation/really_long_1

  • 🟥 execution_time [+541.666ns; +1247.134ns] or [+2.456%; +5.655%]

scenario:BenchmarkHttpServeTraceQueryObfuscation/really_long_2

  • 🟥 execution_time [+553.662ns; +1361.538ns] or [+2.548%; +6.267%]

scenario:BenchmarkInjectW3C

  • 🟩 allocated_mem [-64 bytes; -64 bytes] or [-6.015%; -6.015%]
  • 🟩 allocations [-2; -2] or [-22.222%; -22.222%]

scenario:BenchmarkOTLPProtoSize/1000spans

  • 🟥 execution_time [+16.816µs; +17.918µs] or [+5.392%; +5.745%]

scenario:BenchmarkOTLPProtoSize/100spans

  • 🟥 execution_time [+1.812µs; +1.924µs] or [+5.852%; +6.213%]

scenario:BenchmarkOTLPProtoSize/10spans

  • 🟥 execution_time [+202.499ns; +214.101ns] or [+6.440%; +6.809%]

scenario:BenchmarkOTLPProtoSize/1span

  • 🟥 execution_time [+30.390ns; +31.750ns] or [+8.014%; +8.373%]

scenario:BenchmarkPartialFlushing/Disabled

  • 🟥 allocated_mem [+5.967MB; +6.431MB] or [+3.130%; +3.373%]

scenario:BenchmarkPartialFlushing/Enabled

  • 🟥 allocated_mem [+5.270MB; +7.385MB] or [+2.918%; +4.089%]

scenario:BenchmarkSingleSpanRetention/no-rules

  • 🟥 allocated_mem [+6.432KB; +6.433KB] or [+3.964%; +3.965%]
  • 🟥 execution_time [+7.962µs; +11.008µs] or [+2.619%; +3.621%]

scenario:BenchmarkSingleSpanRetention/with-rules/match-all

  • 🟥 allocated_mem [+6.419KB; +6.439KB] or [+3.953%; +3.966%]

scenario:BenchmarkSingleSpanRetention/with-rules/match-half

  • 🟥 allocated_mem [+6.409KB; +6.437KB] or [+3.947%; +3.964%]

scenario:BenchmarkStartSpan

  • 🟥 allocated_mem [+64 bytes; +64 bytes] or [+3.993%; +3.993%]
  • 🟥 execution_time [+43.908ns; +64.292ns] or [+2.291%; +3.355%]

scenario:BenchmarkStartSpanConfig/scenario_WithStartSpanConfig

  • 🟥 allocated_mem [+64 bytes; +64 bytes] or [+3.150%; +3.150%]
  • 🟥 allocations [+1; +1] or [+5.882%; +5.882%]

scenario:BenchmarkStartSpanConfig/scenario_none

  • 🟥 allocated_mem [+64 bytes; +64 bytes] or [+2.703%; +2.703%]
  • 🟥 allocations [+1; +1] or [+5.263%; +5.263%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

Known flaky benchmarks without significant changes:

  • scenario:BenchmarkOTLPTraceWriterFlush

@eliottness
eliottness marked this pull request as ready for review July 24, 2026 10:11
@eliottness
eliottness requested review from a team as code owners July 24, 2026 10:11
@kakkoyun

Copy link
Copy Markdown
Member

Ouch!

Benchmarks

scenario:BenchmarkOTLPProtoSize/1000spans

  • 🟥 execution_time [+17.121µs; +18.715µs] or [+5.497%; +6.008%]

scenario:BenchmarkOTLPProtoSize/100spans

  • 🟥 execution_time [+1.692µs; +1.884µs] or [+5.459%; +6.078%]

scenario:BenchmarkOTLPProtoSize/10spans

  • 🟥 execution_time [+192.071ns; +214.929ns] or [+6.096%; +6.821%]

scenario:BenchmarkOTLPProtoSize/1span

  • 🟥 execution_time [+29.845ns; +32.075ns] or [+7.859%; +8.446%]

scenario:BenchmarkOTelApiWithCustomTags/datadog_otel_api

  • 🟥 allocated_mem [+59 bytes; +67 bytes] or [+2.379%; +2.684%]
  • 🟥 allocations [+1; +1] or [+4.000%; +4.000%]

scenario:BenchmarkOTelApiWithCustomTags/otel_api

  • 🟥 allocations [+1; +1] or [+2.500%; +2.500%]

scenario:BenchmarkPartialFlushing/Disabled

  • 🟥 allocated_mem [+9.576MB; +10.205MB] or [+5.031%; +5.362%]
  • 🟥 allocations [+100009; +100017] or [+7.688%; +7.689%]
  • 🟥 execution_time [+8.391ms; +14.004ms] or [+2.122%; +3.541%]

scenario:BenchmarkPartialFlushing/Enabled

  • 🟥 allocated_mem [+7.749MB; +10.175MB] or [+4.283%; +5.624%]
  • 🟥 allocations [+100004; +100020] or [+7.676%; +7.677%]
  • 🟥 execution_time [+8.685ms; +15.688ms] or [+2.248%; +4.061%]

scenario:BenchmarkPayloadVersions/detailed_1spans/v1.0

  • 🟥 execution_time [+27.562ns; +50.638ns] or [+2.175%; +3.995%]

scenario:BenchmarkPayloadVersions/simple_1000spans/v1.0

  • 🟥 allocated_mem [+1 bytes; +1 bytes] or [+2.941%; +2.941%]

scenario:BenchmarkSingleSpanRetention/no-rules

  • 🟥 allocated_mem [+9.665KB; +9.665KB] or [+5.956%; +5.957%]
  • 🟥 allocations [+101; +101] or [+7.640%; +7.640%]
  • 🟥 execution_time [+11.564µs; +15.341µs] or [+3.810%; +5.054%]

scenario:BenchmarkSingleSpanRetention/with-rules/match-all

  • 🟥 allocated_mem [+9.653KB; +9.675KB] or [+5.945%; +5.959%]
  • 🟥 allocations [+101; +101] or [+7.640%; +7.640%]
  • 🟥 execution_time [+9.541µs; +15.102µs] or [+2.828%; +4.476%]

scenario:BenchmarkSingleSpanRetention/with-rules/match-half

  • 🟥 allocated_mem [+9.651KB; +9.681KB] or [+5.944%; +5.962%]
  • 🟥 allocations [+101; +101] or [+7.640%; +7.640%]
  • 🟥 execution_time [+9.241µs; +14.786µs] or [+2.729%; +4.367%]

scenario:BenchmarkStartSpan

  • 🟥 allocated_mem [+95 bytes; +96 bytes] or [+5.985%; +6.018%]
  • 🟥 allocations [+1; +1] or [+6.667%; +6.667%]
  • 🟥 execution_time [+105.040ns; +130.560ns] or [+5.509%; +6.847%]

scenario:BenchmarkStartSpanConfig/scenario_WithStartSpanConfig

  • 🟥 allocated_mem [+64 bytes; +64 bytes] or [+3.150%; +3.150%]
  • 🟥 allocations [+1; +1] or [+5.882%; +5.882%]

scenario:BenchmarkStartSpanConfig/scenario_none

  • 🟥 allocated_mem [+64 bytes; +64 bytes] or [+2.703%; +2.703%]
  • 🟥 allocations [+1; +1] or [+5.263%; +5.263%]

scenario:BenchmarkTracerAddSpans

  • 🟥 allocated_mem [+64 bytes; +64 bytes] or [+2.658%; +2.658%]
  • 🟥 allocations [+1; +1] or [+5.000%; +5.000%]

@eliottness eliottness changed the title feat(tracer): add whole trace id to pprof labels feat(tracer): add whole trace id to pprof labels and enable them with appsec Jul 24, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ae25f6e5ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddtrace/tracer/tracer.go
func (t *tracer) applyPPROFLabels(ctx gocontext.Context, span *Span, snap internalconfig.SpanStartSnapshot) {
// "local root span id" and "trace id" are emitted for code hotspots and when
// AppSec is enabled, so it can correlate security events with traces/profiles.
correlate := snap.ProfilerHotspotsEnabled || appsec.Enabled()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep AppSec correlation from enabling endpoint labels

When AppSec is enabled while endpoint profiling is explicitly off, this makes correlate true and applyPPROFLabels now stores a non-nil pprofCtxActive. Later, Span.SetTag(ext.ResourceName, ...) only checks s.pprofCtxActive != nil before adding traceprof.TraceEndpoint (span.go:490-498), so web/custom spans that update their resource after start begin emitting trace endpoint labels even with WithProfilerEndpoints(false). Please keep an explicit endpoints-enabled state for that update path or avoid creating endpoint labels unless endpoint profiling was enabled.

Useful? React with 👍 / 👎.

Comment thread ddtrace/tracer/tracer.go
func (t *tracer) applyPPROFLabels(ctx gocontext.Context, span *Span, snap internalconfig.SpanStartSnapshot) {
// "local root span id" and "trace id" are emitted for code hotspots and when
// AppSec is enabled, so it can correlate security events with traces/profiles.
correlate := snap.ProfilerHotspotsEnabled || appsec.Enabled()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Don't clear user pprof labels in AppSec-only spans

When AppSec is enabled with both profiler label features disabled, correlate becomes true for root spans created via StartSpan without a context; those roots use context.Background() as their restore context, so starting the span replaces any existing goroutine pprof labels and Finish restores the background labels, clearing user labels that previously survived when hotspots/endpoints were off. Please avoid applying AppSec correlation labels without a real caller context, or preserve/restore the existing labels.

Useful? React with 👍 / 👎.

Comment thread ddtrace/tracer/tracer.go Outdated
}
}
if correlate {
labels = append(labels, traceprof.TraceID, span.context.TraceID())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid per-span trace ID encoding on the hot path

With code hotspots defaulting on, this calls span.context.TraceID() for every started span. For locally-created spans, the trace ID cache is intentionally empty and HexEncoded recomputes/allocates on each call (spancontext.go:53-68, spancontext.go:323-331), so a trace with many child spans now pays a duplicate 128-bit hex encoding allocation for every span even though they share the same trace ID. Please cache/reuse the trace label value per trace or otherwise avoid adding this allocation to every StartSpan.

Useful? React with 👍 / 👎.

The new pprof "trace id" label added a per-span hex.EncodeToString allocation
(+1 alloc/span on BenchmarkStartSpan and other span-creation benchmarks).

Every span in a trace shares the same trace id, so compute the 32-char hex once
and let child spans reuse the parent's cached string: hexEncodedCached memoizes
the hex on the not-yet-shared SpanContext during StartSpan, and newSpanContext
copies the parent's cached hex into the child (guarded by a full trace-id
equality check). The read path (HexEncoded, used by Inject) still never writes,
so the v2.8.0-rc.2 concurrent-Inject data race cannot reoccur.

benchstat (count=10): allocs/op 16 -> 15, B/op -1.84% on
BenchmarkStartSpan / BenchmarkStartSpanConcurrent.
@eliottness

Copy link
Copy Markdown
Contributor Author

@kakkoyun the +1 alloc was the per-span trace-id hex encode — it's now computed once per trace and reused by child spans (679beae44), bringing BenchmarkStartSpan back to 15 allocs/op, so the next benchmark run should be clean. 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants