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

tracing: allow specifying parent traceid/spanid when starting a trace #19403

Open
RaduBerinde opened this issue Oct 20, 2017 · 17 comments
Open
Labels
A-kv-client Relating to the KV client and the KV interface. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-kv KV Team

Comments

@RaduBerinde
Copy link
Member

RaduBerinde commented Oct 20, 2017

From https://forum.cockroachlabs.com/t/error-communicating-with-tls-secured-zipkin-collector/1029/3?u=radu

it’d also be useful to explore some way to set the session trace context explicitly. I’m thinking of some parameters when enabling tracing such as SET TRACE = 'TraceID:bd7a977555f6b982; SpanID:ebf33e1a81dc6f71';, and have Cockroach use those identifiers for its parent span.
That would allow an application to pass its tracing context into Cockroach, and show Cockroach’s internal tracing in the context of the rest of the trace across services.

Jira issue: CRDB-5974

Epic: CRDB-11665

@RaduBerinde
Copy link
Member Author

CC @andreimatei

@andreimatei
Copy link
Contributor

I agree with the spirit. It'd be similarly cool to have some sort of support for passing a trace id in a sql query (as a comment).

@dianasaur323
Copy link
Contributor

@asubiotto a user requested this - would it be hard to wrap into the work you are already doing with trace?

@andreimatei
Copy link
Contributor

I think the thing to do here is to add support for parsing trace ids out of SQL comments and then working with one of the Go drivers that supports the new-ish Go sql methods that take a context for generating the comment.
On the server side we'd need to become more flexible in where we allow spans to be generated. I think the current code makes some assumptions about having a span-per-txn.

And then extreme care should be taken around the context that the TxnCoordSender captures for a txn. I think you currently can't have another cancellable ctx derived from the txn one, or something. This is major pain that #23055 is trying to address, but that work is stalled for a bit.

@andreimatei
Copy link
Contributor

Oh and we should see what other databases/tracing systems are doing for propagating trace info to the database. I think other databases support such things too.

@asubiotto
Copy link
Contributor

@dianasaur323, I'm not really doing any work with tracing other than outputting stats collection to the trace.

@knz knz added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Apr 27, 2018
@tbg tbg added the A-kv-client Relating to the KV client and the KV interface. label May 15, 2018
@d4l3k
Copy link
Contributor

d4l3k commented May 17, 2018

Just putting my plug in for this. It definitely would have be a cool feature to have since I have opentracing enabled on both CockroachDB and my application. I'm not actually sure how useful it would be since I already time the requests and that can identify any hot spots. That being said, query planning info (indexes etc) tagged to the trace would be a nice feature.

@tbg tbg added this to the Later milestone Jul 22, 2018
@petermattis petermattis removed this from the Later milestone Oct 5, 2018
@dylanisagit
Copy link

Would like to add a +1 to this idea, it would be incredibly powerful. Right now, we're tracing all of our services but there's no way to have a span go all the way through a service and into CDB.

As a related item, it would be so helpful to be able to set trace levels. Right now, it seems to be binary - either CDB is tracing or it's not. This is hammering our tracing infrastructure, creating an order of magnitude more spans that all of our other services combined.

@RaduBerinde
Copy link
Member Author

Thank you @Dylan-OMahony-Bose, this is good feedback! What kind of control would you like to see w.r.t what we trace and what we don't? Perhaps a mode where there is a single span per SQL query?

@dylanisagit
Copy link

Absolutely, that would be amazing - a verbose mode (as it is today) and a "production" mode (as single span per query, as you suggest), would be enough control. Think of it akin to DEBUG vs. FATAL log levels.

@akshayjshah
Copy link
Contributor

This would be incredibly helpful - tracing browser requests all the way into CDB would be an immensely powerful debugging tool.

The Jaeger collector supports adaptive sampling, but there's some open work to get it completely finished. At the least, probabilistic tracing in "production" mode would be a nice way to keep some visibility but avoid crushing the tracing backend.

@andreimatei
Copy link
Contributor

probabilistic tracing in "production" mode would be a nice way to keep some visibility but avoid crushing the tracing backend.

We're actually also working on that - our own trace collector that's somewhat "adaptive" in the sense that it will try to give you a certain number of samples for each component.

@alienth
Copy link

alienth commented Nov 26, 2019

Would like to +1 this - we add our tracing span IDs to all of our SQL queries via baseplate. Would be incredibly handy if a database engine could capture this for tracing.

@andreimatei
Copy link
Contributor

The time for a new round of investment in our tracing capabilities is coming, as in the next release (20.1) we hope to be able to display some query traces in our UI.
I'll keep this request in mind. Thanks for pointing me to baseplate.

@ajwerner
Copy link
Contributor

ajwerner commented Jan 3, 2020

This would be pretty great.

I'm not sure how I feel about using the comment as in baseplate. I think I like it generally but we'd need to complicate the parsing process as now we'll need to examine comments. Perhaps we could put it into the parsed annotations? Another alternative would be to add it as a transaction setting using SET TRANSACTION. That would have the downside of not working for implicit transactions.

@ajwerner
Copy link
Contributor

ajwerner commented Jan 3, 2020

I looked a bit through how comments get parsed in our grammar (or rather don't) and I no longer like the comment idea. Perhaps we can add some syntax to provide settings for the following statement. A SET STATEMENT ...; that takes the same things as SET TRANSACTION and then the following statement inherits the settings.

@RaduBerinde
Copy link
Member Author

RaduBerinde commented Jan 3, 2020

There is another usecase for comments: query hints. It may be useful to somehow annotate AST nodes with the comments around them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-kv-client Relating to the KV client and the KV interface. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-kv KV Team
Projects
None yet
Development

No branches or pull requests