Skip to content
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 ecto adapter attribute #65

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jhonndabi
Copy link

@jhonndabi jhonndabi commented Feb 9, 2022

I couldn't find any discussion about how to include the required attribute db.system.
I think currently there isn't a good way to infer that information, maybe ecto adapters can send to telemetry that information through metadata. For now, if we simple pass the ecto adapter as attribute, will be possible to infer and map that info.
Elixir.Ecto.Adapters.Postgres -> postgresql
Elixir.Ecto.Adapters.MyXQL -> mysql
Elixir.Ecto.Adapters.Tds -> mssql

This PR do the following:

  • Change some attributes key to follow semantic conventions.

  • Add the attribute ecto.db.adapter

  • Add the attribute db.system

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 9, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@tsloughter
Copy link
Member

Could submit the ecto specific adapter attribute to https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md#connection-level-attributes-for-specific-technologies -- as far as I can tell it is the same as like a JDBC driver class name.

@tsloughter
Copy link
Member

I agree you can create a function to map the adapter name to the db.system name and add db.system attribute to this.

@bryannaegele
Copy link
Collaborator

Can you open an issue on ecto to request it be added as an attribute in the meta?

@bryannaegele
Copy link
Collaborator

Could submit the ecto specific adapter attribute to https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md#connection-level-attributes-for-specific-technologies -- as far as I can tell it is the same as like a JDBC driver class name.

I think this is supposed to be at the driver level which would be postgrex for the postgres adapter.

@jhonndabi
Copy link
Author

jhonndabi commented Feb 10, 2022

Could submit the ecto specific adapter attribute to https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md#connection-level-attributes-for-specific-technologies -- as far as I can tell it is the same as like a JDBC driver class name.

I think this is supposed to be at the driver level which would be postgrex for the postgres adapter.

Driver is a required option to sql adapter.

https://github.com/elixir-ecto/ecto_sql/blob/6935c289f68e1404ef0a6ec652d8fb1f89a82b96/lib/ecto/adapters/sql.ex#L88
https://github.com/elixir-ecto/ecto_sql/blob/6935c289f68e1404ef0a6ec652d8fb1f89a82b96/lib/ecto/adapters/sql.ex#L735

What do you think to ask them in the issue I will open to include driver and dbms_identifier in the telemetry metadata?

cc @bryannaegele @tsloughter

@tsloughter
Copy link
Member

@jhonndabi sorry I missed this, that sounds like a good plan to me.

@tsloughter
Copy link
Member

Also,j can you change the attribute to ecto.db.adapter.

@tsloughter
Copy link
Member

@jhonndabi would you be ok adding db.system with just the mapping you mention in your first comment? Since that information is available, I don't see why we don't just do the mapping.

@jhonndabi
Copy link
Author

jhonndabi commented Apr 1, 2022

@tsloughter Ok, Sorry for the delay, I didn't see before. I'll work on that, and do the mapping.

@tsloughter
Copy link
Member

@jhonndabi can you resolve the conflicts?

I think this is good to merge now once the conflicts are resolved.

@jhonndabi jhonndabi force-pushed the add-ecto-adapter-attribute branch from e3b7d11 to d4f3a89 Compare June 24, 2023 11:56
@jhonndabi
Copy link
Author

@tsloughter yes, of course! Sorry the delay. : )

"db.name": database,
"db.url": url,
"db.sql.table": source,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually know that an Ecto source is a sql table, do we here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://hexdocs.pm/ecto/Ecto.Schema.Metadata.html#module-source

The doc says it will be a table or a collection, I don't know if we have a way to determine if it's a table, but it could be a table. I'm not sure if for SQL adapters it will be always a table.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figure for a sql adapter it will alway be a table. So thats all we need to know to know to include it (I think).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be a view, for example, not sure if it would break your semantics.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's breaks the semantics here, view is like a virtual table.

@jhonndabi jhonndabi force-pushed the add-ecto-adapter-attribute branch from 6444296 to f6e4e5c Compare July 6, 2023 23:14
@tsloughter tsloughter mentioned this pull request Jul 7, 2023
@jhonndabi jhonndabi force-pushed the add-ecto-adapter-attribute branch from f6e4e5c to 043e438 Compare July 17, 2023 17:44
@jhonndabi
Copy link
Author

@tsloughter Is there something else I can do here to get this merged?

@tsloughter
Copy link
Member

@jhonndabi hey, sorry, can you rebase?

And @yordis does this overlap with your PR that is still a draft?

@yordis
Copy link
Contributor

yordis commented Oct 31, 2023

@tsloughter yeah ... that is why I kept it that way, we can merge this one and I can continue the work there (either close it or change it)

Comment on lines +217 to +244

defp db_system(db_system) when db_system in @db_systems, do: db_system
defp db_system(_), do: "other_sql"

defp db_system(nil, Ecto.Adapters.Postgres), do: "postgresql"
defp db_system(nil, Ecto.Adapters.MyXQL), do: "mysql"
defp db_system(nil, Ecto.Adapters.Tds), do: "mssql"
defp db_system(db_system, _), do: db_system(db_system)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsloughter leaving a note here, as I said before, it will be prudent to ask Ecto folks to include a function under the adapter module that allow us to fetch the engine name ...

I am not sure how open they will be, but I think it is a fair thing to ask and see what happens.

"Ideally," this package wouldn't maintain the mapping

Comment on lines +102 to +105
* `:db_system` - The identifier for the database management system (DBMS).
defaults to the mapped value of the ecto adapter used.
Must follow the list of well-known db systems from semantic conventions.
See `https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be globally or per Adapter bases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per adapter bases. I think OpentelemetryEcto.setup/2 is meant to use just for one repo, right? And each repo can have only one Adapter (AFAIK).

@tsloughter
Copy link
Member

@jhonndabi can you rebase this?

@jhonndabi
Copy link
Author

@tsloughter done : )

@jhonndabi jhonndabi force-pushed the add-ecto-adapter-attribute branch from 527511c to f8ff0bb Compare November 24, 2023 11:38
@tsloughter
Copy link
Member

Sorry this never got in. This needs another rebase at least.

@bryannaegele
Copy link
Collaborator

@tsloughter the whole lib needs a semconv rewrite. Probably best to leave it for that PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants