Socket
Socket
Sign inDemoInstall

github.com/newrelic/go-agent/v3/integrations/nrpq/example/sqlx

Package Overview
Dependencies
4
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/newrelic/go-agent/v3/integrations/nrpq/example/sqlx

An application that illustrates how to instrument jmoiron/sqlx with DatastoreSegments To run this example, be sure the environment varible NEW_RELIC_LICENSE_KEY is set to your license key. Postgres must be running on the default port 5432 and have a user "foo" and a database "bar". One quick (albeit insecure) way of doing this is to run a small local Postgres instance in Docker: Adding instrumentation for the SQLx package is easy. It means you can make database calls without having to manually create DatastoreSegments. Setup can be done in two steps: If you are using one of our currently supported database drivers (see https://docs.newrelic.com/docs/agents/go-agent/get-started/go-agent-compatibility-requirements#frameworks), follow the instructions on installing the driver. As an example, for the `lib/pq` driver, you will use the newrelic integration's driver in place of the postgres driver. If your code is using sqlx.Open with `lib/pq` like this: Then change the side-effect import to the integration package, and open "nrpostgres" instead: If you are not using one of the supported database drivers, use the `InstrumentSQLDriver` (https://godoc.org/github.com/newrelic/go-agent#InstrumentSQLDriver) API. See https://github.com/newrelic/go-agent/blob/master/v3/integrations/nrmysql/nrmysql.go for a full example. Next, you must provide a context containing a newrelic.Transaction to all methods on sqlx.DB, sqlx.NamedStmt, sqlx.Stmt, and sqlx.Tx that make a database call. For example, instead of the following: Do this:


Version published

FAQs

Last updated on 14 Dec 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc