open-telemetry / semantic-conventions

Defines standards for generating consistent, accessible telemetry across a variety of domains
Apache License 2.0
288 stars 176 forks source link

[database] reporting stored procedures/prepared statements #1491

Open lmolkova opened 1 month ago

lmolkova commented 1 month ago

See https://github.com/open-telemetry/semantic-conventions/pull/1482#discussion_r1805142038

E.g. query like CALL procedure-name should result in the following attributes:

db.query.text = "CALL procedure-name" db.operation.name = "CALL" db.collection.name = "procedure-name"

We should document that collection name can contain stored procedure/prepared statement name

lmolkova commented 1 month ago

Discussed at DB SIG call, decided to rename collection to target and wider its scope.

Related:

trask commented 2 weeks ago

if we don't go ahead with #1527, we may also consider introducing something like db.stored_procedure.name

I don't think I've worked with "named" prepared statements, do you have an example of that? thanks

matt-hensley commented 2 weeks ago

Microsoft SQL Server returns an integer handle that isn't worth recording IMO. I believe SQLite does something similar.

MySQL, MariaDB, and PostgresSQL support named prepared statements. Invocation is similar to stored procedures.

MySQL and MariaDB

mysql> PREPARE stmt1 FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
mysql> SET @a = 3;
mysql> SET @b = 4;
mysql> EXECUTE stmt1 USING @a, @b;
+------------+
| hypotenuse |
+------------+
|          5 |
+------------+
mysql> DEALLOCATE PREPARE stmt1;

PostgreSQL

PREPARE fooplan (int, text, bool, numeric) AS
    INSERT INTO foo VALUES($1, $2, $3, $4);
EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00);