Skip to content

Commit

Permalink
try again
Browse files Browse the repository at this point in the history
  • Loading branch information
khanayan123 committed Sep 26, 2024
1 parent 2a44258 commit fe57dfe
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
71 changes: 61 additions & 10 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require('fs')
const os = require('os')
const uuid = require('crypto-randomuuid') // we need to keep the old uuid dep because of cypress
const URL = require('url').URL
const { URL } = require('url')
const log = require('./log')
const pkg = require('./pkg')
const coalesce = require('koalas')
Expand All @@ -18,6 +18,7 @@ const { updateConfig } = require('./telemetry')
const telemetryMetrics = require('./telemetry/metrics')
const { getIsGCPFunction, getIsAzureFunction } = require('./serverless')
const { ORIGIN_KEY } = require('./constants')
const { appendRules } = require('./payload-tagging/config')

const tracerMetrics = telemetryMetrics.manager.namespace('tracers')

Expand Down Expand Up @@ -173,6 +174,21 @@ function validateNamingVersion (versionString) {
return versionString
}

/**
* Given a string of comma-separated paths, return the array of paths.
* If a blank path is provided a null is returned to signal that the feature is disabled.
* An empty array means the feature is enabled but that no rules need to be applied.
*
* @param {string} input
* @returns {[string]|null}
*/
function splitJSONPathRules (input) {
if (!input) return null
if (Array.isArray(input)) return input
if (input === 'all') return []
return input.split(',')
}

// Shallow clone with property name remapping
function remapify (input, mappings) {
if (!input) return
Expand Down Expand Up @@ -281,6 +297,26 @@ class Config {
null
)

const DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING = splitJSONPathRules(
coalesce(
process.env.DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING,
options.cloudPayloadTagging?.request,
''
))

const DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING = splitJSONPathRules(
coalesce(
process.env.DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING,
options.cloudPayloadTagging?.response,
''
))

const DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH = coalesce(
process.env.DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH,
options.cloudPayloadTagging?.maxDepth,
10
)

// TODO: refactor
this.apiKey = DD_API_KEY

Expand All @@ -291,6 +327,15 @@ class Config {
type: DD_INSTRUMENTATION_INSTALL_TYPE
}

this.cloudPayloadTagging = {
requestsEnabled: !!DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING,
responsesEnabled: !!DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING,
maxDepth: DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH,
rules: appendRules(
DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING, DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING
)
}

this._applyDefaults()
this._applyEnvironment()
this._applyOptions(options)
Expand Down Expand Up @@ -423,6 +468,7 @@ class Config {
this._setValue(defaults, 'dogstatsd.hostname', '127.0.0.1')
this._setValue(defaults, 'dogstatsd.port', '8125')
this._setValue(defaults, 'dsmEnabled', false)
this._setValue(defaults, 'dynamicInstrumentationEnabled', false)
this._setValue(defaults, 'env', undefined)
this._setValue(defaults, 'experimental.enableGetRumData', false)
this._setValue(defaults, 'experimental.exporter', undefined)
Expand Down Expand Up @@ -451,6 +497,7 @@ class Config {
this._setValue(defaults, 'isGitUploadEnabled', false)
this._setValue(defaults, 'isIntelligentTestRunnerEnabled', false)
this._setValue(defaults, 'isManualApiEnabled', false)
this._setValue(defaults, 'ciVisibilityTestSessionName', '')
this._setValue(defaults, 'logInjection', false)
this._setValue(defaults, 'lookup', undefined)
this._setValue(defaults, 'memcachedCommandEnabled', false)
Expand Down Expand Up @@ -528,6 +575,7 @@ class Config {
DD_DBM_PROPAGATION_MODE,
DD_DOGSTATSD_HOSTNAME,
DD_DOGSTATSD_PORT,
DD_DYNAMIC_INSTRUMENTATION_ENABLED,
DD_ENV,
DD_EXPERIMENTAL_API_SECURITY_ENABLED,
DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED,
Expand Down Expand Up @@ -657,6 +705,7 @@ class Config {
this._setString(env, 'dogstatsd.hostname', DD_DOGSTATSD_HOSTNAME)
this._setString(env, 'dogstatsd.port', DD_DOGSTATSD_PORT)
this._setBoolean(env, 'dsmEnabled', DD_DATA_STREAMS_ENABLED)
this._setBoolean(env, 'dynamicInstrumentationEnabled', DD_DYNAMIC_INSTRUMENTATION_ENABLED)
this._setString(env, 'env', DD_ENV || tags.env)
this._setBoolean(env, 'experimental.enableGetRumData', DD_TRACE_EXPERIMENTAL_GET_RUM_DATA_ENABLED)
this._setString(env, 'experimental.exporter', DD_TRACE_EXPERIMENTAL_EXPORTER)
Expand Down Expand Up @@ -824,11 +873,11 @@ class Config {
this._setString(opts, 'dogstatsd.port', options.dogstatsd.port)
}
this._setBoolean(opts, 'dsmEnabled', options.dsmEnabled)
this._setBoolean(opts, 'dynamicInstrumentationEnabled', options.experimental?.dynamicInstrumentationEnabled)
this._setString(opts, 'env', options.env || tags.env)
this._setBoolean(opts, 'experimental.enableGetRumData',
options.experimental && options.experimental.enableGetRumData)
this._setString(opts, 'experimental.exporter', options.experimental && options.experimental.exporter)
this._setBoolean(opts, 'experimental.runtimeId', options.experimental && options.experimental.runtimeId)
this._setBoolean(opts, 'experimental.enableGetRumData', options.experimental?.enableGetRumData)
this._setString(opts, 'experimental.exporter', options.experimental?.exporter)
this._setBoolean(opts, 'experimental.runtimeId', options.experimental?.runtimeId)
this._setValue(opts, 'flushInterval', maybeInt(options.flushInterval))
this._optsUnprocessed.flushInterval = options.flushInterval
this._setValue(opts, 'flushMinSpans', maybeInt(options.flushMinSpans))
Expand Down Expand Up @@ -954,10 +1003,10 @@ class Config {
}

_isCiVisibilityManualApiEnabled () {
return isTrue(coalesce(
return coalesce(
process.env.DD_CIVISIBILITY_MANUAL_API_ENABLED,
false
))
true
)
}

_isTraceStatsComputationEnabled () {
Expand Down Expand Up @@ -985,7 +1034,8 @@ class Config {
DD_CIVISIBILITY_AGENTLESS_URL,
DD_CIVISIBILITY_EARLY_FLAKE_DETECTION_ENABLED,
DD_CIVISIBILITY_FLAKY_RETRY_ENABLED,
DD_CIVISIBILITY_FLAKY_RETRY_COUNT
DD_CIVISIBILITY_FLAKY_RETRY_COUNT,
DD_TEST_SESSION_NAME
} = process.env

if (DD_CIVISIBILITY_AGENTLESS_URL) {
Expand All @@ -1000,7 +1050,8 @@ class Config {
coalesce(DD_CIVISIBILITY_FLAKY_RETRY_ENABLED, true))
this._setValue(calc, 'flakyTestRetriesCount', coalesce(maybeInt(DD_CIVISIBILITY_FLAKY_RETRY_COUNT), 5))
this._setBoolean(calc, 'isIntelligentTestRunnerEnabled', isTrue(this._isCiVisibilityItrEnabled()))
this._setBoolean(calc, 'isManualApiEnabled', this._isCiVisibilityManualApiEnabled())
this._setBoolean(calc, 'isManualApiEnabled', !isFalse(this._isCiVisibilityManualApiEnabled()))
this._setString(calc, 'ciVisibilityTestSessionName', DD_TEST_SESSION_NAME)
}
this._setString(calc, 'dogstatsd.hostname', this._getHostname())
this._setBoolean(calc, 'isGitUploadEnabled',
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/telemetry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ function start (aConfig, thePluginManager) {
return
}
config = aConfig
console.log(44, config)

Check failure on line 246 in packages/dd-trace/src/telemetry/index.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
pluginManager = thePluginManager
application = createAppObject(config)
host = createHostObject()
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/telemetry/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('telemetry', () => {
traceAgent.close()
})

it('should send app-started', () => {
it.only('should send app-started', () => {

Check warning on line 93 in packages/dd-trace/test/telemetry/index.spec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected exclusive mocha test
return testSeq(1, 'app-started', payload => {
expect(payload).to.have.property('products').that.deep.equal({
appsec: { enabled: true },
Expand Down

0 comments on commit fe57dfe

Please sign in to comment.