Skip to content

(feat) internal/civisibility: civisibility mocktracer#3507

Merged
tonyredondo merged 10 commits into
mainfrom
tony/civisibility-civisibilitymocktracer-v2
May 20, 2025
Merged

(feat) internal/civisibility: civisibility mocktracer#3507
tonyredondo merged 10 commits into
mainfrom
tony/civisibility-civisibilitymocktracer-v2

Conversation

@tonyredondo

@tonyredondo tonyredondo commented May 8, 2025

Copy link
Copy Markdown
Member

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:

  • CI Visibility is initialized: A new tracer instance is created configured for civisibility, meaning: custom payload, custom writer, custom transport, etc.
  • A test starts the mocktracer: In this case we want customers to be able to use the mocktracer but we need to keep our tracer instance to report the tests spans being generated by the test session.
  • Mocktracer then create a new civisibilitymocktracer instance 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.
  • The test uses the mock tracer normally. Normal spans will be kept in the mocktracer, test spans will be passed to the civisibility tracer.

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

  • 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 golangci-lint run locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

@tonyredondo
tonyredondo requested review from a team as code owners May 8, 2025 11:10
@tonyredondo
tonyredondo requested a review from anmarchenko May 8, 2025 11:10
@tonyredondo tonyredondo self-assigned this May 8, 2025
@pr-commenter

pr-commenter Bot commented May 8, 2025

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2025-05-20 11:28:00

Comparing candidate commit 2ef5fb4 in PR branch tony/civisibility-civisibilitymocktracer-v2 with baseline commit e7a40ff in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 55 metrics, 1 unstable metrics.

@datadog-datadog-prod-us1

Copy link
Copy Markdown

Datadog Summary

✅ Code Quality    ✅ Code Security    ✅ Dependencies


Was this helpful? Give us feedback!

Comment on lines +57 to +64
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)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Currently doesn't change the current mocktracer behavior, test spans will bypass.

@tonyredondo
tonyredondo enabled auto-merge (squash) May 20, 2025 11:07
@tonyredondo
tonyredondo merged commit e92a055 into main May 20, 2025
@tonyredondo
tonyredondo deleted the tony/civisibility-civisibilitymocktracer-v2 branch May 20, 2025 11:29
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.

3 participants