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

Make sure sqlite3 instrumentation follows semantic conventions #1625

Open
Tracked by #1624
srikanthccv opened this issue Feb 4, 2023 · 2 comments
Open
Tracked by #1624

Make sure sqlite3 instrumentation follows semantic conventions #1625

srikanthccv opened this issue Feb 4, 2023 · 2 comments
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed instrumentation

Comments

@srikanthccv
Copy link
Member

No description provided.

@Anu-MT
Copy link

Anu-MT commented Aug 1, 2023

Hi,
I would like to work on the issue. Would you assign this to me?Any guidance will be greatly appreciated.

@baravkareknath
Copy link

Hi srikanthccv and Anu-MT,
I think I am able to resolve this issue as below-

from opentelemetry import trace
from opentelemetry.instrumentation.dbapi import trace_integration
import sqlite3

Initialize tracer

tracer = tracer.get_tracer(name)

Instrument sqlite3

tracer_integration(sqlite3, "connect", "sqlite3")

Connect to database

conn = sqlite3.connect("example.db")

Create cursor

cur = conn.cursor()

Example db operation with instrumentation

with tracer.start_as_current_span("example-database-operation") as span:
cur.execute("select * from example_table")

    # Add sematic attributes
    span.set_attribute("db.system", "sqlite")
    span.set_attribute("db.name", "example.db")
    span.set_attribute("db.statement", "select * from example_table")
  
    # fetch results
    results = cur.fetchall()

close connection

conn.close()

Like this is it correct way to resolve this issue.
And please guide me in that because I am first time contributor.
If is it correct way, please let me know where this code part implements in the repository.
Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed instrumentation
Projects
None yet
Development

No branches or pull requests

3 participants