Skip to content

Commit

Permalink
Updating CI/CD Detectors and more (#55)
Browse files Browse the repository at this point in the history
* Remove -workflow from GHA detectors

* CI detectors to ignore OTEL_SERVICE_NAME if defined

* Update detector conditionals

* Bump version
  • Loading branch information
krzko committed Oct 13, 2022
1 parent bccdde4 commit 99073b8
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion library/otel_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if [ -z "${OTEL_EXPORTER_OTEL_ENDPOINT-}" ]; then
fi

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

if [ -z "${service_version-}" ]; then
Expand Down
12 changes: 9 additions & 3 deletions library/otel_traces.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ otel_trace_start_parent_span() {
otel_trace_add_resource_scopespans_span "$name" \
"$OTEL_TRACE_ID" \
"$span_id" \
"" \
'' \
"$start_time_unix_nano" \
"$end_time_unix_nano" \
"$exit_code"

otel_trace_add_resourcespan_scopespans_spans_attrib_string "command" "$*"
otel_trace_add_resourcespan_scopespans_spans_attrib_string "errorlevel" "${exit_code}"
otel_trace_add_resourcespan_scopespans_spans_attrib_string "function" "${FUNCNAME[1]}()"

otel_trace_add_resourcespan_scopespans_spans_attrib_string "code.url" "${PWD}/${0##*/}#L${BASH_LINENO[0]}"

if [ -z "${FUNCNAME-}" ]; then
otel_trace_add_resourcespan_scopespans_spans_attrib_string "function" "${FUNCNAME[1]}()"
fi

if [ -z "${OTEL_LOG_LEVEL-}" ]; then
log_debug "curling ${OTEL_EXPORTER_OTEL_ENDPOINT}/v1/traces"
net_client_post "${otel_trace_resource_spans}" "${OTEL_EXPORTER_OTEL_ENDPOINT}/v1/traces"
Expand Down Expand Up @@ -155,6 +157,10 @@ otel_trace_start_child_span() {
otel_trace_add_resourcespan_scopespans_spans_attrib_string "errorlevel" "${exit_code}"
otel_trace_add_resourcespan_scopespans_spans_attrib_string "function" "${FUNCNAME[1]}()"

if [ -z "${FUNCNAME-}" ]; then
otel_trace_add_resourcespan_scopespans_spans_attrib_string "function" "${FUNCNAME[1]}()"
fi

otel_trace_add_resourcespan_scopespans_spans_attrib_string "code.url" "${PWD}/${0##*/}#L${BASH_LINENO[0]}"

if [ -z "${OTEL_LOG_LEVEL-}" ]; then
Expand Down
4 changes: 3 additions & 1 deletion library/otel_traces_detector_azure_pipelines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

log_info "Detected, Azure Pipelines..."

return_spaces_to_dashes "${BUILD_REPOSITORY_URI}-pipelines" "OTEL_SERVICE_NAME"
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
return_spaces_to_dashes "${BUILD_REPOSITORY_URI}" "OTEL_SERVICE_NAME"
fi

detector_resource_attributes=(
"azure.branch:${BUILD_SOURCEBRANCHNAME}"
Expand Down
4 changes: 3 additions & 1 deletion library/otel_traces_detector_bitbucket_pipelines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

log_info "Detected, Bitbucket Pipelines..."

return_spaces_to_dashes "${BITBUCKET_REPO_FULL_NAME}-pipelines" "OTEL_SERVICE_NAME"
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
return_spaces_to_dashes "${BITBUCKET_REPO_FULL_NAME}" "OTEL_SERVICE_NAME"
fi

detector_resource_attributes=(
"buildkite.branch:${BITBUCKET_BRANCH}"
Expand Down
4 changes: 3 additions & 1 deletion library/otel_traces_detector_buildkite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

log_info "Detected, Buildkite..."

return_spaces_to_dashes "${BUILDKITE_REPO}-pipelines" "OTEL_SERVICE_NAME"
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
return_spaces_to_dashes "${BUILDKITE_REPO}" "OTEL_SERVICE_NAME"
fi

detector_resource_attributes=(
"buildkite.branch:${BUILDKITE_BRANCH}"
Expand Down
4 changes: 3 additions & 1 deletion library/otel_traces_detector_circle_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

log_info "Detected, Circle CI..."

return_spaces_to_dashes "${CIRCLE_REPOSITORY_URL}-pipelines" "OTEL_SERVICE_NAME"
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
return_spaces_to_dashes "${CIRCLE_REPOSITORY_URL}" "OTEL_SERVICE_NAME"
fi

detector_resource_attributes=(
"circle.ci.branch:${CIRCLE_BRANCH}"
Expand Down
4 changes: 3 additions & 1 deletion library/otel_traces_detector_github_actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

log_info "Detected, GitHub Actions..."

return_spaces_to_dashes "${GITHUB_REPOSITORY}-workflows" "OTEL_SERVICE_NAME"
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
return_spaces_to_dashes "${GITHUB_REPOSITORY}" "OTEL_SERVICE_NAME"
fi

detector_resource_attributes=(
"github.action:${GITHUB_ACTION}"
Expand Down
4 changes: 2 additions & 2 deletions library/otel_traces_detector_gitlab_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

log_info "Detected, Gitlab CI..."

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

if [ -n "${detector_resource_attributes-}" ]; then
Expand Down
4 changes: 3 additions & 1 deletion library/otel_traces_detector_google_cloud_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

log_info "Detected, Google Cloud Build..."

return_spaces_to_dashes "${REPO_NAME}-workflows" "OTEL_SERVICE_NAME"
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
return_spaces_to_dashes "${REPO_NAME}" "OTEL_SERVICE_NAME"
fi

detector_resource_attributes=(
"cloud.build.branch:${BRANCH_NAME}"
Expand Down
4 changes: 3 additions & 1 deletion library/otel_traces_detector_harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

log_info "Detected, Harness..."

return_spaces_to_dashes "${REPO_NAME}-pipelines" "OTEL_SERVICE_NAME"
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
return_spaces_to_dashes "${REPO_NAME}" "OTEL_SERVICE_NAME"
fi

declare -t detector_resource_attributes

Expand Down
4 changes: 3 additions & 1 deletion library/otel_traces_detector_jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

log_info "Detected, Jenkins..."

return_spaces_to_dashes "${JOB_NAME}-pipelines" "OTEL_SERVICE_NAME"
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
return_spaces_to_dashes "${JOB_NAME}" "OTEL_SERVICE_NAME"
fi

detector_resource_attributes=(
"jenkins.branch.name:${BRANCH_NAME}"
Expand Down
4 changes: 3 additions & 1 deletion library/otel_traces_detector_jenkins_x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

log_info "Detected, Jenkins X..."

return_spaces_to_dashes "${REPO_NAME}-pipelines" "OTEL_SERVICE_NAME"
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
return_spaces_to_dashes "${REPO_NAME}" "OTEL_SERVICE_NAME"
fi

detector_resource_attributes=(
"jenkins.branch:${BRANCH_NAME}"
Expand Down
4 changes: 3 additions & 1 deletion library/otel_traces_detector_travis_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

log_info "Detected, Travis CI..."

return_spaces_to_dashes "${TRAVIS_REPO_SLUG}-pipelines" "OTEL_SERVICE_NAME"
if [ "$OTEL_SERVICE_NAME" == "unknown_service" ]; then
return_spaces_to_dashes "${TRAVIS_REPO_SLUG}" "OTEL_SERVICE_NAME"
fi

detector_resource_attributes=(
"travis.branch:${TRAVIS_BRANCH}"
Expand Down
2 changes: 1 addition & 1 deletion library/otel_ver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

export telemetry_sdk_ver="0.0.8"
export telemetry_sdk_ver="0.0.9"

#######################################
# Returns a version of the SDK
Expand Down

0 comments on commit 99073b8

Please sign in to comment.