Skip to content

Commit

Permalink
Enable Serverless Mini Agent for Azure Functions on All Plans (#4304)
Browse files Browse the repository at this point in the history
Run Serverless Mini Agent for Azure Functions on all consumption plans.
https://datadoghq.atlassian.net/browse/SVLS-4805
  • Loading branch information
duncanpharvey authored May 16, 2024
1 parent 59cb67b commit 12d02ee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 32 deletions.
10 changes: 5 additions & 5 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { GIT_REPOSITORY_URL, GIT_COMMIT_SHA } = require('./plugins/util/tags')
const { getGitMetadataFromGitProperties, removeUserSensitiveInfo } = require('./git_properties')
const { updateConfig } = require('./telemetry')
const telemetryMetrics = require('./telemetry/metrics')
const { getIsGCPFunction, getIsAzureFunctionConsumptionPlan } = require('./serverless')
const { getIsGCPFunction, getIsAzureFunction } = require('./serverless')
const { ORIGIN_KEY } = require('./constants')

const tracerMetrics = telemetryMetrics.manager.namespace('tracers')
Expand Down Expand Up @@ -339,7 +339,7 @@ class Config {

// Requires an accompanying DD_APM_OBFUSCATION_MEMCACHED_KEEP_COMMAND=true in the agent
this.memcachedCommandEnabled = isTrue(DD_TRACE_MEMCACHED_COMMAND_ENABLED)
this.isAzureFunctionConsumptionPlan = getIsAzureFunctionConsumptionPlan()
this.isAzureFunction = getIsAzureFunction()
this.spanLeakDebug = Number(DD_TRACE_SPAN_LEAK_DEBUG)
this.installSignature = {
id: DD_INSTRUMENTATION_INSTALL_ID,
Expand Down Expand Up @@ -417,8 +417,8 @@ class Config {
_isInServerlessEnvironment () {
const inAWSLambda = process.env.AWS_LAMBDA_FUNCTION_NAME !== undefined
const isGCPFunction = getIsGCPFunction()
const isAzureFunctionConsumptionPlan = getIsAzureFunctionConsumptionPlan()
return inAWSLambda || isGCPFunction || isAzureFunctionConsumptionPlan
const isAzureFunction = getIsAzureFunction()
return inAWSLambda || isGCPFunction || isAzureFunction
}

// for _merge to work, every config value must have a default value
Expand Down Expand Up @@ -877,7 +877,7 @@ class Config {
return coalesce(
this.options.stats,
process.env.DD_TRACE_STATS_COMPUTATION_ENABLED,
getIsGCPFunction() || getIsAzureFunctionConsumptionPlan()
getIsGCPFunction() || getIsAzureFunction()
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Tracer extends NoopProxy {
})
}

if (config.isGCPFunction || config.isAzureFunctionConsumptionPlan) {
if (config.isGCPFunction || config.isAzureFunction) {
require('./serverless').maybeStartServerlessMiniAgent(config)
}

Expand Down
8 changes: 3 additions & 5 deletions packages/dd-trace/src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ function getIsGCPFunction () {
return isDeprecatedGCPFunction || isNewerGCPFunction
}

function getIsAzureFunctionConsumptionPlan () {
function getIsAzureFunction () {
const isAzureFunction =
process.env.FUNCTIONS_EXTENSION_VERSION !== undefined && process.env.FUNCTIONS_WORKER_RUNTIME !== undefined
const azureWebsiteSKU = process.env.WEBSITE_SKU
const isConsumptionPlan = azureWebsiteSKU === undefined || azureWebsiteSKU === 'Dynamic'

return isAzureFunction && isConsumptionPlan
return isAzureFunction
}

module.exports = {
maybeStartServerlessMiniAgent,
getIsGCPFunction,
getIsAzureFunctionConsumptionPlan,
getIsAzureFunction,
getRustBinaryPath
}
22 changes: 1 addition & 21 deletions packages/dd-trace/test/serverless.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Serverless', () => {
expect(spawnStub).to.have.been.calledOnce
})

it('should spawn mini agent when FUNCTIONS_WORKER_RUNTIME, FUNCTIONS_EXTENSION_VERSION env vars are defined', () => {
it('should spawn mini agent when Azure env vars are defined', () => {
process.env.FUNCTIONS_WORKER_RUNTIME = 'node'
process.env.FUNCTIONS_EXTENSION_VERSION = '4'

Expand All @@ -63,26 +63,6 @@ describe('Serverless', () => {
expect(spawnStub).to.have.been.calledOnce
})

it('should spawn mini agent when Azure Function env vars are defined and SKU is dynamic', () => {
process.env.FUNCTIONS_WORKER_RUNTIME = 'node'
process.env.FUNCTIONS_EXTENSION_VERSION = '4'
process.env.WEBSITE_SKU = 'Dynamic'

proxy.init()

expect(spawnStub).to.have.been.calledOnce
})

it('should NOT spawn mini agent when Azure Function env vars are defined but SKU is NOT dynamic', () => {
process.env.FUNCTIONS_WORKER_RUNTIME = 'node'
process.env.FUNCTIONS_EXTENSION_VERSION = '4'
process.env.WEBSITE_SKU = 'Basic'

proxy.init()

expect(spawnStub).to.not.have.been.called
})

it('should log error if mini agent binary path is invalid', () => {
process.env.K_SERVICE = 'test_function'
process.env.FUNCTION_TARGET = 'function_target'
Expand Down

0 comments on commit 12d02ee

Please sign in to comment.