Skip to content

Commit f6fcf98

Browse files
authored
Log JSON parse errors for DD_SPAN_SAMPLING_RULES_FILE (#5940)
Log error if `DD_SPAN_SAMPLING_RULES_FILE` is provided, but it doesn't contain valid JSON.
1 parent 264e1e1 commit f6fcf98

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/dd-trace/src/config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ function maybeFile (filepath) {
151151
}
152152
}
153153

154+
function maybeJsonFile (filepath) {
155+
const file = maybeFile(filepath)
156+
if (!file) return
157+
try {
158+
return JSON.parse(file)
159+
} catch (e) {
160+
log.error('Error parsing JSON file %s', filepath, e)
161+
}
162+
}
163+
154164
function safeJsonParse (input) {
155165
try {
156166
return JSON.parse(input)
@@ -944,7 +954,7 @@ class Config {
944954
otelSetRuntimeMetrics)
945955
this._setBoolean(env, 'runtimeMetricsRuntimeId', DD_RUNTIME_METRICS_RUNTIME_ID_ENABLED)
946956
this._setArray(env, 'sampler.spanSamplingRules', reformatSpanSamplingRules(coalesce(
947-
safeJsonParse(maybeFile(DD_SPAN_SAMPLING_RULES_FILE)),
957+
maybeJsonFile(DD_SPAN_SAMPLING_RULES_FILE),
948958
safeJsonParse(DD_SPAN_SAMPLING_RULES)
949959
)))
950960
this._setUnit(env, 'sampleRate', DD_TRACE_SAMPLE_RATE ||

0 commit comments

Comments
 (0)