Skip to content

Commit 99073b8

Browse files
authored
Updating CI/CD Detectors and more (#55)
* Remove -workflow from GHA detectors * CI detectors to ignore OTEL_SERVICE_NAME if defined * Update detector conditionals * Bump version
1 parent bccdde4 commit 99073b8

14 files changed

+43
-17
lines changed

library/otel_init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [ -z "${OTEL_EXPORTER_OTEL_ENDPOINT-}" ]; then
5252
fi
5353

5454
if [ -z "${OTEL_SERVICE_NAME-}" ]; then
55-
export OTEL_SERVICE_NAME="${0##*/}"
55+
export OTEL_SERVICE_NAME="unknown_service"
5656
fi
5757

5858
if [ -z "${service_version-}" ]; then

library/otel_traces.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,19 @@ otel_trace_start_parent_span() {
7171
otel_trace_add_resource_scopespans_span "$name" \
7272
"$OTEL_TRACE_ID" \
7373
"$span_id" \
74-
"" \
74+
'' \
7575
"$start_time_unix_nano" \
7676
"$end_time_unix_nano" \
7777
"$exit_code"
7878

7979
otel_trace_add_resourcespan_scopespans_spans_attrib_string "command" "$*"
8080
otel_trace_add_resourcespan_scopespans_spans_attrib_string "errorlevel" "${exit_code}"
81-
otel_trace_add_resourcespan_scopespans_spans_attrib_string "function" "${FUNCNAME[1]}()"
82-
8381
otel_trace_add_resourcespan_scopespans_spans_attrib_string "code.url" "${PWD}/${0##*/}#L${BASH_LINENO[0]}"
8482

83+
if [ -z "${FUNCNAME-}" ]; then
84+
otel_trace_add_resourcespan_scopespans_spans_attrib_string "function" "${FUNCNAME[1]}()"
85+
fi
86+
8587
if [ -z "${OTEL_LOG_LEVEL-}" ]; then
8688
log_debug "curling ${OTEL_EXPORTER_OTEL_ENDPOINT}/v1/traces"
8789
net_client_post "${otel_trace_resource_spans}" "${OTEL_EXPORTER_OTEL_ENDPOINT}/v1/traces"
@@ -155,6 +157,10 @@ otel_trace_start_child_span() {
155157
otel_trace_add_resourcespan_scopespans_spans_attrib_string "errorlevel" "${exit_code}"
156158
otel_trace_add_resourcespan_scopespans_spans_attrib_string "function" "${FUNCNAME[1]}()"
157159

160+
if [ -z "${FUNCNAME-}" ]; then
161+
otel_trace_add_resourcespan_scopespans_spans_attrib_string "function" "${FUNCNAME[1]}()"
162+
fi
163+
158164
otel_trace_add_resourcespan_scopespans_spans_attrib_string "code.url" "${PWD}/${0##*/}#L${BASH_LINENO[0]}"
159165

160166
if [ -z "${OTEL_LOG_LEVEL-}" ]; then

library/otel_traces_detector_azure_pipelines.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
log_info "Detected, Azure Pipelines..."
2121

22-
return_spaces_to_dashes "${BUILD_REPOSITORY_URI}-pipelines" "OTEL_SERVICE_NAME"
22+
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
23+
return_spaces_to_dashes "${BUILD_REPOSITORY_URI}" "OTEL_SERVICE_NAME"
24+
fi
2325

2426
detector_resource_attributes=(
2527
"azure.branch:${BUILD_SOURCEBRANCHNAME}"

library/otel_traces_detector_bitbucket_pipelines.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
log_info "Detected, Bitbucket Pipelines..."
2121

22-
return_spaces_to_dashes "${BITBUCKET_REPO_FULL_NAME}-pipelines" "OTEL_SERVICE_NAME"
22+
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
23+
return_spaces_to_dashes "${BITBUCKET_REPO_FULL_NAME}" "OTEL_SERVICE_NAME"
24+
fi
2325

2426
detector_resource_attributes=(
2527
"buildkite.branch:${BITBUCKET_BRANCH}"

library/otel_traces_detector_buildkite.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
log_info "Detected, Buildkite..."
2121

22-
return_spaces_to_dashes "${BUILDKITE_REPO}-pipelines" "OTEL_SERVICE_NAME"
22+
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
23+
return_spaces_to_dashes "${BUILDKITE_REPO}" "OTEL_SERVICE_NAME"
24+
fi
2325

2426
detector_resource_attributes=(
2527
"buildkite.branch:${BUILDKITE_BRANCH}"

library/otel_traces_detector_circle_ci.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
log_info "Detected, Circle CI..."
2121

22-
return_spaces_to_dashes "${CIRCLE_REPOSITORY_URL}-pipelines" "OTEL_SERVICE_NAME"
22+
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
23+
return_spaces_to_dashes "${CIRCLE_REPOSITORY_URL}" "OTEL_SERVICE_NAME"
24+
fi
2325

2426
detector_resource_attributes=(
2527
"circle.ci.branch:${CIRCLE_BRANCH}"

library/otel_traces_detector_github_actions.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
log_info "Detected, GitHub Actions..."
2121

22-
return_spaces_to_dashes "${GITHUB_REPOSITORY}-workflows" "OTEL_SERVICE_NAME"
22+
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
23+
return_spaces_to_dashes "${GITHUB_REPOSITORY}" "OTEL_SERVICE_NAME"
24+
fi
2325

2426
detector_resource_attributes=(
2527
"github.action:${GITHUB_ACTION}"

library/otel_traces_detector_gitlab_ci.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
log_info "Detected, Gitlab CI..."
2121

22-
if [ -z "${OTEL_SERVICE_NAME-}" ]; then
23-
return_spaces_to_dashes "${CI_PROJECT_URL}-pipelines" "OTEL_SERVICE_NAME"
22+
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
23+
return_spaces_to_dashes "${CI_PROJECT_URL}" "OTEL_SERVICE_NAME"
2424
fi
2525

2626
if [ -n "${detector_resource_attributes-}" ]; then

library/otel_traces_detector_google_cloud_build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
log_info "Detected, Google Cloud Build..."
2121

22-
return_spaces_to_dashes "${REPO_NAME}-workflows" "OTEL_SERVICE_NAME"
22+
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
23+
return_spaces_to_dashes "${REPO_NAME}" "OTEL_SERVICE_NAME"
24+
fi
2325

2426
detector_resource_attributes=(
2527
"cloud.build.branch:${BRANCH_NAME}"

library/otel_traces_detector_harness.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
log_info "Detected, Harness..."
2121

22-
return_spaces_to_dashes "${REPO_NAME}-pipelines" "OTEL_SERVICE_NAME"
22+
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
23+
return_spaces_to_dashes "${REPO_NAME}" "OTEL_SERVICE_NAME"
24+
fi
2325

2426
declare -t detector_resource_attributes
2527

0 commit comments

Comments
 (0)