From 0648856398aa412c69f2a9c58d24a8d6c477a3e2 Mon Sep 17 00:00:00 2001 From: NouemanKHAL Date: Mon, 20 Mar 2023 17:10:40 +0100 Subject: [PATCH] Add ability to wait for the trace agent startup before application start (#158) --- lib/run-datadog.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/run-datadog.sh b/lib/run-datadog.sh index b6e3a9b..2407914 100644 --- a/lib/run-datadog.sh +++ b/lib/run-datadog.sh @@ -233,5 +233,22 @@ main() { exec 9>&- fi fi + + # wait for the trace agent startup + if [ "${WAIT_DD_TRACE_AGENT}" = "true" ]; then + timeout=120 + while ! nc -z localhost 8126 && [ $timeout -ge 0 ]; do + echo "Waiting for the trace agent to start on 8126..." + sleep 1 + timeout=$((timeout - 1)) + done + if [ $timeout -ge 0 ]; then + echo "Trace agent is listening for traces" + else + echo "Timed out waiting for the trace agent" + fi + fi } main "$@" + +