Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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,
)
Loading