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

Plugins and Versions Refactor #5015

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/datadog-plugin-aws-sdk/test/aws-sdk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const agent = require('../../dd-trace/test/plugins/agent')
const { setup, sort } = require('./spec_helpers')
const semver = require('semver')
const { ERROR_MESSAGE, ERROR_STACK, ERROR_TYPE } = require('../../dd-trace/src/constants')
const { getEquivVersion } = require('../../dd-trace/test/setup/helpers/version-utils')

describe('Plugin', () => {
// TODO: use the Request class directly for generic tests
Expand Down Expand Up @@ -75,14 +76,16 @@ describe('Plugin', () => {

const s3ClientName = moduleName === '@aws-sdk/smithy-client' ? '@aws-sdk/client-s3' : 'aws-sdk'
const sqsClientName = moduleName === '@aws-sdk/smithy-client' ? '@aws-sdk/client-sqs' : 'aws-sdk'
const versionCtx = withVersions.context

describe('without configuration', () => {
before(() => {
return agent.load(['aws-sdk', 'http'], [{}, { server: false }])
})

before(() => {
AWS = require(`../../../versions/${s3ClientName}@${version}`).get()
const clientVersion = getEquivVersion(s3ClientName, versionCtx)
AWS = require(`../../../versions/${s3ClientName}@${clientVersion}`).get()
s3 = new AWS.S3({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1', s3ForcePathStyle: true })
tracer = require('../../dd-trace')
})
Expand Down Expand Up @@ -225,7 +228,8 @@ describe('Plugin', () => {
})

before(() => {
AWS = require(`../../../versions/${s3ClientName}@${version}`).get()
const clientVersion = getEquivVersion(s3ClientName, versionCtx)
AWS = require(`../../../versions/${s3ClientName}@${clientVersion}`).get()
s3 = new AWS.S3({ endpoint: 'http://127.0.0.1:5000', region: 'us-east-1', s3ForcePathStyle: true })
tracer = require('../../dd-trace')
})
Expand Down Expand Up @@ -262,8 +266,10 @@ describe('Plugin', () => {
})

before(() => {
const { S3 } = require(`../../../versions/${s3ClientName}@${version}`).get()
const { SQS } = require(`../../../versions/${sqsClientName}@${version}`).get()
const s3Version = getEquivVersion(s3ClientName, versionCtx)
const { S3 } = require(`../../../versions/${s3ClientName}@${s3Version}`).get()
const sqsVersion = getEquivVersion(s3ClientName, versionCtx)
const { SQS } = require(`../../../versions/${sqsClientName}@${sqsVersion}`).get()

s3 = new S3({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1', s3ForcePathStyle: true })
sqs = new SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
Expand Down
8 changes: 6 additions & 2 deletions packages/datadog-plugin-aws-sdk/test/kinesis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const agent = require('../../dd-trace/test/plugins/agent')
const { setup } = require('./spec_helpers')
const helpers = require('./kinesis_helpers')
const { rawExpectedSchema } = require('./kinesis-naming')
const { getEquivVersion } = require('../../dd-trace/test/setup/helpers/version-utils')

describe('Kinesis', function () {
this.timeout(10000)
Expand All @@ -19,17 +20,20 @@ describe('Kinesis', function () {
const streamName = 'MyStream'
const streamNameDSM = 'MyStreamDSM'
const kinesisClientName = moduleName === '@aws-sdk/smithy-client' ? '@aws-sdk/client-kinesis' : 'aws-sdk'
const versionCtx = withVersions.context

function createResources (streamName, cb) {
AWS = require(`../../../versions/${kinesisClientName}@${version}`).get()
const clientVersion = getEquivVersion(kinesisClientName, versionCtx)
AWS = require(`../../../versions/${kinesisClientName}@${clientVersion}`).get()

const params = {
endpoint: 'http://127.0.0.1:4566',
region: 'us-east-1'
}

if (moduleName === '@aws-sdk/smithy-client') {
const { NodeHttpHandler } = require(`../../../versions/@aws-sdk/node-http-handler@${version}`).get()
const handlerVersion = getEquivVersion('@aws-sdk/node-http-handler', versionCtx)
const { NodeHttpHandler } = require(`../../../versions/@aws-sdk/node-http-handler@${handlerVersion}`).get()

params.requestHandler = new NodeHttpHandler()
}
Expand Down
4 changes: 3 additions & 1 deletion packages/datadog-plugin-aws-sdk/test/lambda.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const JSZip = require('jszip')
const agent = require('../../dd-trace/test/plugins/agent')
const { setup } = require('./spec_helpers')
const { rawExpectedSchema } = require('./lambda-naming')
const { getEquivVersion } = require('../../dd-trace/test/setup/helpers/version-utils')

const zip = new JSZip()

Expand All @@ -19,6 +20,7 @@ describe('Plugin', () => {
let tracer

const lambdaClientName = moduleName === '@aws-sdk/smithy-client' ? '@aws-sdk/client-lambda' : 'aws-sdk'
const lambdaClientVersion = getEquivVersion(lambdaClientName, withVersions.context)

const parsePayload = payload => {
if (typeof payload !== 'string') {
Expand All @@ -38,7 +40,7 @@ describe('Plugin', () => {
})

before(done => {
AWS = require(`../../../versions/${lambdaClientName}@${version}`).get()
AWS = require(`../../../versions/${lambdaClientName}@${lambdaClientVersion}`).get()

lambda = new AWS.Lambda({ endpoint: 'http://127.0.0.1:4567', region: 'us-east-1' })
lambda.createFunction({
Expand Down
6 changes: 5 additions & 1 deletion packages/datadog-plugin-aws-sdk/test/s3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { setup } = require('./spec_helpers')
const axios = require('axios')
const { rawExpectedSchema } = require('./s3-naming')
const { S3_PTR_KIND, SPAN_POINTER_DIRECTION } = require('../../dd-trace/src/constants')
const { getEquivVersion } = require('../../dd-trace/test/setup/helpers/version-utils')

const bucketName = 's3-bucket-name-test'

Expand All @@ -27,6 +28,8 @@ describe('Plugin', () => {
let s3
let tracer

const versionCtx = withVersions.context

const s3ClientName = moduleName === '@aws-sdk/smithy-client' ? '@aws-sdk/client-s3' : 'aws-sdk'
describe('with configuration', () => {
before(() => {
Expand All @@ -36,7 +39,8 @@ describe('Plugin', () => {
})

before(done => {
AWS = require(`../../../versions/${s3ClientName}@${version}`).get()
const clientVersion = getEquivVersion(s3ClientName, versionCtx)
AWS = require(`../../../versions/${s3ClientName}@${clientVersion}`).get()
s3 = new AWS.S3({ endpoint: 'http://127.0.0.1:4566', s3ForcePathStyle: true, region: 'us-east-1' })

// Fix for LocationConstraint issue - only for SDK v2
Expand Down
7 changes: 5 additions & 2 deletions packages/datadog-plugin-aws-sdk/test/sns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const semver = require('semver')
const agent = require('../../dd-trace/test/plugins/agent')
const { setup } = require('./spec_helpers')
const { rawExpectedSchema } = require('./sns-naming')
const { getEquivVersion } = require('../../dd-trace/test/setup/helpers/version-utils')

describe('Sns', function () {
setup()
Expand All @@ -24,6 +25,8 @@ describe('Sns', function () {

const snsClientName = moduleName === '@aws-sdk/smithy-client' ? '@aws-sdk/client-sns' : 'aws-sdk'
const sqsClientName = moduleName === '@aws-sdk/smithy-client' ? '@aws-sdk/client-sqs' : 'aws-sdk'
const snsVersion = getEquivVersion(snsClientName, withVersions.context)
const sqsVersion = getEquivVersion(sqsClientName, withVersions.context)

let childSpansFound = 0
const assertPropagation = (done, childSpans = 1) => {
Expand All @@ -45,8 +48,8 @@ describe('Sns', function () {
}

function createResources (queueName, topicName, cb) {
const { SNS } = require(`../../../versions/${snsClientName}@${version}`).get()
const { SQS } = require(`../../../versions/${sqsClientName}@${version}`).get()
const { SNS } = require(`../../../versions/${snsClientName}@${snsVersion}`).get()
const { SQS } = require(`../../../versions/${sqsClientName}@${sqsVersion}`).get()

sns = new SNS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
sqs = new SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
Expand Down
13 changes: 9 additions & 4 deletions packages/datadog-plugin-aws-sdk/test/sqs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const { setup } = require('./spec_helpers')
const semver = require('semver')
const { rawExpectedSchema } = require('./sqs-naming')
const { getEquivVersion } = require('../../dd-trace/test/setup/helpers/version-utils')

const queueName = 'SQS_QUEUE_NAME'
const queueNameDSM = 'SQS_QUEUE_NAME_DSM'
Expand Down Expand Up @@ -36,6 +37,7 @@
let tracer

const sqsClientName = moduleName === '@aws-sdk/smithy-client' ? '@aws-sdk/client-sqs' : 'aws-sdk'
const clientVersion = getEquivVersion(sqsClientName, withVersions.context)

describe('without configuration', () => {
before(() => {
Expand All @@ -49,7 +51,7 @@
})

before(done => {
AWS = require(`../../../versions/${sqsClientName}@${version}`).get()
AWS = require(`../../../versions/${sqsClientName}@${clientVersion}`).get()

sqs = new AWS.SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
sqs.createQueue(queueOptions, (err, res) => {
Expand Down Expand Up @@ -314,7 +316,8 @@
})

before(done => {
AWS = require(`../../../versions/${sqsClientName}@${version}`).get()
const clientVersion = getEquivVersion(sqsClientName, versionCtx)

Check failure on line 319 in packages/datadog-plugin-aws-sdk/test/sqs.spec.js

View workflow job for this annotation

GitHub Actions / lint

'versionCtx' is not defined
AWS = require(`../../../versions/${sqsClientName}@${clientVersion}`).get()

sqs = new AWS.SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
sqs.createQueue(queueOptions, (err, res) => {
Expand Down Expand Up @@ -405,7 +408,8 @@
})

before(done => {
AWS = require(`../../../versions/${sqsClientName}@${version}`).get()
const clientVersion = getEquivVersion(sqsClientName, versionCtx)

Check failure on line 411 in packages/datadog-plugin-aws-sdk/test/sqs.spec.js

View workflow job for this annotation

GitHub Actions / lint

'versionCtx' is not defined
AWS = require(`../../../versions/${sqsClientName}@${clientVersion}`).get()

sqs = new AWS.SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
sqs.createQueue(queueOptionsDsm, (err, res) => {
Expand All @@ -416,7 +420,8 @@
})

before(done => {
AWS = require(`../../../versions/${sqsClientName}@${version}`).get()
const clientVersion = getEquivVersion(sqsClientName, versionCtx)

Check failure on line 423 in packages/datadog-plugin-aws-sdk/test/sqs.spec.js

View workflow job for this annotation

GitHub Actions / lint

'versionCtx' is not defined
AWS = require(`../../../versions/${sqsClientName}@${clientVersion}`).get()

sqs = new AWS.SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
sqs.createQueue(queueOptionsDsmConsumerOnly, (err, res) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const semver = require('semver')
const agent = require('../../dd-trace/test/plugins/agent')
const { setup } = require('./spec_helpers')
const { getEquivVersion } = require('../../dd-trace/test/setup/helpers/version-utils')

const helloWorldSMD = {
Comment: 'A Hello World example of the Amazon States Language using a Pass state',
Expand All @@ -23,6 +24,7 @@ describe('Sfn', () => {
withVersions('aws-sdk', ['aws-sdk', '@aws-sdk/smithy-client'], (version, moduleName) => {
let stateMachineArn
let client
const versionCtx = withVersions.context

setup()

Expand All @@ -33,7 +35,8 @@ describe('Sfn', () => {
function getClient () {
const params = { endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' }
if (moduleName === '@aws-sdk/smithy-client') {
const lib = require(`../../../versions/@aws-sdk/client-sfn@${version}`).get()
const sfnVersion = getEquivVersion('@aws-sdk/client-sfn', versionCtx)
const lib = require(`../../../versions/@aws-sdk/client-sfn@${sfnVersion}`).get()
const client = new lib.SFNClient(params)
return {
client,
Expand Down
8 changes: 6 additions & 2 deletions packages/datadog-plugin-langchain/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { useEnv } = require('../../../integration-tests/helpers')
const agent = require('../../dd-trace/test/plugins/agent')
const { getEquivVersion } = require('../../dd-trace/test/setup/helpers/version-utils')

const nock = require('nock')

Expand Down Expand Up @@ -33,6 +34,9 @@ describe('Plugin', () => {

describe('langchain', () => {
withVersions('langchain', ['@langchain/core'], version => {
const openAiVersion = getEquivVersion('@langchain/openai', withVersions.context)
const anthropicVersion = getEquivVersion('@langchain/anthropic', withVersions.context)

beforeEach(() => {
return agent.load('langchain')
})
Expand All @@ -43,8 +47,8 @@ describe('Plugin', () => {
})

beforeEach(() => {
langchainOpenai = require(`../../../versions/@langchain/openai@${version}`).get()
langchainAnthropic = require(`../../../versions/@langchain/anthropic@${version}`).get()
langchainOpenai = require(`../../../versions/@langchain/openai@${openAiVersion}`).get()
langchainAnthropic = require(`../../../versions/@langchain/anthropic@${anthropicVersion}`).get()

// need to specify specific import in `get(...)`
langchainMessages = require(`../../../versions/@langchain/core@${version}`).get('@langchain/core/messages')
Expand Down
62 changes: 62 additions & 0 deletions packages/dd-trace/test/setup/helpers/load-inst.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict'

const fs = require('fs')
const path = require('path')
const proxyquire = require('proxyquire')

function loadInstFile (file, instrumentations) {
const instrument = {
addHook (instrumentation) {
instrumentations.push(instrumentation)
}
}

const instPath = path.join(__dirname, `../../../../datadog-instrumentations/src/${file}`)

proxyquire.noPreserveCache()(instPath, {
'./helpers/instrument': instrument,
'../helpers/instrument': instrument
})
}

function loadOneInst (name) {
const instrumentations = []

try {
loadInstFile(`${name}/server.js`, instrumentations)
loadInstFile(`${name}/client.js`, instrumentations)
} catch (e) {
try {
loadInstFile(`${name}/main.js`, instrumentations)
} catch (e) {
loadInstFile(`${name}.js`, instrumentations)
}
}

return instrumentations
}

function getAllInstrumentations () {
const names = fs.readdirSync(path.join(__dirname, '../../../../', 'datadog-instrumentations', 'src'))
.filter(file => file.endsWith('.js'))
.map(file => file.slice(0, -3))

const instrumentations = names.reduce((acc, key) => {
const name = key
let instrumentations = loadOneInst(name)

instrumentations = instrumentations.filter(i => i.versions)
if (instrumentations.length) {
acc[key] = instrumentations
}

return acc
}, {})

return instrumentations
}

module.exports = {
getInstrumentation: loadOneInst,
getAllInstrumentations
}
Loading
Loading