← Back to Pull requests

feat: agentless log submission #22141

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 26, 2026 18:18 UTC
Author

Description

DD_AGENTLESS_LOG_SUBMISSION_ENABLED only worked inside the Test Optimization pytest plugin. Services that cannot reach a Datadog Agent had to set up the OpenTelemetry logs exporter (extra packages and several settings) to ship logs, while dd-trace-js needs only this variable and DD_API_KEY.

In agentless mode (DD_AGENTLESS_ENABLED=true with DD_API_KEY), the bootstrap (ddtrace-run / import ddtrace.auto) now submits every logging record that propagates to the root logger. Records are batched and posted gzipped to https://http-intake.logs.<DD_SITE>/api/v2/logs, with service, env, version, hostname, tags, the traceback when present, and dd.trace_id / dd.span_id from the logging integration.

  • One switch, like the other agentless products and dd-trace-js: DD_AGENTLESS_ENABLED turns log submission on, and DD_AGENTLESS_LOG_SUBMISSION_ENABLED is its per-product override: false opts out, true submits logs without making anything else agentless (it previously only applied to the Test Optimization plugin). Without DD_API_KEY, a warning is logged and nothing is submitted.

  • Behavior change: applications already running with DD_AGENTLESS_ENABLED=true start shipping their logs, and so do agentless Test Optimization sessions (called out in the upgrade release note).

  • OpenTelemetry, as in dd-trace-js: with DD_LOGS_OTEL_ENABLED, the global switch leaves logs to OpenTelemetry (which then exports them agentlessly), in services and in the Test Optimization plugin alike; an explicit DD_AGENTLESS_LOG_SUBMISSION_ENABLED=true wins and turns OpenTelemetry log export off with a startup warning, once the API key and intake URL are known to be valid.

  • Logging configuration is untouched. No handler is added: records are picked up by wrapping logging.Logger.callHandlers, so lastResort stderr output, basicConfig() and dictConfig/fileConfig behave as without the tracer. Records are not modified either: tracebacks are formatted on a copy, so the application's own exception formatting (for example redaction) is unaffected.

  • Test Optimization sessions are unchanged. Under ddtrace-run pytest, the plugin turns APM submission off before conftests load and discards anything buffered; test logs go only through the plugin, as before.

  • Limits: requests stay within the intake's 1000 entries and 5MB, messages are truncated at 1MB of UTF-8, and the buffer is capped at 10k events. Submission is best-effort: rejected or failed batches are dropped, without retries.

  • Exit and fork handling: pending records are sent at a normal exit and when multiprocessing workers finish normally (they leave through os._exit()), within one 1s deadline, covering encoding as well as sending, so a slow or unreachable intake or a large backlog can't hold up the exit. Nothing runs from signal handlers: a process ended by a signal, os._exit() or Pool.terminate() (with Pool()) loses unsent records, as documented, rather than delaying its shutdown or the tracer's. Forked children don't resend the parent's buffer.

  • uWSGI: in a preloaded uWSGI master that forks without Python's fork hooks, the writer starts in each worker instead, as the products manager defers its own startup, so no thread runs in the master at fork time.

  • Service, env, version and tags are read for every record, so logs keep matching their traces when the application changes them after startup (e.g. LLMObs.enable(service=...)).

  • Adds DD_AGENTLESS_LOG_SUBMISSION_URL to override the intake URL, mainly for testing (dd-trace-js has it too).
  • Stacked on #22182 (base gnufede/log-intake-shared), which adds the shared, tracer-independent logs-intake writer and handler (ddtrace.internal.log_intake) and moves Test Optimization and LLMObs onto it. This PR only adds the tracer-side wiring (ddtrace.internal.logs) and a small ddtrace.internal.settings._log_submission module that decides whether submission applies, so the Test Optimization plugin uses the same rule without importing the tracer.

    Customer impact

    Services without a reachable Datadog Agent get their Python logs shipped by the same DD_AGENTLESS_ENABLED=true and DD_API_KEY that make the rest of the SDK agentless, as in dd-trace-js, instead of configuring the OpenTelemetry logs exporter. DD_AGENTLESS_LOG_SUBMISSION_ENABLED=false opts out. Test Optimization logs now include tracebacks. Release notes are included.

    Testing

  • tests/internal/test_logs.py (new) covers the writer (batching, limits, UTF-8 encoding, errors), the handler payload, the startup warnings, and end-to-end ddtrace-run runs against a local intake for:

  • - trace correlation;
    - console output and logging reconfiguration;
    - forks and multiprocessing workers, including Pool with close()/join() and module cloning;
    - an intake that never responds: SIGTERM exits as fast and with the same status as with the feature off, and a normal exit is delayed by at most the 1s deadline.
  • Test Optimization: the shared handler, DDTestLogsHandler, and a pytest-plugin test that APM submission is off during the session and drops pre-session records, with and without agentless mode.

  • tests/llmobs/test_logger.py for V2LogWriter.

  • Regression tests for review and end-to-end findings were confirmed to fail against the previous behaviour.

  • A test checks that importing the Test Optimization plugin and ddtrace.testing.logs does not load ddtrace.internal.logs, and another that the tracer-free DD_LOGS_OTEL_ENABLED resolution matches the tracer's configuration.

  • The branch was rebuilt on the current main for this split; its tests have not been re-run locally since, so CI is their first run.

  • Run locally on Python 3.9: the full tests/internal/ suite, the LLMObs logger tests and the Test Optimization log tests; tests/internal/test_logs.py also on 3.14. scripts/lint checks and the dependency-direction and circular-import checks pass.

  • Benchmarks: none run. With the flag off, nothing is imported. With it on, each log call adds the callHandlers wrapper, a walk up the logger's parents, and one buffered append.
  • Risks

  • Processes that already set DD_AGENTLESS_ENABLED=true, or DD_AGENTLESS_LOG_SUBMISSION_ENABLED (for example globally in CI), start shipping logs; agentless Test Optimization sessions start submitting test logs.

  • logging.Logger.callHandlers is patched process-wide while enabled. A Logger subclass that overrides it without calling the base method is not captured.

  • A normal exit can take up to 1s longer while pending records are sent.

  • Under ddtrace-run pytest, records logged before pytest_load_initial_conftests are discarded; if that takes over 5s, they could be sent as APM logs.
  • Additional Notes

  • Not captured: records below the logger's level (root defaults to WARNING), loggers with propagate=False, and loguru.

  • Records not yet sent are lost when a process is ended by a signal such as SIGTERM or SIGKILL, by os._exit() (for example a raw os.fork() child), by Pool.terminate() (use close()/join()), or by a crash.

  • Trace correlation relies on DD_LOGS_INJECTION (on by default).

  • Serverless environments get no special handling.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: gnufede Review duration: 6533m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #22141"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%