open-telemetry / open-telemetry/opentelemetry-python-contrib

Default SQLite3 cursor is not instrumented

Open
#3,082 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Describe your environment

OS: (e.g, Ubuntu)
Python version: (e.g., Python 3.8.10)
Package version: (e.g., 0.46.0)

What happened?

The default sqlite3.Cursor is not instrumented.

Steps to Reproduce
import sqlite3

from opentelemetry.instrumentation.sqlite3 import SQLite3Instrumentor

import logfire

logfire.configure()

SQLite3Instrumentor().instrument()

cnx = sqlite3.connect(':memory:')
cnx.execute('CREATE TABLE test (testField INTEGER)')
cnx.close()
Expected Result

I would expect a span to be created for the table creation.

Actual Result

The span was not created.

Instead, if you do...

import sqlite3

from opentelemetry.instrumentation.sqlite3 import SQLite3Instrumentor

import logfire

logfire.configure()

SQLite3Instrumentor().instrument()

cnx = sqlite3.connect(':memory:')
cursor = cnx.cursor()
cursor.execute('CREATE TABLE test (testField INTEGER)')
cursor.close()
cnx.close()
Additional context

The documentation should be updated... The code there doesn't run as is...

https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/sqlite3/sqlite3.html

It should create the table first!

Would you like to implement a fix?

None

PRs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SQLite3Instrumentor and reproduce the two examples from the issue, then read the SQLite3 instrumentation documentation linked in the report. The fix is done when the default connection.execute path creates a span for table creation and the documentation example runs as written.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
databases, observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.