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

psycopg3 support #585

Open
alexeyshockov opened this issue Jul 20, 2022 · 17 comments
Open

psycopg3 support #585

alexeyshockov opened this issue Jul 20, 2022 · 17 comments

Comments

@alexeyshockov
Copy link

Hey, thanks for the great monitoring integration! psycong3 was released in October 2021, do you have any plans to support it? Would be really nice to have a hook for this lib, as it brings a lot of useful features.

@gushecht
Copy link

Hi @alexeyshockov! I'll start by saying that I am not an expert of psycopg3, or New Relic, or even Python, but we came across this problem today and also this issue that you opened.

Perhaps you've solved this already, but, if not, here's how I addressed it.

For context, startup.py is the entry point for our web server.

startup.py

import psycopg
from newrelic_custom_instrumentation import instrument_psycopg3_async_cursor
instrument_psycopg3_async_cursor(psycopg)

# ... loads of other unrelated stuff

newrelic_custom_instrumentation.py

from newrelic.api.database_trace import (
    DatabaseTrace,
    enable_datastore_instance_feature,
    register_database_client,
)
from newrelic.common.object_wrapper import wrap_function_wrapper


# TODO – I'm not certain we're getting everything we want out of this – I based it off database_asyncpg
class PostgresApi(object):
    @staticmethod
    def _instance_info(addr, connected_fut, con_params, *args, **kwargs):
        if isinstance(addr, str):
            host = "localhost"
            port = addr
        else:
            host, port = addr

        return host, str(port), getattr(con_params, "database", None)

    @classmethod
    def instance_info(cls, args, kwargs):
        return cls._instance_info(*args, **kwargs)


register_database_client(
    PostgresApi,
    "Postgres",
    quoting_style="single+dollar",
    instance_info=PostgresApi.instance_info,
)
enable_datastore_instance_feature(PostgresApi)


# TODO – Similarly, there may be more things we can pass to DatabaseTrace
async def wrap_execute(wrapped, instance, args, kwargs):
    query, params = args
    with DatabaseTrace(
            query,
            database_name=instance.connection.info.dbname,
            dbapi2_module=PostgresApi,
            host=instance.connection.info.host,
            port_path_or_id=instance.connection.info.port,
            source=instance.execute,
            sql_parameters=params,
    ):
        return await wrapped(*args, **kwargs)


def instrument_psycopg3_async_cursor(module):
    wrap_function_wrapper(module, "AsyncCursor.execute", wrap_execute)

As you see in my TODO comments above, I'm sure that we're missing out on more capabilities. We also have a limited use of psycopg3, hence only needing to instrument AsyncCursor.execute. Nevertheless, hopefully this helps.

@stale
Copy link

stale bot commented Nov 12, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 12, 2022
@alexeyshockov
Copy link
Author

Hey @gushecht, thanks a lot for the snippet! Currently I put this on hold in my app, in favour of "good old" psycopg2. But I'm really looking forward to hear any updates from New Relic team here...

@stale stale bot removed the stale label Nov 14, 2022
@Ak-x
Copy link

Ak-x commented Nov 16, 2022

We have reviewed this ticket with the team and have created a Feature Request to get this through in our backlog.
cc: @ak-war

@stale
Copy link

stale bot commented Mar 18, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 18, 2023
@risoms
Copy link

risoms commented May 12, 2023

@Ak-x Is there any plan on support this? psycopg3 has been available for a few years now.

@stale stale bot removed the stale label May 12, 2023
@gvangool
Copy link

gvangool commented Jul 6, 2023

We're curious as well about psycopg/psycopg3 support.

We switched to it because of Django 4.2's official support.

@sinwoobang
Copy link

I am into this topic.

@Ak-x
Copy link

Ak-x commented Aug 24, 2023

Hey all, thank you for your interest. We have started to add this to our upcoming roadmap and will start to notify this group as we approach taking this on.

@pleasedontbelong
Copy link

Hello people ^^
Is there an update on this?

@adamJLev
Copy link

Come on newrelic, psycopg3 is not some obscure library used by a few people, and its been out for years now.
Django already said they're deprecating psycopg2, so this is way overdue.
Hope you guys can prioritize this, thanks

@kwood
Copy link

kwood commented Dec 23, 2023

@TimPansino @lrafeei Can someone from NewRelic comment on whether psycopg3 will be supported in the near future?

@lrafeei
Copy link
Contributor

lrafeei commented Dec 28, 2023

Hello--sorry about the delay. We are looking into adding psycopg3 as a supported framework. Unfortunately, we cannot commit to releasing that this coming quarter (but we're really hoping for the following quarter).

@msainty
Copy link

msainty commented Mar 20, 2024

Hey New Relic or @lrafeei, Checking if there is any commitment to release this soon?

@umaannamalai
Copy link
Contributor

Hey all! We have psycopg3 support up next on our priority list in the coming quarter. We will inform you all when the release goes live.

@rodolfolottin
Copy link

Hey all! We have psycopg3 support up next on our priority list in the coming quarter. We will inform you all when the release goes live.

Nice! Looking forward to this.

@tarasinf
Copy link

Any updates here? We are looking for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests