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

[sql] Parse db.operation.name and db.collection.name from db.query.text #2222

Open
alanwest opened this issue Oct 17, 2024 · 1 comment
Open
Assignees
Labels
comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient enhancement New feature or request

Comments

@alanwest
Copy link
Member

alanwest commented Oct 17, 2024

Component

OpenTelemetry.Instrumentation.SqlClient

What is the expected behavior?

The attributes db.operation.name and db.collection.name are conditionally required "if readily available".

Alternatively, they MAY be parsed from db.query.text. See relevant footnotes.

[3]: If readily available. The collection name MAY be parsed from the query text, in which case it SHOULD be the first collection name found in the query.
[6]: If readily available. The operation name MAY be parsed from the query text, in which case it SHOULD be the first operation name found in the query.

These attributes are very valuable to end users.

Parsing db.query.text is a costly operation. What this issue does not attempt to address is whether parsing operation/collection from db.query.text should be on by default. For now, it should be implemented as opt-in, though later we should decide whether it should be on by default.

@alanwest alanwest added the enhancement New feature or request label Oct 17, 2024
@alanwest alanwest self-assigned this Oct 17, 2024
@github-actions github-actions bot added the comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient label Oct 17, 2024
@alanwest alanwest changed the title [feature request] Parse db.operation.name and db.collection.name from db.query.text [sql] Parse db.operation.name and db.collection.name from db.query.text Oct 17, 2024
@hannahramadan
Copy link

Ruby has an in-progress PR to add db.collection.name. Here is the regex:

# Capture the first word (including letters, digits, underscores, & '.', ) that follows common table commands
TABLE_NAME = /\b(?:(?:FROM|INTO|UPDATE)|(?:(?:CREATE|DROP|ALTER)\s+TABLE(?:\s+IF\s+(?:NOT\s+)?EXISTS)?))\s+["]?([\w.]+)["]?/i

Adding this note as more of a resource/ point of discussion when this ticket gets worked on. Might be a better way to grab this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants