Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
feat(plugin-neo4j): support for neo4j-driver up to 5.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mackermans committed Sep 13, 2023
1 parent c5e6027 commit c4bbecd
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 179 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -738,12 +738,12 @@ jobs:
runs-on: ubuntu-latest
services:
neo4j:
image: neo4j:4.2.3
image: neo4j:5.11.0
env:
NEO4J_AUTH: 'neo4j/test'
NEO4J_AUTH: 'neo4j/test-password'
ports:
- 7474:7474
- 11011:7687
- 7687:7687
env:
PLUGINS: neo4j
SERVICES: neo4j
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ services:
ports:
- "127.0.0.1:8081:8081"
neo4j:
image: neo4j:4.2.3
image: neo4j:5.11.0
environment:
- NEO4J_AUTH=neo4j/test
- NEO4J_AUTH=neo4j/test-password
ports:
- "7474:7474"
- "11011:7687"
- "7687:7687"
localstack:
# TODO: Figure out why SNS doesn't work in >=1.2
# https://github.com/localstack/localstack/issues/7479
Expand Down
3 changes: 2 additions & 1 deletion packages/datadog-instrumentations/src/helpers/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ module.exports = {
'mongoose': () => require('../mongoose'),
'mysql': () => require('../mysql'),
'mysql2': () => require('../mysql2'),
'neo4j': () => require('../neo4j'),
'neo4j-driver': () => require('../neo4j'),
'neo4j-driver-core': () => require('../neo4j'),
'net': () => require('../net'),
'next': () => require('../next'),
'oracledb': () => require('../oracledb'),
Expand Down
83 changes: 59 additions & 24 deletions packages/datadog-instrumentations/src/neo4j.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,53 @@ const startCh = channel('apm:neo4j:query:start')
const finishCh = channel('apm:neo4j:query:finish')
const errorCh = channel('apm:neo4j:query:error')

addHook({ name: 'neo4j-driver-core', file: 'lib/session.js', versions: ['>=4.3.0'] }, exports => {
const Session = exports.default
shimmer.wrap(Session.prototype, 'run', wrapRun)
return Session
})

addHook({ name: 'neo4j-driver-core', file: 'lib/transaction.js', versions: ['>=4.3.0'] }, exports => {
const Transaction = exports.default
shimmer.wrap(Transaction.prototype, 'run', wrapRun)
return Transaction
})

addHook({ name: 'neo4j-driver', file: 'lib/session.js', versions: ['<4.3.0', '>=4.0.0'] }, exports => {
const Session = exports.default
shimmer.wrap(Session.prototype, 'run', wrapRun)
return Session
})

addHook({ name: 'neo4j-driver', file: 'lib/transaction.js', versions: ['<4.3.0', '>=4.0.0'] }, exports => {
const Transaction = exports.default
shimmer.wrap(Transaction.prototype, 'run', wrapRun)
return Transaction
})
addHook(
{
name: 'neo4j-driver-core',
file: 'lib/session.js',
versions: ['>=4.3.0']
},
(exports) => {
shimmer.wrap(exports.default.prototype, 'run', wrapRun)
return exports
}
)

addHook(
{
name: 'neo4j-driver-core',
file: 'lib/transaction.js',
versions: ['>=4.3.0']
},
(exports) => {
shimmer.wrap(exports.default.prototype, 'run', wrapRun)
return exports
}
)

addHook(
{
name: 'neo4j-driver',
file: 'lib/session.js',
versions: ['>=4.0.0 <4.3.0']
},
(exports) => {
shimmer.wrap(exports.default.prototype, 'run', wrapRun)
return exports
}
)

addHook(
{
name: 'neo4j-driver',
file: 'lib/transaction.js',
versions: ['>=4.0.0 <4.3.0']
},
(exports) => {
shimmer.wrap(exports.default.prototype, 'run', wrapRun)
return exports
}
)

function wrapRun (run) {
return function (statement) {
Expand Down Expand Up @@ -86,7 +110,6 @@ function getAttributesFromNeo4jSession (session) {

// seedRouter is used when connecting to a url that starts with "neo4j", usually aura
const address = connectionProvider._address || connectionProvider._seedRouter
const auth = connectionProvider._authToken || {}

const attributes = {
// "neo4j" is the default database name. When used, "session._database" is an empty string
Expand All @@ -96,8 +119,20 @@ function getAttributesFromNeo4jSession (session) {
attributes.host = address._host
attributes.port = address._port
}

// neo4j-driver <5.12.0
const auth = connectionProvider._authToken || {}
if (auth.principal) {
attributes.dbUser = auth.principal
}

// neo4j-driver >=5.12.0
const authProvider = connectionProvider._authenticationProvider || {}
const authTokenManager = authProvider._authTokenManager || {}
const authToken = authTokenManager._authToken || {}
if (authToken.principal) {
attributes.dbUser = authToken.principal
}

return attributes
}
Loading

0 comments on commit c4bbecd

Please sign in to comment.