-
Notifications
You must be signed in to change notification settings - Fork 78
feat: Add support for OpenTelemetry #551
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
base: main
Are you sure you want to change the base?
Conversation
krlmlr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, lovely!
For what functions does it not make sense to implement telemetry? I guess dbQuote*(), what else?
Does this supersede https://github.com/r-dbi/dblog? Do you think a non-invasive approach like used there would be feasible here as well? What is the overhead if no listeners are active?
If we need to add here, a suggested package would be preferred.
hadley
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a great first step!
My preliminary thoughts are that we should instrument all 'full transactions', where we might be interested in the length of the spans. Otel expects all spans to be short-lived. Hence for example, we don't have a span that starts with
Gabor has spent a lot of time to make the interface as user-friendly as possible. I think the idea that you can get instrumentation for free with no code changes, and can leave it on in production is a powerful proposition. If not active, there is practically no overhead - the current main instrumentation function
Updated to suggests in d6213f6. |
|
I've updated this PR to cover the high-level operations - let me know if any obvious ones are missing. Instrumenting the lower level ones would result in much more (noisy) output. Live link here: https://logfire-eu.pydantic.dev/public-trace/73de9eac-7379-4581-b285-845a7a52c56b?spanId=eddfab36dba4de22 Re. documentation, let me know if you have a particular preference here e.g. if you want to stick with a news item (knitr), or have a separate vignette (mirai). |
?otelsdk::collecting for more details on configuring OpenTelemetry
krlmlr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. My understanding is that this is opt-in, and that tracing for DBI can be disabled even if tracing for other sources is enabled. I wonder if we can emit a banner message when connecting that points to relevant documentation?
Yes, you're right - and detailed in the otelsdk instrumentation docs.
I'm thinking that in some cases it may be a system admin which has set up otel collection rather than the end user. So it may be surprising for the user to see a banner, especially as they wouldn't then know what to do with the information. |
?otelsdk::collecting for more details on configuring OpenTelemetry|
As this rolls out across more packages, we'll do more to promote it, so hopefully folks start to internalise that this sort of observability is available in all the packages they rely on the most. |
|
I've now updated this PR with a common approach on caching the tracer, and a testing helper (following discussions with @schloerke who's been spearheading the otel integration in Shiny/promises). |

This PR implements basic OpenTelemetry instrumentation for DBI.
Abides by the otel semantic conventions for database spans as far as possible (with considerations for limitations of the R API, performance etc.).
The following is a screenshot of the spans created by running the examples for
dbGetQuery(). This trace may also be examined interactively at this public link (30 day validity):https://logfire-eu.pydantic.dev/public-trace/a3da0166-cf62-43de-b194-864bf3c9e33d?spanId=77e385b051f86076
Implementation progress:
dbConnect/dbDisconnect,dbCreateTable/dbRemoveTable,dbGetQueryTodo:
dbAppendTable,dbWriteTable/dbReadTableand all Arrow variants- [ ] Add documentation(covered by news item + separate article for other packages)I've assumed otel to be an 'imports' package for simplicity, but it shouldn't be a problem to move to 'suggests' if that's the preference.