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
4 changes: 2 additions & 2 deletions packages/dd-trace/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const {
getIsAzureFunction,
enableGCPPubSubPushSubscription,
} = require('../serverless')
const { ORIGIN_KEY } = require('../constants')
const { ORIGIN_KEY, DATADOG_MINI_AGENT_PATH } = require('../constants')
const { appendRules } = require('../payload-tagging/config')
const { getGitMetadataFromGitProperties, removeUserSensitiveInfo, getRemoteOriginURL, resolveGitHeadSHA } =
require('./git_properties')
Expand Down Expand Up @@ -620,7 +620,7 @@ class Config {
unprocessedTarget['experimental.aiguard.timeout'] = DD_AI_GUARD_TIMEOUT
setBoolean(target, 'experimental.enableGetRumData', DD_TRACE_EXPERIMENTAL_GET_RUM_DATA_ENABLED)
setString(target, 'experimental.exporter', DD_TRACE_EXPERIMENTAL_EXPORTER)
if (AWS_LAMBDA_FUNCTION_NAME) {
if (AWS_LAMBDA_FUNCTION_NAME && !fs.existsSync(DATADOG_MINI_AGENT_PATH)) {
target.flushInterval = 0
} else if (DD_TRACE_FLUSH_INTERVAL) {
target.flushInterval = maybeInt(DD_TRACE_FLUSH_INTERVAL)
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
SPAN_SAMPLING_RULE_RATE: '_dd.span_sampling.rule_rate',
SPAN_SAMPLING_MAX_PER_SECOND: '_dd.span_sampling.max_per_second',
DATADOG_LAMBDA_EXTENSION_PATH: '/opt/extensions/datadog-agent',
DATADOG_MINI_AGENT_PATH: '/tmp/datadog/mini_agent_ready',
DECISION_MAKER_KEY: '_dd.p.dm',
SAMPLING_KNUTH_RATE: '_dd.p.ksr',
PROCESS_ID: 'process_id',
Expand Down
7 changes: 5 additions & 2 deletions packages/dd-trace/src/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ module.exports = function getExporter (name) {
return require('./ci-visibility/exporters/test-worker')
default: {
const inAWSLambda = getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME') !== undefined
const usingLambdaExtension = inAWSLambda && fs.existsSync(constants.DATADOG_LAMBDA_EXTENSION_PATH)
return require(inAWSLambda && !usingLambdaExtension ? './exporters/log' : './exporters/agent')
const usingAgent = inAWSLambda && (
fs.existsSync(constants.DATADOG_LAMBDA_EXTENSION_PATH) ||
fs.existsSync(constants.DATADOG_MINI_AGENT_PATH)
)
return require(inAWSLambda && !usingAgent ? './exporters/log' : './exporters/agent')
}
}
}
23 changes: 23 additions & 0 deletions packages/dd-trace/test/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2330,6 +2330,29 @@ describe('Config', () => {
assert.strictEqual(config.remoteConfig.enabled, false)
})

describe('flushInterval in Lambda', () => {
afterEach(() => {
existsSyncReturn = undefined
})

it('should set flushInterval to 0 in standard Lambda environment', () => {
process.env.AWS_LAMBDA_FUNCTION_NAME = 'my-great-lambda-function'

const config = getConfig()

assert.strictEqual(config.flushInterval, 0)
})

it('should not set flushInterval to 0 in Lambda environment with mini agent', () => {
process.env.AWS_LAMBDA_FUNCTION_NAME = 'my-great-lambda-function'
existsSyncReturn = true

const config = getConfig()

assert.strictEqual(config.flushInterval, 2000)
})
})

it('should not set DD_REMOTE_CONFIGURATION_ENABLED if FUNCTION_NAME and GCP_PROJECT are present', () => {
process.env.FUNCTION_NAME = 'function_name'
process.env.GCP_PROJECT = 'project_name'
Expand Down
12 changes: 12 additions & 0 deletions packages/dd-trace/test/exporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const sinon = require('sinon')
require('./setup/core')
const AgentExporter = require('../src/exporters/agent')
const LogExporter = require('../src/exporters/log')
const { DATADOG_MINI_AGENT_PATH } = require('../src/constants')

describe('exporter', () => {
let env
Expand Down Expand Up @@ -47,6 +48,17 @@ describe('exporter', () => {
stub.restore()
})

it('should create an AgentExporter when in Lambda environment with mini agent', () => {
process.env.AWS_LAMBDA_FUNCTION_NAME = 'my-func'
const stub = sinon.stub(fs, 'existsSync')
stub.withArgs(DATADOG_MINI_AGENT_PATH).returns(true)

const Exporter = require('../src/exporter')()

assert.strictEqual(Exporter, AgentExporter)
stub.restore()
})

it('should allow configuring the exporter', () => {
const Exporter = require('../src/exporter')('log')

Expand Down
Loading