How do I give database queries names?

I am using the Java agent version 3.35.2 in an application that uses JDBC to talk to a PostgreSQL database. The thing is, that all the query names are just not helpful - see attached image.

I could tell New Relic a great query name every time, is there an API call / attribute for that?

Hi @vektor

Java Agent version 3.36.0 introduce API functionality for Custom Instrumentation of Datastore (Database) calls: https://docs.newrelic.com/docs/agents/java-agent/custom-instrumentation/java-api-instrumenting-example-app-external-datastore-calls-cat

You might be able to use this to submit your own names. Though I am uncertain on the specifics of the implementation there. If you are able to, we’d love to have an update on how you did it here.

Please also keep metric grouping issue in mind when doing any custom instrumentation or naming.

First of all - thanks for the link, it actually pointed me to another thing I needed to solve :slight_smile:

Regarding the new APIs - it seems to be going in a good direction, in particular this part

// Create a DatastoreParameters object and report a call to an external datastore service
method.reportAsExternal(
  DatastoreParameters
    .product("sqlite")
    .collection("test.db")
    .operation("select")
    .instance("localhost", 8080)
    .databaseName("test.db")
    .build());

is almost exactly the data I expect to be able to tell New Relic. Having said that, this code is explicitly reporting the call as “external” which sounds like quite the hack.

I will give it a shot later on after I upgrade to the latest agent/API.

Thanks again!