Conversation
This allows to swap the flush handling on the tracer with other implementations that require different flush semantics, like synchronous ones.
…integration tests to use {test,agent}test
8212d72 to
3c74aaf
Compare
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: b2e7bd2 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
BenchmarksBenchmark execution time: 2026-03-25 16:10:32 Comparing candidate commit b2e7bd2 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 215 metrics, 9 unstable metrics.
|
…es by replacing FreePort+ListenAndServe with a pre-bound FreeListener+Serve and adding a TestCasePreBootstrap interface so os/lfi.go can configure AppSec env vars before the tracer starts
|
@codex review |
…Tags to attributes, Meta and Metrics to agenttest span tags
…n to expected traces
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 078b37add2
ℹ️ 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".
| o := append([]StartOption{ | ||
| WithAgentAddr(agent.Addr()), | ||
| }, opts...) | ||
| tracer, err := newTracer(o...) |
There was a problem hiding this comment.
Invoke full startup path for inspectable tracer
startInspectableTracer creates the tracer with newTracer(...) but never executes the extra initialization done in tracer.Start (notably AppSec startup and other post-construction runtime hooks). This means options passed through tracertest.Bootstrap, such as tracer.WithAppSecEnabled(true) in the orchestrion harness, are not actually activated, so AppSec-dependent integration scenarios can silently lose coverage or fail inconsistently. The inspectable bootstrap path should run the same startup hooks as Start before returning.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This requires a significant refactor. Doing it in a future PR.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f6465bb5f
ℹ️ 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".
| } | ||
| drained: | ||
| tracer.traceWriter.flush() | ||
| tracer.traceWriter.(*agentTraceWriter).wg.Wait() |
There was a problem hiding this comment.
Avoid assuming agentTraceWriter in inspectable flush path
This hard cast panics when the tracer is configured with a non-agent writer (for example log-to-stdout or CI Visibility modes), even though Start accepts arbitrary tracer options/environment. A Flush() call from such tests will crash instead of flushing; guard the cast or handle non-agent writers explicitly.
Useful? React with 👍 / 👎.
Codecov Report❌ Patch coverage is Additional details and impacted files
🚀 New features to boost your workflow:
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 63cc74f440
ℹ️ 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".
| } | ||
| drained: | ||
| tracer.traceWriter.flush() | ||
| tracer.traceWriter.(*agentTraceWriter).wg.Wait() |
There was a problem hiding this comment.
Guard flush wait against non-agent trace writers
startInspectableTracer accepts arbitrary tracer.StartOptions, but the custom flush handler unconditionally casts tracer.traceWriter to *agentTraceWriter; if callers pass options that select a different writer (for example log/stdout or CI Visibility modes), Flush() will panic at runtime instead of flushing. This makes the new ddtrace/x/tracertest helper fragile in valid option combinations and can crash integration tests unexpectedly.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Already mentioned previously. I'll fix it when needed.
| // FlushSync flushes all currently buffered data and blocks until the HTTP send completes. | ||
| func (l *LLMObs) FlushSync() { | ||
| done := make(chan struct{}) | ||
| l.flushSyncCh <- done |
There was a problem hiding this comment.
Avoid blocking FlushSync when LLMObs is not running
FlushSync always sends on the unbuffered flushSyncCh without checking lifecycle state, so calling it after Stop() (or before Run() starts receiving) blocks forever because no goroutine is left to read that channel. Since this commit wires llmobs.FlushSync() into tracer test flushing, that deadlock path can hang test runs whenever LLMObs is stopped out of band.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good to know. I'll fix it in another PR.
…urning slices or iterators
kakkoyun
left a comment
There was a problem hiding this comment.
I did an initial pass. I will need more time on this. This PR does a lot. But I can see it's neatly separated into commits. So I'll do a commit-by-commit review.
| // flushHandler is called by the worker when an explicit flush is triggered | ||
| // (i.e. when Flush() is called). It defaults to defaultFlushHandler. | ||
| // Tests can override this to provide stronger flush semantics. | ||
| flushHandler func(done chan<- struct{}) |
There was a problem hiding this comment.
I will have to revisit https://github.com/DataDog/dd-trace-go/pull/3995/changes
or close after this PR.
| // flushHandler is called by the worker when an explicit flush is triggered | ||
| // (i.e. when Flush() is called). It defaults to defaultFlushHandler. | ||
| // Tests can override this to provide stronger flush semantics. | ||
| flushHandler func(done chan<- struct{}) |
There was a problem hiding this comment.
nit: Maybe we should have an interface type Flasher and FlushFunc for future and possibly more complicated flushing mechanisms.
There was a problem hiding this comment.
Agreed. Should we do it in a followup PR?
|
@kakkoyun I agree that the PR does a lot, but the core is in The rest are adapted tests and a fix for Orchestrion integration tests to avoid flakiness that the new free-wait approach unfortunately introduced. |
Co-authored-by: Kemal Akkoyun <kakkoyun@users.noreply.github.com>
This reverts commit 9098ddd.
What does this PR do?
Adds an inspectable tracer that replaces the other four different ways to inspect spans and mocking the tracer.
Migrates a few example tests that we using any of the different existing approaches in the codebase.
Important
testracer.Startstarts a test tracer but it doesn't register it as global tracer.testtracer.Bootstrapstarts a test tracer, a test agent, and registers the former as global tracer.ddtrace/tracerAPI.Motivation
Reviewer's Checklist
make lintlocally.make testlocally.make generatelocally.Unsure? Have a question? Request a review!