Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib/gocql/gocql: implement observer api based tracing #2805

Merged
merged 8 commits into from
Aug 16, 2024

Conversation

rarguelloF
Copy link
Contributor

@rarguelloF rarguelloF commented Aug 2, 2024

What does this PR do?

  • Adds CreateTracedSession, and NewObserver functions that make use of the gocql observer apis: (it only implements the query, batch and connect observers for now).
  • Adds new options WithTraceQuery, WithTraceBatch and WithTraceConnect to enable/disable these observers individually (all are enabled by default).
  • Mark the existing wrapping functions and types as deprecated.

Differences with the existing tracing method:

  • The tags cassandra.paginated and cassandra.consistency_level are not set, since the required information is not available in the observer api.
  • The new observer based functions set out.host to the actual host name instead of the cassandra host ID. The host ID is set to a new tag called db.cassandra.host.id.
  • The new observer based functions ignore the DD_TRACE_GOCQL_COMPAT env variable introduced in [contrib/gocql] reporting both cluster and datacenter #2577 and instead directly set the correct values for the cassandra.cluster and cassandra.datacenter tags.
  • cassandra.row_count is a number value instead of a string.

Motivation

Using the observer apis makes this instrumentation easier to use and maintain. It also allows to use the native gocql types instead of our custom wrapper types.

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.
  • 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!

@github-actions github-actions bot added the apm:ecosystem contrib/* related feature requests or bugs label Aug 2, 2024
@pr-commenter
Copy link

pr-commenter bot commented Aug 2, 2024

Benchmarks

Benchmark execution time: 2024-08-12 10:12:32

Comparing candidate commit c6c0385 in PR branch rarguelloF/AIDM-229/gocql-observer-api with baseline commit 0462924 in branch main.

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

@rarguelloF rarguelloF marked this pull request as ready for review August 2, 2024 13:59
@rarguelloF rarguelloF requested review from a team as code owners August 2, 2024 13:59
@rarguelloF rarguelloF requested a review from ufoot August 2, 2024 14:00
Copy link
Contributor

@ufoot ufoot left a comment

Choose a reason for hiding this comment

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

This is great IMO, much better than the previous API. Left a few comments in the review.

contrib/gocql/gocql/observer.go Outdated Show resolved Hide resolved
cluster.Keyspace = "my-keyspace"

// Create a new traced session using any number of options
session, err := gocqltrace.NewTracedSession(cluster, gocqltrace.WithServiceName("ServiceName"))
Copy link
Contributor

Choose a reason for hiding this comment

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

^ my understanding is that this specific call will NOT trace anything.

[EDIT] me wrong, indeed by default this is true, forget about this. Maybe only comment somewhere that the default is "it's traced".

Suggested change
session, err := gocqltrace.NewTracedSession(cluster, gocqltrace.WithServiceName("ServiceName"))
session, err := gocqltrace.NewTracedSession(cluster, gocqltrace.WithServiceName("ServiceName"), gocqltrace.WithTraceQuery(true), gocqltrace.WithTraceBatch(true), gocqltrace.WithTraceConnect(true))

as we have to explicitly pass WithTrace<Something> to activate tracing (but I may be wrong, just asking)

contrib/gocql/gocql/observer.go Outdated Show resolved Hide resolved
contrib/gocql/gocql/option.go Show resolved Hide resolved
contrib/gocql/gocql/observer.go Outdated Show resolved Hide resolved
contrib/gocql/gocql/example_test.go Show resolved Hide resolved
@rarguelloF rarguelloF requested review from darccio and ufoot August 12, 2024 09:42
Copy link
Contributor

@ufoot ufoot left a comment

Choose a reason for hiding this comment

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

Thanks for addressing all my remarks, looks good!

@rarguelloF rarguelloF enabled auto-merge (squash) August 16, 2024 14:14
@rarguelloF rarguelloF merged commit 1bb170a into main Aug 16, 2024
184 of 186 checks passed
@rarguelloF rarguelloF deleted the rarguelloF/AIDM-229/gocql-observer-api branch August 16, 2024 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:ecosystem contrib/* related feature requests or bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants