Skip to content

Commit

Permalink
fix: gitlab pipeline env vars are optional (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Oct 6, 2022
1 parent 5908e63 commit 5771f1b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions library/otel_traces_detector_gitlab_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,25 @@

log_info "Detected, Gitlab CI..."

return_spaces_to_dashes "${CI_PROJECT_URL}-pipelines" "OTEL_SERVICE_NAME"
if [ -z "${OTEL_SERVICE_NAME-}" }; then
return_spaces_to_dashes "${CI_PROJECT_URL}-pipelines" "OTEL_SERVICE_NAME"
fi

detector_resource_attributes=(
if [ -n "${detector_resource_attributes-}" ]; then
detector_resource_attributes=()
fi

detector_resource_attributes+=(
"gitlab.ci.branch:${CI_COMMIT_REF_NAME}"
"gitlab.ci.build.number:${CI_PIPELINE_ID}"
"gitlab.ci.build.url:${CI_PIPELINE_URL}"
"gitlab.ci.pull.request.branch:${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}"
"gitlab.ci.pull.request.number:${CI_MERGE_REQUEST_ID}"
"gitlab.ci.pull.request.repo:${CI_MERGE_REQUEST_SOURCE_PROJECT_PATH}"
"gitlab.ci.repo:${CI_PROJECT_URL}"
)

if [ -n "${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME-}" ]; then
detector_resource_attributes+=(
"gitlab.ci.pull.request.branch:${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}"
"gitlab.ci.pull.request.number:${CI_MERGE_REQUEST_ID}"
"gitlab.ci.pull.request.repo:${CI_MERGE_REQUEST_SOURCE_PROJECT_PATH}"
)
fi

0 comments on commit 5771f1b

Please sign in to comment.