Skip to content
Merged
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
18 changes: 7 additions & 11 deletions .github/workflows/debugger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,21 @@ concurrency:

jobs:
ubuntu:
strategy:
matrix:
version: [18, 20, 22, latest]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: ./.github/actions/testagent/start
- uses: ./.github/actions/node/oldest-maintenance-lts
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: ${{ matrix.version }}
- uses: ./.github/actions/install
- run: yarn test:debugger:ci
- run: yarn test:integration:debugger
- uses: ./.github/actions/node/newest-maintenance-lts
- run: yarn test:debugger:ci
- run: yarn test:integration:debugger
- uses: ./.github/actions/node/active-lts
- run: yarn test:debugger:ci
- run: yarn test:integration:debugger
- uses: ./.github/actions/node/latest
- run: yarn test:debugger:ci
- run: yarn test:integration:debugger
- if: always()
uses: ./.github/actions/testagent/logs
with:
suffix: debugger
suffix: debugger-ubuntu-${{ matrix.version }}
- uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dd-trace",
"version": "5.44.0",
"version": "5.45.0",
"description": "Datadog APM tracing client for JavaScript",
"main": "index.js",
"typings": "index.d.ts",
Expand Down
85 changes: 3 additions & 82 deletions packages/datadog-plugin-langchain/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ describe('Plugin', () => {

describe('langchain', () => {
withVersions('langchain', ['@langchain/core'], version => {
beforeEach(() => {
before(() => {
return agent.load('langchain')
})

afterEach(() => {
// wiping in order to read new env vars for the config each time
return agent.close({ ritmReset: false, wipe: true })
after(() => {
return agent.close({ ritmReset: false })
})

beforeEach(() => {
Expand All @@ -65,84 +64,6 @@ describe('Plugin', () => {
nock.cleanAll()
})

describe('with global configurations', () => {
describe('with sampling rate', () => {
useEnv({
DD_LANGCHAIN_SPAN_PROMPT_COMPLETION_SAMPLE_RATE: 0
})

it('does not tag prompt or completion', async () => {
stubCall({
...openAiBaseCompletionInfo,
response: {
model: 'gpt-3.5-turbo-instruct',
choices: [{
text: 'The answer is 4',
index: 0,
logprobs: null,
finish_reason: 'length'
}],
usage: { prompt_tokens: 8, completion_tokens: 12, otal_tokens: 20 }
}
})

const llm = new langchainOpenai.OpenAI({ model: 'gpt-3.5-turbo-instruct' })
const checkTraces = agent
.use(traces => {
expect(traces[0].length).to.equal(1)
const span = traces[0][0]

expect(span.meta).to.not.have.property('langchain.request.prompts.0.content')
expect(span.meta).to.not.have.property('langchain.response.completions.0.text')
})

const result = await llm.generate(['what is 2 + 2?'])

expect(result.generations[0][0].text).to.equal('The answer is 4')

await checkTraces
})
})

describe('with span char limit', () => {
useEnv({
DD_LANGCHAIN_SPAN_CHAR_LIMIT: 5
})

it('truncates the prompt and completion', async () => {
stubCall({
...openAiBaseCompletionInfo,
response: {
model: 'gpt-3.5-turbo-instruct',
choices: [{
text: 'The answer is 4',
index: 0,
logprobs: null,
finish_reason: 'length'
}],
usage: { prompt_tokens: 8, completion_tokens: 12, otal_tokens: 20 }
}
})

const llm = new langchainOpenai.OpenAI({ model: 'gpt-3.5-turbo-instruct' })
const checkTraces = agent
.use(traces => {
expect(traces[0].length).to.equal(1)
const span = traces[0][0]

expect(span.meta).to.have.property('langchain.request.prompts.0.content', 'what ...')
expect(span.meta).to.have.property('langchain.response.completions.0.text', 'The a...')
})

const result = await llm.generate(['what is 2 + 2?'])

expect(result.generations[0][0].text).to.equal('The answer is 4')

await checkTraces
})
})
})

describe('llm', () => {
it('does not tag output on error', async () => {
nock('https://api.openai.com').post('/v1/completions').reply(403)
Expand Down
7 changes: 7 additions & 0 deletions packages/dd-trace/src/appsec/sdk/track_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const waf = require('../waf')
const { keepTrace } = require('../../priority_sampler')
const addresses = require('../addresses')
const { ASM } = require('../../standalone/product')
const { incrementSdkEventMetric } = require('../telemetry')

function trackUserLoginSuccessEvent (tracer, user, metadata) {
// TODO: better user check here and in _setUser() ?
Expand All @@ -15,6 +16,8 @@ function trackUserLoginSuccessEvent (tracer, user, metadata) {
return
}

incrementSdkEventMetric('login_success')

const rootSpan = getRootSpan(tracer)
if (!rootSpan) {
log.warn('[ASM] Root span not available in trackUserLoginSuccessEvent')
Expand Down Expand Up @@ -48,6 +51,8 @@ function trackUserLoginFailureEvent (tracer, userId, exists, metadata) {
trackEvent('users.login.failure', fields, 'trackUserLoginFailureEvent', getRootSpan(tracer))

runWaf('users.login.failure', { login: userId })

incrementSdkEventMetric('login_failure')
}

function trackCustomEvent (tracer, eventName, metadata) {
Expand All @@ -57,6 +62,8 @@ function trackCustomEvent (tracer, eventName, metadata) {
}

trackEvent(eventName, metadata, 'trackCustomEvent', getRootSpan(tracer))

incrementSdkEventMetric('custom')
}

function trackEvent (eventName, fields, sdkMethodName, rootSpan) {
Expand Down
9 changes: 8 additions & 1 deletion packages/dd-trace/src/appsec/telemetry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { DD_TELEMETRY_REQUEST_METRICS } = require('./common')
const { addRaspRequestMetrics, trackRaspMetrics } = require('./rasp')
const { incrementMissingUserId, incrementMissingUserLogin } = require('./user')
const { incrementMissingUserId, incrementMissingUserLogin, incrementSdkEvent } = require('./user')
const {
addWafRequestMetrics,
trackWafMetrics,
Expand Down Expand Up @@ -121,6 +121,12 @@ function incrementMissingUserIdMetric (framework, eventType) {
incrementMissingUserId(framework, eventType)
}

function incrementSdkEventMetric (framework, eventType) {
if (!enabled) return

incrementSdkEvent(framework, eventType)
}

function getRequestMetrics (req) {
if (req) {
const store = getStore(req)
Expand All @@ -141,6 +147,7 @@ module.exports = {
incrementWafRequestsMetric,
incrementMissingUserLoginMetric,
incrementMissingUserIdMetric,
incrementSdkEventMetric,

getRequestMetrics
}
10 changes: 9 additions & 1 deletion packages/dd-trace/src/appsec/telemetry/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ function incrementMissingUserId (framework, eventType) {
}).inc()
}

function incrementSdkEvent (eventType) {
appsecMetrics.count('sdk.event', {
event_type: eventType,
sdk_version: 'v1'
}).inc()
}

module.exports = {
incrementMissingUserLogin,
incrementMissingUserId
incrementMissingUserId,
incrementSdkEvent
}
Loading
Loading