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

adding nrpgx5 instrumentation tracer for github.com/jackc/pgx/v5 #592

Merged

Conversation

egon12
Copy link
Contributor

@egon12 egon12 commented Oct 24, 2022

This PR are adding instrumentation for nrpgx/v5 (https://github.com/jackc/pgx)

Links

The discussion about new tracing in pgx jackc/pgx#1061.
Open Telemetry Implementation for this tracing feature https://github.com/exaring/otelpgx/blob/main/tracer.go

Details

The pgx library has new tracing support in v5. Before pgx only support for logging that only provide us with duration of the operation. With this new tracing feature, we can create new Segment at QueryStart and End the Segment with QueryEnd

For passing the segment between QueryStart and QueryEnd we use context.Context. This folllow the implementation from open telemetry.

And for the Host, Port and Database Name, I try to follow database/sql implementation in nrpq and nrpgx by using BaseSegment.

To use the library you can use this code

cfg, _ := pgx.ParseConfig(context.Backgroud(), "<url here>")
cfg.Tracer = nrpgx5.NewTracer()

pgx.ConnectConfig(context.Background(), cfg)

@iamemilio
Copy link
Contributor

Hi @egon12, thanks for contributing. Could you please include a simple example of how to use this library in a directory named example/.

@iamemilio
Copy link
Contributor

I am not sure at which point in this extension we should be incorporating the go-agent

@egon12
Copy link
Contributor Author

egon12 commented Nov 2, 2022

Just for info, this is related for this issues #386.
But In pgx/v4, we don't have tracer interface yet. So it's hard to add instrumentation.
In pgx/v5, the maintainer add tracer interface. And we can use that to add newrelic instrumentation

@egon12
Copy link
Contributor Author

egon12 commented Nov 11, 2022

Hello are there any update on this?

@iamemilio iamemilio changed the base branch from master to develop November 11, 2022 15:01
@iamemilio
Copy link
Contributor

iamemilio commented Nov 11, 2022

Looks good to me, thanks for submitting this. Once you address the comment I left, you have my approval!

UPDATE: I went ahead and patched this up, since we are planning a release tomorrow. Thanks for submitting this, it should be live in the v3.20.1 release by EOD tomorrow :)

@iamemilio iamemilio self-assigned this Nov 14, 2022
@iamemilio iamemilio force-pushed the pr/feature/integrations/nrpgx5 branch from 7b254a5 to 164c417 Compare November 14, 2022 20:13
@nr-swilloughby nr-swilloughby merged commit 348286e into newrelic:develop Nov 15, 2022
@BertBR
Copy link

BertBR commented Mar 3, 2023

There's any equivalent implementation for v4?

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

Successfully merging this pull request may close these issues.

4 participants