diff --git a/library/otel_init.sh b/library/otel_init.sh index ec2f15f..4a4a9e3 100644 --- a/library/otel_init.sh +++ b/library/otel_init.sh @@ -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 diff --git a/library/otel_traces.sh b/library/otel_traces.sh index 237ddee..479ef31 100644 --- a/library/otel_traces.sh +++ b/library/otel_traces.sh @@ -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" @@ -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 diff --git a/library/otel_traces_detector_azure_pipelines.sh b/library/otel_traces_detector_azure_pipelines.sh index b4918b5..1dd0823 100644 --- a/library/otel_traces_detector_azure_pipelines.sh +++ b/library/otel_traces_detector_azure_pipelines.sh @@ -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}" diff --git a/library/otel_traces_detector_bitbucket_pipelines.sh b/library/otel_traces_detector_bitbucket_pipelines.sh index fb1eff0..b38e5b3 100644 --- a/library/otel_traces_detector_bitbucket_pipelines.sh +++ b/library/otel_traces_detector_bitbucket_pipelines.sh @@ -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}" diff --git a/library/otel_traces_detector_buildkite.sh b/library/otel_traces_detector_buildkite.sh index f552b21..5445b11 100644 --- a/library/otel_traces_detector_buildkite.sh +++ b/library/otel_traces_detector_buildkite.sh @@ -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}" diff --git a/library/otel_traces_detector_circle_ci.sh b/library/otel_traces_detector_circle_ci.sh index b8846b1..7ebf0b9 100644 --- a/library/otel_traces_detector_circle_ci.sh +++ b/library/otel_traces_detector_circle_ci.sh @@ -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}" diff --git a/library/otel_traces_detector_github_actions.sh b/library/otel_traces_detector_github_actions.sh index 757af10..8e88d22 100644 --- a/library/otel_traces_detector_github_actions.sh +++ b/library/otel_traces_detector_github_actions.sh @@ -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}" diff --git a/library/otel_traces_detector_gitlab_ci.sh b/library/otel_traces_detector_gitlab_ci.sh index ffec454..e83cc7f 100644 --- a/library/otel_traces_detector_gitlab_ci.sh +++ b/library/otel_traces_detector_gitlab_ci.sh @@ -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 diff --git a/library/otel_traces_detector_google_cloud_build.sh b/library/otel_traces_detector_google_cloud_build.sh index 4592a0b..db71bfd 100644 --- a/library/otel_traces_detector_google_cloud_build.sh +++ b/library/otel_traces_detector_google_cloud_build.sh @@ -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}" diff --git a/library/otel_traces_detector_harness.sh b/library/otel_traces_detector_harness.sh index 05064f0..b3b035d 100644 --- a/library/otel_traces_detector_harness.sh +++ b/library/otel_traces_detector_harness.sh @@ -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 diff --git a/library/otel_traces_detector_jenkins.sh b/library/otel_traces_detector_jenkins.sh index ddc7bf0..1efc47b 100644 --- a/library/otel_traces_detector_jenkins.sh +++ b/library/otel_traces_detector_jenkins.sh @@ -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}" diff --git a/library/otel_traces_detector_jenkins_x.sh b/library/otel_traces_detector_jenkins_x.sh index cf467da..f8083cc 100644 --- a/library/otel_traces_detector_jenkins_x.sh +++ b/library/otel_traces_detector_jenkins_x.sh @@ -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}" diff --git a/library/otel_traces_detector_travis_ci.sh b/library/otel_traces_detector_travis_ci.sh index b577f10..d89fbc6 100644 --- a/library/otel_traces_detector_travis_ci.sh +++ b/library/otel_traces_detector_travis_ci.sh @@ -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}" diff --git a/library/otel_ver.sh b/library/otel_ver.sh index 09f4c5f..0c022a9 100644 --- a/library/otel_ver.sh +++ b/library/otel_ver.sh @@ -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