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

upgrade(tracer): Support libdatadog's library_config module #5126

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
20 changes: 20 additions & 0 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const telemetryMetrics = require('./telemetry/metrics')
const { getIsGCPFunction, getIsAzureFunction } = require('./serverless')
const { ORIGIN_KEY, GRPC_CLIENT_ERROR_STATUSES, GRPC_SERVER_ERROR_STATUSES } = require('./constants')
const { appendRules } = require('./payload-tagging/config')
const libdatadog = require('@datadog/libdatadog')

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

Expand Down Expand Up @@ -236,6 +237,25 @@ function reformatSpanSamplingRules (rules) {

class Config {
constructor (options = {}) {
// Read & apply the YAML configuration
const libconfig = libdatadog.maybeLoadWASM('library_config')
if (libconfig != null) {
const yamlConfigPath = '/etc/datadog-agent/managed/datadog-apm-libraries/stable/libraries_config.yaml'
if (fs.existsSync(yamlConfigPath)) {
const rawConfig = fs.readFileSync(yamlConfigPath, 'utf8')
const configurator = new libconfig.JsConfigurator()
configurator.set_envp(Object.entries(process.env).map(([key, value]) => `${key}=${value}`))
configurator.set_args(process.argv)
configurator.get_configuration(rawConfig.toString()).forEach((value, key, map) => {
// TODO: this is ugly and only for demo purposes, we should use
// the config object we get and override parameters that way
process.env[key] = value
})
}
} else {
log.info('libconfig not found, skipping file-based configuration')
}

options = {
...options,
appsec: options.appsec != null ? options.appsec : options.experimental?.appsec,
Expand Down
Loading