uptrace / opentelemetry-go-extra

OpenTelemetry instrumentations for Go
https://uptrace.dev/get/instrument/
BSD 2-Clause "Simplified" License
314 stars 72 forks source link

Allow naming `otelsql` spans by `db.operation` #118

Open joshmgross opened 8 months ago

joshmgross commented 8 months ago

Spans from otelsql have static names like db.Query and db.Exect

Per https://opentelemetry.io/docs/specs/semconv/database/database-spans/

The span name SHOULD be set to a low cardinality value representing the statement executed on the database. It MAY be a stored procedure name (without arguments), DB statement without variable arguments, operation name, etc. Since SQL statements may have very high cardinality even without arguments, SQL spans SHOULD be named the following way, unless the statement is known to be of low cardinality: <db.operation> <db.name>.<db.sql.table>, provided that db.operation and db.sql.tableare available. If db.sql.table is not available due to its semantics, the span SHOULD be named <db.operation> <db.name>.

We should add the ability for otelsql spans to follow this naming convention.

The same guidelines do not recommend parsing the db.statement, so we'd need some other way to pass this information to otelsql:

It is not recommended to attempt any client-side parsing of db.statement just to get these properties, they should only be used if the library being instrumented already provides them. When it’s otherwise impossible to get any meaningful span name, db.nameor the tech-specific database name MAY be used.