Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 768db91

Browse files
committed
Add commit SHA to sandbox env for instrumentation
1 parent 2f03b25 commit 768db91

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

sandbox/shared/sandbox_config.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ function sbcfg_check_cfg_prop {
2525
return 0
2626
}
2727

28+
function sbcfg_setup_for_newrelic_instrumentation {
29+
local repoRoot="$1" sandboxTop="$2"
30+
grep -q licenseIngestKey $CSSVC_CFG_FILE || { echo "licenseIngestKey prop not in config file. No instrumenting today."; return; }
31+
[ -z "$CSSVC_NEWRELIC_LICENSE_KEY" ] && export CSSVC_NEWRELIC_LICENSE_KEY=$(get-json-property -j $CSSVC_CFG_FILE -p integrations.newrelic.cloud.licenseIngestKey)
32+
[ -d "$repoRoot/.git" ] && export NEW_RELIC_METADATA_COMMIT=$(cd "$repoRoot" && git rev-parse HEAD) && return
33+
# similar logic to server_utils/get_asset_data.js
34+
[ ! -f "$sandboxTop/package.json" ] && echo "cannot determine SHA for instrumentation. package.json not found" && return
35+
local assetName=$(get-json-property -j "$sandboxTop/package.json" -p name)
36+
local assetFile="$sandboxTop/$assetName.info"
37+
[ ! -f "$assetFile" ] && echo "cannot determine SHA for instrumentation. $assetFile not found" && return
38+
local primaryRepo=$(get-json-property -j "$sandboxTop/$assetName.info" -p primaryRepo)
39+
export NEW_RELIC_METADATA_COMMIT=$(get-json-property -j "$sandboxTop/$assetName.info" -p repoCommitId.$primaryRepo)
40+
}
41+
2842
function sbcfg_initialize {
2943
local sbPrefix=$1
3044

@@ -40,6 +54,7 @@ function sbcfg_initialize {
4054
local sbData=$(sbcfg_get_var ${sbPrefix}_DATA)
4155
local sbPids=$(sbcfg_get_var ${sbPrefix}_PIDS)
4256
local sbCfgFile=$(sbcfg_get_var ${sbPrefix}_CFG_FILE)
57+
local sbRepoRoot=$(sbcfg_get_var ${sbPrefix}_REPO_ROOT)
4358

4459
# ----- SANDBOX OPTIONS (for single-service sandboxes only)
4560
[ -z "$CSBE_TOP" ] && { sandutil_load_options $sbRoot || { echo "failed to load options for $sbRoot" >&2 && return 1; } }
@@ -99,8 +114,7 @@ function sbcfg_initialize {
99114
fi
100115

101116
# For instrumenting backend services
102-
[ -z "$CSSVC_NEWRELIC_LICENSE_KEY" ] && export CSSVC_NEWRELIC_LICENSE_KEY=$(get-json-property -j $CSSVC_CFG_FILE -p integrations.newrelic.cloud.licenseIngestKey)
103-
117+
[ -n "$CSSVC_CFG_FILE" ] && sbcfg_setup_for_newrelic_instrumentation "$sbRepoRoot" "$sbTop"
104118

105119
# ----- REMOTE DEVELOPMENT SANDBOXES
106120
# local development on ec2 instances (remote hosts) should reference their

0 commit comments

Comments
 (0)