-
Notifications
You must be signed in to change notification settings - Fork 560
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
Add tracing instrumentation for database/sql #505
Conversation
Before adding tests, @open-telemetry/go-approvers I'm interested in your opinions on this. |
The rationale for the Rows* spans is that if you do a query that returns a significant number of rows, the actual query will likely return quickly, but fetching the rows may take a non-insignificant amount of time. From looking at the current implementation this would be invisible to the tracing. While creating an unbounded number of spans is definitely a bad idea, not having visibility is also less than ideal. I think a model similar to the net/http tracing where a parent span is created that persists for the entire duration with sub-spans for the query itself and RowsClose/RowsAffected calls and instead of spans for RowsNext perhaps use a log entry to indicate when it was called as this is a lot lighter weight than a span for it. The parent span would finish when RowsClose is called. A similar pattern would likely be useful for transactions too with the parent persisting until Commit or Rollback is called (although context propagation in this instance might be a bit trickier so maybe this is less doable). |
@nvx Thanks for the review. I made some changes to record the status of |
Codecov Report
@@ Coverage Diff @@
## main #505 +/- ##
=======================================
+ Coverage 77.9% 78.1% +0.1%
=======================================
Files 55 65 +10
Lines 2602 2890 +288
=======================================
+ Hits 2029 2259 +230
- Misses 443 491 +48
- Partials 130 140 +10
|
Tests added. @open-telemetry/go-approvers, PTAL. |
I'd like to chime in and say that this "just-works". I tried it locally and it works perfectly. I didn't do any stress test. |
@fsaintjacques, how did you integrate this branch into your project? If we can update this to depend on OpenTelemetry version 0.17.0, I can start using it. |
Hey @seh, I upgraded the version of OTel to |
Thank you, Sam. I was able to test it in my project by adding the following to my go.mod file: replace go.opentelemetry.io/contrib/instrumentation/database/sql/otelsql => github.com/XSAM/opentelemetry-go-contrib/instrumentation/database/sql/otelsql v0.0.0-20210221151636-93de4d250415 I had written the branch name as "database-sql," but one of the go mod commands rewrote it with that computed reference. |
hey! Is this PR anywhere close to getting merged? We would love to make use of this to get traces against our DBs! |
I'm still interested in being able to include query parameters in the spans, though I understand the security risk. We'd probably need to able to configure allowed or blocked sets of parameters, but that's fragile; parameters don't always have names that would allow identifying them. Perhaps we could introduce something like There's also the question of how we'd represent the sequence of arguments in a trace span. Would we write them in a single field, in the style of a JSON array? Would we create field names like "db.arg.1," "db.arg.2," and so on? Or maybe require that the hypothetical |
I think this PR is big enough as it is. The proposed change would be better suited in a followup issue/PR. We're already 2 (+ committer) that voiced our desire to use this immediately. |
Yes, I too am using it today. I didn't intend to hold this up. I'm just sharing my impressions from having used it over the last week or so. |
I mean if you're having to specially tag arguments anyway, might as well just add a tag to a parent span no? |
I'm already doing that. The utility here is for debugging when you pass the arguments in the wrong order, or when you're trying to figure out why a query behaves strangely with particular arguments. Now, you could say in those cases one should just inspect the parent spans to learn of those arguments, but that doesn't always provide the whole story—at least not easily. With Honeycomb, for example, it's not possible today to query for matching fields in related spans; your query predicate must be satisfied by a single span. Sometimes you're querying for things specific to the database, focusing on SQL statements, below the level of the application spans. |
agreed, I would prefer to just see rapid iteration on this, add any additional features/fixes to go in new PRs. This has been open for 2 months now. If the tests are passing and if the people willing to consume the branch version of this are reporting it just works lets get it merged so the whole community can use it. Personally we have a need to get tracing for our databases and we're blocked whilst we wait for this to complete since we don't want to use prerelease versions. |
Thank you once again for the prompt update, Sam. |
Any progress on merging this? @XSAM did a great job, but every time PR gets rebased and updated to the latest code base it expires (conflicts) in a week or so. |
We've discussed this a couple times at the SIG meeting and the consensus seems to be that we are not ready to land a @XSAM are you able to host this module independently for the time being? |
@Aneurysm9 Sure thing, I host this module in https://github.com/XSAM/otelsql. |
Thank you very much, Sam. I'm now using your other module path in concert with the version 0.19.0 release, and it works well. |
want to comment that this works great and would love to see it included in contrib. |
|
@pellared You can check this issue XSAM/otelsql#22. :) |
I'm going to close this as the instrumentation is now being hosted at https://github.com/XSAM/otelsql in accordance with our new instrumentation policy. |
* update README with import instructions and how to build / test * fix typo * remove building the code section from README.md * add clone instructions to CONTRIBUTING.md Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com> Co-authored-by: Rahul Patel <rahulpa@google.com>
mark |
Related #5
Here is the MVP instrumentation of database/sql.
After I looked at some of the prior implementations: https://github.com/j2gg0s/otsql, https://github.com/opencensus-integrations/ocsql, and https://github.com/DataDog/dd-trace-go/tree/v1.24.1/contrib/database/sql, I find out most of the codes from these arts are similar. Also, they all use
Register
to create a new SQL driver.The big difference is whether to add extra spans, for example, creating spans in the
Ping
function. I accept some features and drop the rest. Here is the detail:Rows
db.statement
will use this, which is a required attribute. https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/database.mdAlthough I choose to drop these features, we might add them in the future; this is just an MVP implementation.