Add db.name to ecto spans (#172)

* Add db.name to ecto spans

As per the spec, the db.name attribute is required on database spans. This changes adds it.

Ref: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md#call-level-attributes

* Add db.name attribute to tests

* Changelog update

* Update instrumentation/opentelemetry_ecto/test/opentelemetry_ecto_test.exs

* Update instrumentation/opentelemetry_ecto/test/opentelemetry_ecto_test.exs
This commit is contained in:
Cedric Ziel 2023-05-23 12:49:29 +02:00 committed by GitHub
parent ddf0706bf1
commit 8292870b66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View File

@ -1,5 +1,11 @@
# Changelog # Changelog
## 1.1.1
### Changed
* Add db.name to ecto spans
## 1.1.0 ## 1.1.0
### Changed ### Changed

View File

@ -92,6 +92,7 @@ defmodule OpentelemetryEcto do
"db.statement": query, "db.statement": query,
source: source, source: source,
"db.instance": database, "db.instance": database,
"db.name": database,
"db.url": url, "db.url": url,
"total_time_#{time_unit}s": System.convert_time_unit(total_time, :native, time_unit) "total_time_#{time_unit}s": System.convert_time_unit(total_time, :native, time_unit)
} }

View File

@ -50,6 +50,7 @@ defmodule OpentelemetryEctoTest do
assert %{ assert %{
"db.instance": "opentelemetry_ecto_test", "db.instance": "opentelemetry_ecto_test",
"db.name": "opentelemetry_ecto_test",
"db.statement": "SELECT u0.\"id\", u0.\"email\" FROM \"users\" AS u0", "db.statement": "SELECT u0.\"id\", u0.\"email\" FROM \"users\" AS u0",
"db.type": :sql, "db.type": :sql,
"db.url": "ecto://localhost", "db.url": "ecto://localhost",
@ -82,6 +83,7 @@ defmodule OpentelemetryEctoTest do
assert %{ assert %{
"db.instance": "opentelemetry_ecto_test", "db.instance": "opentelemetry_ecto_test",
"db.name": "opentelemetry_ecto_test",
"db.statement": "SELECT p0.\"id\", p0.\"body\", p0.\"user_id\" FROM \"posts\" AS p0", "db.statement": "SELECT p0.\"id\", p0.\"body\", p0.\"user_id\" FROM \"posts\" AS p0",
"db.type": :sql, "db.type": :sql,
"db.url": "ecto://localhost", "db.url": "ecto://localhost",