Skip to content

Write a per-process tracer log file in Azure App Service - #13227

Draft
Lewis-E wants to merge 3 commits into
masterfrom
lewis.lewis/svls-9057-aas-per-process-log-file
Draft

Lewis-E wants to merge 3 commits into
masterfrom
lewis.lewis/svls-9057-aas-per-process-log-file

Conversation

@Lewis-E

@Lewis-E Lewis-E commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

In Azure App Service, each JVM writes its own tracer log file, <name>-<pid>.<ext>, instead of sharing the configured one. The file rolls over at DD_MAX_LOGFILE_SIZE (10 MB by default). At startup a background thread deletes this tracer's own per-process files older than DD_TRACE_LOGFILE_RETENTION_DAYS (32 by default, 0 turns cleanup off). Both settings use the .NET tracer's names and defaults. Logging to stderr or stdout, and logging outside App Service, are unchanged. Each commit message has the details.

Motivation

On Azure App Service (Windows), each new JVM truncates the tracer log file that the JVMs before it wrote to (SVLS-9057, escalation SLES-2826). An overlapped IIS recycle runs the old and new worker at the same time, and each worker start runs several JVMs in a row through JavaBootstrapper, four in our runs. In our App Service repro, a new JVM truncated the shared file from 3,522 bytes to 0, so the old JVM's last lines, including its shutdown, were lost. This is likely why customer logs never cover an outage.

In a repro run with this change, the old JVM's file was still there after the recycle. #12899 describes the rest of the repro.

Additional Notes

Design choices and known gaps:

  • It gets the PID through ProcessHandle by reflection, with a JMX fallback on Java 8, because PidHelper can't be used safely during logging startup. Its cleanup runs on a plain daemon thread.
  • It adds two public settings, DD_MAX_LOGFILE_SIZE and DD_TRACE_LOGFILE_RETENTION_DAYS, registered in metadata/supported-configurations.json with the .NET tracer's type and defaults. They're read as environment variables only, like DD_AZURE_APP_SERVICES, because logging starts before Config.
  • AasPerProcessLogFile is left out of agent-logging's instruction coverage rule. Its PID lookup has separate Java 8 and Java 9+ paths, and no single JVM runs both. The branch rule still applies to it. If reviewers prefer, the PID lookup can move into its own small class, and only that class would be excluded.

Tests: AasPerProcessLogFileTest covers the file name, rollover, appending to an existing file, falling back to stderr when the file can't be opened, and retention cleanup.

Contributor Checklist

Jira ticket: SVLS-9057

Overlapping worker processes in Azure App Service run several JVMs that
share one configured log file, and each new JVM truncates it, so the old
JVM's last lines are lost. In an overlapped IIS recycle, a new JVM wiped
the old JVM's log, including its shutdown. Copy the .NET tracer:

- Write to <name>-<pid>.<ext> instead of the configured file.
- Roll over at DD_MAX_LOGFILE_SIZE bytes (default 10 MB).
- At startup, delete this tracer's own per-process files last written
  more than DD_TRACE_LOGFILE_RETENTION_DAYS ago (default 32, 0 turns
  cleanup off), stopping quietly at the first failure.

Only active when DD_AZURE_APP_SERVICES is set.
AasPerProcessLogFile had no tests, so the agent-logging coverage check
failed. The new tests check that, in Azure App Service only, the tracer
writes to <name>-<pid>.<ext> next to the configured file. They also check
that it falls back to standard error when that file cannot be opened,
rolls over to numbered files at DD_MAX_LOGFILE_SIZE (0 turns rollover
off), and appends to an existing file instead of truncating it. Cleanup
is checked too: it deletes only this tracer's per-process files older
than DD_TRACE_LOGFILE_RETENTION_DAYS (0 turns it off), and it stops
quietly when a file cannot be deleted.

The class is left out of the instruction coverage rule. Its PID lookup
has one path for Java 8 and another for Java 9+, and coverage runs on
only one JVM, so one path always shows as missed. The class can't use
PidHelper, because PidHelper sets up an slf4j logger and this code runs
while the tracer's logger is starting. The branch rule still covers the
class, and both rules still cover RollingFileOutputStream.
AasPerProcessLogFile read DD_AZURE_APP_SERVICES, DD_MAX_LOGFILE_SIZE, and
DD_TRACE_LOGFILE_RETENTION_DAYS with EnvironmentVariables.get, which the
config inversion linter rejects. Read them through ConfigHelper.env, and
add the two log file settings to supported-configurations.json with the
.NET tracer's type and defaults: int, 10485760 bytes, and 32 days.
@Lewis-E Lewis-E added type: bug fix Bug fix comp: logging Tracer internal logging tag: ai generated Largely based on code generated by an AI or LLM labels Nov 4, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.84 s 14.74 s [-0.1%; +1.4%] (no difference)
startup:insecure-bank:tracing:Agent 13.61 s 13.68 s [-1.4%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 17.14 s 17.09 s [-0.4%; +1.0%] (no difference)
startup:petclinic:iast:Agent 17.05 s 17.15 s [-1.4%; +0.3%] (no difference)
startup:petclinic:profiling:Agent 16.70 s 16.94 s [-2.5%; -0.4%] (maybe better)
startup:petclinic:sca:Agent 17.13 s 17.05 s [-0.4%; +1.4%] (no difference)
startup:petclinic:tracing:Agent 16.28 s 16.14 s [-0.1%; +1.9%] (no difference)

Commit: 7c2da616 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 79.78%
• Overall Coverage: 59.98% (+0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7c2da61 | Docs | Give us feedback!

This branch has not been deployed

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

Labels

comp: logging Tracer internal logging tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant