(feat) internal/civisibility: civisibility mocktracer#3507
Conversation
BenchmarksBenchmark execution time: 2025-05-20 11:28:00 Comparing candidate commit 2ef5fb4 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 55 metrics, 1 unstable metrics. |
Datadog Summary✅ Code Quality ✅ Code Security ✅ Dependencies Was this helpful? Give us feedback! |
| func StoreGlobalTracer[M mockTracerLike, T tracerLike](m M) { | ||
| if (mockTracerLike)(m) == nil { | ||
| panic("ddtrace/internal: StoreGlobalTracer called with nil") | ||
| } | ||
| // convert the mock tracer like to the actual tracer like type (avoid panic on storing different types in the atomic.Value) | ||
| t := (tracerLike)(m).(T) | ||
| globalTracer.Store(&t) | ||
| } |
There was a problem hiding this comment.
If this is intended for mocktracer, maybe it should be more restrictive. WDYT? I'm approving the PR because this is an internal API, so we can modify at our will.
There was a problem hiding this comment.
Ok, thanks, do you have any ideas to make it more restrictive? we don't have any reference to the mocktracer package, the only different I detected was the Reset() func, hence the mockTracerLike interface. I guess we can do this in a next PR as well...
| // OpenSpans returns the set of started spans that have not been finished yet. | ||
| // This is useful for verifying spans are properly finished in tests. | ||
| func (t *civisibilitymocktracer) OpenSpans() []*Span { | ||
| return t.mock.OpenSpans() |
There was a problem hiding this comment.
I wonder how does CIVis work in a scenario where tests are running in parallel. Is it something that could impact in the design of this mocktracer? Or, is it something that we care about?
There was a problem hiding this comment.
Currently doesn't change the current mocktracer behavior, test spans will bypass.
What does this PR do?
This PR adds a new MockTracer for CI Visibility mode, to allow mocktracer usage while sending ci visibility data to the backend.
The proc lifetime goes like this:
civisibilitymocktracerinstance as a global tracer. It calls the StoreGlobalTracer and not the Swap. We don't call the swap because if we do that the swap will call the Stop func over the civisibility tracer and we don't want that.Motivation
A TestOptimization/CIVisibility customer have some tests over their custom/manual spans using the mocktracer. Currently, those tests are not being reported due the fact that CIVisibility Test spans also end up in the mocktracer instance.
Reviewer's Checklist
golangci-lint runlocally.Unsure? Have a question? Request a review!