-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create spans for Github workflow jobs and auto-inject into run steps
- Loading branch information
Showing
13 changed files
with
228 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4.5.0 | ||
4.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: 'OpenTelemetry' | ||
description: 'Observe Github Actions with OpenTelemetry' | ||
runs: | ||
using: 'node20' | ||
pre: 'inject_and_init.js' | ||
main: 'nop.js' | ||
post: 'shutdown.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
// forward [ forward arg1 arg2 NULL ] => EXECUTABLE [ EXECUTABLE ARG1 ARG2 arg1 arg2 NULL ] | ||
|
||
#ifndef EXECUTABLE | ||
#error must define executable | ||
#endif | ||
|
||
#define STR(s) XSTR(s) | ||
#define XSTR(s) #s | ||
|
||
int main(int argc, char **argv) { | ||
int new_argc = argc; | ||
#ifdef ARG1 | ||
new_argc++; | ||
#endif | ||
#ifdef ARG2 | ||
new_argc++; | ||
#endif | ||
|
||
char **new_argv = (char**) calloc((size_t) new_argc + 1, sizeof(char*)); | ||
int i = 0; | ||
new_argv[i++] = STR(EXECUTABLE); | ||
#ifdef ARG1 | ||
new_argv[i++] = STR(ARG1); | ||
#endif | ||
#ifdef ARG2 | ||
new_argv[i++] = STR(ARG2); | ||
#endif | ||
for (int j = 1; j < argc; j++) { | ||
new_argv[i++] = argv[j]; | ||
} | ||
new_argv[i++] = NULL; | ||
|
||
execv(STR(EXECUTABLE), new_argv); | ||
perror("execv failed"); | ||
free(new_argv); | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#/bin/sh | ||
set -e | ||
# sh|dash|bash -e /.../*.sh | ||
if [ -n "$GITHUB_RUN_ID" ] && [ -f "$3" ] && [ "$(echo "$3" | rev | cut -d . -f 1 | rev)" = "sh" ] && [ "$(echo "$GITHUB_ENV" | rev | cut -d / -f 3- | rev)" = "$(echo "$3" | rev | cut -d / -f 2- | rev)" ]; then | ||
file="$3" | ||
script="$(cat "$file")" | ||
script=". otel.sh | ||
$script" | ||
echo "$script" > "$file" | ||
fi | ||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
set -e | ||
|
||
root4job_end() { | ||
if [ "$(curl "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs" | jq -r ".jobs[] | select(.name==\"$GITHUB_JOB\") | select(.run_attempt==\"$GITHUB_RUN_ATTEMPT\") | .steps[] | select(.status==\"completed\") | select(.conclusion==\"failure\") | .name" | wc -l)" -gt 0 ]; then | ||
otel_span_error "$span_handle" | ||
fi | ||
otel_span_end "$span_handle" | ||
otel_shutdown | ||
exit 0 | ||
} | ||
export -f root4job_end | ||
|
||
root4job() { | ||
traceparent_file="$1" | ||
. otelapi.sh | ||
otel_init | ||
span_handle="$(otel_span_start CONSUMER "$GITHUB_WORKFLOW / $GITHUB_JOB")" | ||
otel_span_activate "$span_handle" | ||
echo "$OTEL_TRACEPARENT" > "$traceparent_file" | ||
otel_span_deactivate "$span_handle" | ||
trap root4job_end SIGUSR1 | ||
while true; do sleep 1; done | ||
} | ||
export -f root4job | ||
|
||
root_pid_file="$(mktemp -u | rev | cut -d / -f 2- | rev)/opentelemetry_shell_$GITHUB_RUN_ID.pid" | ||
traceparent_file="$(mktemp -u)" | ||
nohup bash -c 'root4job "$@"' bash "$traceparent_file" &> /dev/null & | ||
echo "$!" > "$root_pid_file" | ||
|
||
while ! [ -f "$traceparent_file" ]; do sleep 1; done | ||
export OTEL_TRACEPARENT="$(cat "$traceparent_file")" | ||
rm "$traceparent_file" | ||
|
||
if [ -z "$OTEL_SERVICE_NAME" ]; then | ||
export OTEL_SERVICE_NAME="$(echo "$GITHUB_REPOSITORY" | cut -d / -f 2-) CI" | ||
fi | ||
|
||
printenv | grep '^OTEL_' >> "$GITHUB_ENV" | ||
|
||
my_dir="$(echo "$0" | rev | cut -d / -f 2- | rev)" | ||
new_path_dir="$(mktemp -d)" | ||
gcc -o "$new_path_dir"/sh_w_otel "$my_dir"/forward.c -DEXECUTABLE="$(which sh)" -DARG1="$my_dir"/forward.sh -DARG2="$(which sh)" | ||
gcc -o "$new_path_dir"/dash_w_otel "$my_dir"/forward.c -DEXECUTABLE="$(which dash)" -DARG1="$my_dir"/forward.sh -DARG2="$(which dash)" | ||
gcc -o "$new_path_dir"/bash_w_otel "$my_dir"/forward.c -DEXECUTABLE="$(which bash)" -DARG1="$my_dir"/forward.sh -DARG2="$(which bash)" | ||
ln --symbolic "$new_path_dir"/sh_w_otel "$new_path_dir"/sh | ||
ln --symbolic "$new_path_dir"/dash_w_otel "$new_path_dir"/dash | ||
ln --symbolic "$new_path_dir"/bash_w_otel "$new_path_dir"/bash | ||
echo "$new_path_dir" >> "$GITHUB_PATH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { spawn } = require('child_process'); | ||
|
||
function run(executable, args = []) { | ||
return new Promise((resolve, reject) => { | ||
const process = spawn(executable, args); | ||
process.stdout.on('data', data => console.log('' + data)); | ||
process.stderr.on('data', data => console.error('' + data)); | ||
process.on('close', code => code == 0 ? resolve(code) : reject(code)); | ||
process.on('error', error => reject(new Error(error))); | ||
}); | ||
} | ||
|
||
run('/bin/sh', [ '-c', 'wget -O - https://raw.githubusercontent.com/plengauer/opentelemetry-bash/main/INSTALL.sh | sh -E' ]) | ||
.then(() => run('/bin/bash', [ '-e', __dirname + '/inject_and_init.bash' ])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const process = require('process'); | ||
if (process.env['GITHUB_REPOSITORY'] == 'plengauer/opentelemetry-bash') { | ||
// action is local and pre steps is not supported because the action needs to be checked out first and then its too let to execute a pre step | ||
require('./inject_and_init.js'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { spawn } = require('child_process'); | ||
|
||
function run(executable, args = []) { | ||
return new Promise((resolve, reject) => { | ||
const process = spawn(executable, args); | ||
process.stdout.on('data', data => console.log('' + data)); | ||
process.stderr.on('data', data => console.error('' + data)); | ||
process.on('close', code => code == 0 ? resolve(code) : reject(code)); | ||
process.on('error', error => reject(new Error(error))); | ||
}); | ||
} | ||
|
||
run('/bin/sh', [ '-e', __dirname + '/shutdown.sh' ]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
set -e | ||
root_pid_file="$(mktemp -u | rev | cut -d / -f 2- | rev)/opentelemetry_shell_$GITHUB_RUN_ID.pid" | ||
root_pid="$(cat "$root_pid_file")" | ||
kill -USR1 "$root_pid" | ||
while kill -0 "$root_pid" 2> /dev/null; do sleep 1; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters