Skip to content
Merged
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
29 changes: 24 additions & 5 deletions scripts/serverless_init_dotnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,35 @@ if [ -f "/etc/alpine-release" ]; then
exit 1
fi

# Make sure curl is installed
apt-get update && apt-get install -y curl
# Make sure curl and jq are installed
apt-get update && apt-get install -y curl jq

ghcurl() {
if [ -n "$GITHUB_TOKEN" ]; then
echo "Github token provided" >&2
curl -sSL -w '{"status_code": %{http_code}}' -H "Authorization: Bearer $GITHUB_TOKEN" "$@" | jq -sre add
else
echo "Github token not provided" >&2
curl -sSL -w '{"status_code": %{http_code}}' "$@" | jq -sre add
fi
}

# Get latest released version of dd-trace-dotnet
TRACER_VERSION=$(curl -s https://api.github.com/repos/DataDog/dd-trace-dotnet/releases/latest | grep 'tag_name' | cut -d '"' -f 4)
TRACER_VERSION=${TRACER_VERSION#v} # remove the 'v' prefix
response=$(ghcurl https://api.github.com/repos/DataDog/dd-trace-dotnet/releases/latest)
sanitized_response=$(echo "$response" | tr -d '\000-\037') # remove control characters from json response
echo "Status code of version request: $(echo "$sanitized_response" | jq '.status_code')"
TRACER_VERSION=$(echo "$sanitized_response" | jq -r '.tag_name // empty' | sed 's/^v//')

if [ -z "$TRACER_VERSION" ]; then
echo "Error: Could not determine the tracer version. Exiting." >&2
exit 1
fi

# Download the tracer to the dd_tracer folder
echo Downloading version "${TRACER_VERSION}" of the .NET tracer into /tmp/datadog-dotnet-apm.tar.gz
curl -L "https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm-${TRACER_VERSION}.tar.gz" -o /tmp/datadog-dotnet-apm.tar.gz
response=$(ghcurl "https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm-${TRACER_VERSION}.tar.gz" \
-o /tmp/datadog-dotnet-apm.tar.gz)
echo "Status code of download request: $(echo "$response" | jq '.status_code')"

# Unarchive the tracer and remove the tmp
mkdir -p /dd_tracer/dotnet
Expand Down
Loading