Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3129](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3129))
- `opentelemetry-util-http` Add `py.typed` file to enable PEP 561
([#3127](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3127))
- `opentelemetry-instrumentation-psycopg2` Add support for psycopg2-binary
([#3186](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3186))

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
| [opentelemetry-instrumentation-mysqlclient](./opentelemetry-instrumentation-mysqlclient) | mysqlclient < 3 | No | experimental
| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 0.12.0 | No | experimental
| [opentelemetry-instrumentation-psycopg](./opentelemetry-instrumentation-psycopg) | psycopg >= 3.1.0 | No | experimental
| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1 | No | experimental
| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1,psycopg2-binary >= 2.7.3.1 | No | experimental
| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 5 | No | experimental
| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 | No | experimental
| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | No | experimental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
[project.optional-dependencies]
instruments = [
"psycopg2 >= 2.7.3.1",
"psycopg2-binary >= 2.7.3.1",
]

[project.entry-points.opentelemetry_instrumentor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@

import logging
import typing
from importlib.metadata import PackageNotFoundError, distribution
from typing import Collection

import psycopg2
Expand All @@ -149,7 +150,11 @@

from opentelemetry.instrumentation import dbapi
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.psycopg2.package import _instruments
from opentelemetry.instrumentation.psycopg2.package import (
_instruments,
_instruments_psycopg2,
_instruments_psycopg2_binary,
)
from opentelemetry.instrumentation.psycopg2.version import __version__

_logger = logging.getLogger(__name__)
Expand All @@ -167,6 +172,21 @@ class Psycopg2Instrumentor(BaseInstrumentor):
_DATABASE_SYSTEM = "postgresql"

def instrumentation_dependencies(self) -> Collection[str]:
# Determine which package of psycopg2 is installed
# Right now there are two packages, psycopg2 and psycopg2-binary
# The latter is a binary wheel package that does not require a compiler
try:
distribution("psycopg2")
return (_instruments_psycopg2,)
except PackageNotFoundError:
pass

try:
distribution("psycopg2-binary")
return (_instruments_psycopg2_binary,)
except PackageNotFoundError:
pass

return _instruments

def _instrument(self, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
# limitations under the License.


_instruments = ("psycopg2 >= 2.7.3.1",)
_instruments_psycopg2 = "psycopg2 >= 2.7.3.1"
_instruments_psycopg2_binary = "psycopg2-binary >= 2.7.3.1"

_instruments = (
_instruments_psycopg2,
_instruments_psycopg2_binary,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
asgiref==3.8.1
Deprecated==1.2.14
iniconfig==2.0.0
packaging==24.0
pluggy==1.5.0
psycopg2-binary==2.9.10
py-cpuinfo==9.0.0
pytest==7.4.4
tomli==2.0.1
typing_extensions==4.12.2
wrapt==1.16.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-dbapi
-e instrumentation/opentelemetry-instrumentation-psycopg2
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
"library": "psycopg2 >= 2.7.3.1",
"instrumentation": "opentelemetry-instrumentation-psycopg2==0.51b0.dev",
},
{
"library": "psycopg2-binary >= 2.7.3.1",
"instrumentation": "opentelemetry-instrumentation-psycopg2==0.51b0.dev",
},
{
"library": "pymemcache >= 1.3.5, < 5",
"instrumentation": "opentelemetry-instrumentation-pymemcache==0.51b0.dev",
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ deps =

psycopg2: {[testenv]test_deps}
psycopg2: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-psycopg2/test-requirements.txt
psycopg2-binary: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-psycopg2/test-requirements-binary.txt

pymysql: {[testenv]test_deps}
pymysql: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-pymysql/test-requirements.txt
Expand Down
Loading