diff --git a/templates/installer/telemetry/send_telemetry.sh.epp b/templates/installer/telemetry/send_telemetry.sh.epp index 3c3c6c57..d628670e 100644 --- a/templates/installer/telemetry/send_telemetry.sh.epp +++ b/templates/installer/telemetry/send_telemetry.sh.epp @@ -11,26 +11,36 @@ TRACER_END_TIME=$(' \ --d '@/tmp/trace_payload.json' \ -"$TELEMETRY_URL" - -# Send log payload -curl -f -sSL --retry 5 -o /dev/null -X POST \ --H 'Content-Type: application/json' \ --H 'DD-API-KEY: <%= $api_key %>' \ --d '@/tmp/log_payload.json' \ -"$TELEMETRY_URL" +# Prepare placeholders and values +declare -A placeholders=( + ["TRACER_START_TIME_PLACEHOLDER"]=$TRACER_START_TIME + ["TRACER_END_TIME_PLACEHOLDER"]=$TRACER_END_TIME + ["DURATION_PLACEHOLDER"]=$DURATION + ["RUNTIME_ID_PLACEHOLDER"]=$RUNTIME_ID +) + +# Function to replace placeholders in a file +replace_placeholders() { + local file=$1 + for placeholder in "${!placeholders[@]}"; do + sed -i "s/$placeholder/${placeholders[$placeholder]}/g" "$file" + done +} + +# Prepare trace and log payloads +replace_placeholders /tmp/trace_payload.json +replace_placeholders /tmp/log_payload.json + +# Function to send payload +send_payload() { + local file=$1 + curl -f -sSL --retry 5 -o /dev/null -X POST \ + -H 'Content-Type: application/json' \ + -H 'DD-API-KEY: <%= $api_key %>' \ + -d "@$file" \ + "$TELEMETRY_URL" +} + +# Send trace and log payloads +send_payload /tmp/trace_payload.json +send_payload /tmp/log_payload.json