-
Notifications
You must be signed in to change notification settings - Fork 282
Description
Proposal for new db.target attribute
The type of targets available for a database operation is dependent on a database system. For example, the target of a SQL database operation may be a table, function, or stored procedure. Other database systems may refer to their targets as collections or indexes, etc.
Currently, there exists database system specific attributes for describing this. Examples include:
Introducing a general-purpose attribute would enable backends to provide a generic experience for faceting database operations by their target without requiring the backend have knowledge of all the database system specific attributes. It would also enable end users to more easily explore their data at a high-level without having to know the specific database systems in use.
I propose a new call-level attribute db.target for describing the target of a database operation. The term "target" may not be the greatest, but I'm using it for lack of a better term for the moment. I considered db.operation.target but of course db.operation is already an attribute. Maybe db.operation could become db.operation.type thereby allowing db.operation.target.
Issues to consider
- Similar to
db.operation, the value of thedb.targetmay not be readily available without parsing the value ofdb.statement, e.g.SELECT * FROM Usersthedb.operationisSELECTand thedb.targetisUsers. The specification advises against parsingdb.statementto derive other attributes. I consider this a limitation particularly once we have a database client operation metric (see Database client operation duration metricย #512). Thedb.statementattribute is fine for spans but because of its high-cardinality will not work for metrics. Therefore, havingdb.operationanddb.targetattributes on metrics will be useful. - There may be many targets for a single database operation, e.g.
SELECT * FROM Users U JOIN Company C ON ....
Perhaps parsing db.statement can be an opt-in feature?
Various backends have prior art for addressing these issues. For example:
- Elastic APM performs a limited parsing to extract the operation and outer-most table name from a SQL statement. This is described in their agent specifications.
- New Relic APM agents perform a similar limited parsing and includes operation/target on metric data. New Relic's agent specs are unfortunately not publicly available, so I do not have a link to share. Though here is New Relic Java agent source code that performs the parsing.
- New Relic agents offer a feature for providing a "hint" of the database target. The hint can be added as a comment prior to the database statement to simplify parsing, e.g.,
/* nrhint:Company */ SELECT * FROM Users U JOIN Company C ON ....