-
Notifications
You must be signed in to change notification settings - Fork 22
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 instrumentation for the database/sql package #88
Conversation
This reverts commit a69a5e5.
Have instrumentation register setup configuration for the driver they are instrumenting. This moves the internal dsn parsing to the instrumentation itself.
Do you want to add a Also, we need to think if we should not move this PR to https://github.com/open-telemetry/opentelemetry-go-contrib Can this approach of instrumenting ng via |
Yeah, let's do that in a follow on PR. This is quite large already. |
An idea for the next PR with documentation. I think it may be a good idea to demonstrate how to add an additional attribute like |
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.
LGTM
I guess your are finishing adding explanations to places with nolint:
😉
This new module instruments the built-in
database/sql
package. The instrumentation wraps all calls made with this package and is designed with a similar registration method for instrumentation setup (more on that bellow).Instrumentation of specific drivers
The design of the
splunksql
package is such that users wanting an instrumented version of their driver and thedatabase/sql
package need to do two things.splunksql.Open
function instead of thesql.Open
function.To understand this flow, take for instance the generic example of a user using the MySQL driver with the
database/sql
package. To start their code looks like this.To use this instrumentation, their code will need to be updated to this.
The import of
github.com/signalfx/splunk-otel-go/instrumentation/github.com/go-sql-driver/mysql/splunkmysql
will import the instrumentedgh.neting.cc/go-sql-driver/mysql
(registering its driver with thedatabase/sql
package) and itself register instrumentation specific setup with thesplunksql
package (e.g. this). Then when the user callssplunksql.Open
(which is a drop in replacement forsql.Open
based on its variadic Option design). the registered driver and instrumentation setup will be loaded appropriately. From this, telemetry that knows what database it is for and annotated according to the OpenTelemetry semantic conventions is produced.The need to register instrumentation setup comes from the need to parse the database connection string. That string will contain needed annotations and the way it is parsed is going to be specific to the database being instrumented.
This registration method differed from the existing signalfx-go-tracing instrumentation. There the
database/sql
package is designed to hold all parsing logic. This is a design that will not extend well, unlike the one presented here.Uninstrumented drivers
If the user does not import an instrumentation package for the driver they are using, or one does not exist, the
splunksql.Open
function can still be extended to accommodate this. The returnedsql.DB
will still use an instrumented Driver which will produce telemetry. If the user passes attributes conforming to OTel semantic conventions using theWithAttributes
Option as a parameter the produced telemetry will comply with the OTel specification.