From 0258e7c878efdb25a662dcff61d7987cadc6260a Mon Sep 17 00:00:00 2001 From: John Bley Date: Tue, 31 Jan 2023 13:39:15 -0500 Subject: [PATCH 1/9] nodejs script has duplicate logic from splunk-default-config --- nodejs/nodejs-otel-handler | 3 --- 1 file changed, 3 deletions(-) diff --git a/nodejs/nodejs-otel-handler b/nodejs/nodejs-otel-handler index 93e29f6..2604db0 100755 --- a/nodejs/nodejs-otel-handler +++ b/nodejs/nodejs-otel-handler @@ -1,7 +1,4 @@ #!/bin/bash - -export OTEL_TRACES_EXPORTER="${OTEL_TRACES_EXPORTER:-otlp}" - source /opt/splunk-default-config export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js" From c1bdb147f984f5524665a6881dae4d03693b5816 Mon Sep 17 00:00:00 2001 From: John Bley Date: Tue, 31 Jan 2023 13:46:53 -0500 Subject: [PATCH 2/9] Modify upstream python wrapper during build instead of forking it --- python/build-layer.sh | 6 +++--- python/otel-instrument | 17 ----------------- 2 files changed, 3 insertions(+), 20 deletions(-) delete mode 100755 python/otel-instrument diff --git a/python/build-layer.sh b/python/build-layer.sh index b1d670e..fe6051f 100755 --- a/python/build-layer.sh +++ b/python/build-layer.sh @@ -24,13 +24,13 @@ rm -rf build cd $DISTRO_DIR docker cp "$(docker ps --all | grep aws-otel-lambda-python-layer | cut -d' ' -f1 | head -1)":/out/layer.zip . unzip -qo layer.zip && rm layer.zip -mv otel-instrument otel-instrument-upstream +# inject our script into upstream wrapper +sed -i '2isource splunk-default-config' otel-instrument popd echo "Preparing Splunk layer" -# copy Splunk scripts (delegating to OTEL ones) -cp otel-instrument $OTEL_PYTHON_DIR/$DISTRO_DIR/ +# copy Splunk scripts cp ../scripts/* $OTEL_PYTHON_DIR/$DISTRO_DIR/ cp -r ./src/* $OTEL_PYTHON_DIR/$DISTRO_DIR/python/ cd $OTEL_PYTHON_DIR/$DISTRO_DIR diff --git a/python/otel-instrument b/python/otel-instrument deleted file mode 100755 index 12a6548..0000000 --- a/python/otel-instrument +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -source /opt/splunk-default-config - -# temporarily, until Python supports spec exporter/protocol values -if [[ $OTEL_TRACES_EXPORTER = *"otlp"* ]] -then - if [ "$OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" = "grpc" ] - then - export OTEL_TRACES_EXPORTER="otlp_proto_grpc" - elif [ "$OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" = "http/protobuf" ] - then - export OTEL_TRACES_EXPORTER="otlp_proto_http" - fi -fi - -/opt/otel-instrument-upstream "$@" From 1d6706437ba7ae0a128bb9b3cbe227938d18ec13 Mon Sep 17 00:00:00 2001 From: John Bley Date: Tue, 31 Jan 2023 13:53:32 -0500 Subject: [PATCH 3/9] Modify upstream java wrappers during build instead of forking them --- java/build-layer.sh | 9 ++++++--- java/scripts/otel-handler | 13 ------------- java/scripts/otel-proxy-handler | 13 ------------- java/scripts/otel-stream-handler | 13 ------------- python/build-layer.sh | 2 +- 5 files changed, 7 insertions(+), 43 deletions(-) delete mode 100755 java/scripts/otel-handler delete mode 100755 java/scripts/otel-proxy-handler delete mode 100755 java/scripts/otel-stream-handler diff --git a/java/build-layer.sh b/java/build-layer.sh index 8e4d01d..f8e8c3a 100755 --- a/java/build-layer.sh +++ b/java/build-layer.sh @@ -21,9 +21,12 @@ echo "Preparing Splunk layer" cd $DISTRO_DIR unzip -qo opentelemetry-java-wrapper.zip rm opentelemetry-java-wrapper.zip -mv otel-handler otel-handler-upstream -mv otel-stream-handler otel-stream-handler-upstream -mv otel-proxy-handler otel-proxy-handler-upstream +sed -i '2isource /opt/splunk-default-config' otel-handler +sed -i '2isource /opt/splunk-default-config' otel-stream-handler +sed -i '2isource /opt/splunk-default-config' otel-proxy-handler +sed -i '3isource /opt/splunk-java-config' otel-handler +sed -i '3isource /opt/splunk-java-config' otel-stream-handler +sed -i '3isource /opt/splunk-java-config' otel-proxy-handler popd # copy Splunk scripts (delegating to OTEL ones) diff --git a/java/scripts/otel-handler b/java/scripts/otel-handler deleted file mode 100755 index 306c911..0000000 --- a/java/scripts/otel-handler +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -source /opt/splunk-default-config -source /opt/splunk-java-config - -export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER" -export _HANDLER="io.opentelemetry.instrumentation.awslambdaevents.v2_2.TracingRequestWrapper" - -if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then - export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}" -fi - -exec "$@" \ No newline at end of file diff --git a/java/scripts/otel-proxy-handler b/java/scripts/otel-proxy-handler deleted file mode 100755 index 2054ab5..0000000 --- a/java/scripts/otel-proxy-handler +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -source /opt/splunk-default-config -source /opt/splunk-java-config - -export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER" -export _HANDLER="com.splunk.support.lambda.TracingRequestApiGatewayWrapper" - -if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then - export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}" -fi - -exec "$@" diff --git a/java/scripts/otel-stream-handler b/java/scripts/otel-stream-handler deleted file mode 100755 index c8ec6c0..0000000 --- a/java/scripts/otel-stream-handler +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -source /opt/splunk-default-config -source /opt/splunk-java-config - -export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER" -export _HANDLER="io.opentelemetry.instrumentation.awslambdacore.v1_0.TracingRequestStreamWrapper" - -if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then - export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}" -fi - -exec "$@" \ No newline at end of file diff --git a/python/build-layer.sh b/python/build-layer.sh index fe6051f..609abba 100755 --- a/python/build-layer.sh +++ b/python/build-layer.sh @@ -25,7 +25,7 @@ cd $DISTRO_DIR docker cp "$(docker ps --all | grep aws-otel-lambda-python-layer | cut -d' ' -f1 | head -1)":/out/layer.zip . unzip -qo layer.zip && rm layer.zip # inject our script into upstream wrapper -sed -i '2isource splunk-default-config' otel-instrument +sed -i '2isource /opt/splunk-default-config' otel-instrument popd From cb745610e5d1fdf2184a6a5f8ac5e80962f03771 Mon Sep 17 00:00:00 2001 From: John Bley Date: Tue, 31 Jan 2023 14:01:41 -0500 Subject: [PATCH 4/9] Specifically disable SPLUNK_REALM and associated variables and logic for language instrumentations. --- scripts/splunk-default-config | 40 +++-------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/scripts/splunk-default-config b/scripts/splunk-default-config index de9f510..c263b8c 100755 --- a/scripts/splunk-default-config +++ b/scripts/splunk-default-config @@ -1,4 +1,7 @@ #!/bin/bash +# specifically unset these so language-level instrumentations won't talk directly to ingest +unset SPLUNK_REALM +unset SPLUNK_ACCESS_TOKEN # no otel metrics export OTEL_METRICS_EXPORTER=none @@ -14,42 +17,5 @@ export OTEL_PROPAGATORS="${OTEL_PROPAGATORS:-tracecontext,baggage}" # no sampling export OTEL_TRACES_SAMPLER="${OTEL_TRACES_SAMPLER:-always_on}" -# splunk token header if OLTP -if [[ -n "$SPLUNK_ACCESS_TOKEN" && "$OTEL_TRACES_EXPORTER" = "otlp" ]] -then - HEADER="X-SF-TOKEN=$SPLUNK_ACCESS_TOKEN," - export OTEL_EXPORTER_OTLP_TRACES_HEADERS="$HEADER""${OTEL_EXPORTER_OTLP_TRACES_HEADERS}" -fi - # default flush timeout if not set export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT="${OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT:-30000}" - -# splunk REALM support -if [ -n "$SPLUNK_REALM" ] -then - - if [ -z "$SPLUNK_METRICS_ENDPOINT" ] - then - export SPLUNK_METRICS_ENDPOINT="https://ingest.${SPLUNK_REALM}.signalfx.com" - fi - - if [[ "$OTEL_TRACES_EXPORTER" = *"otlp"* && -z "$OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" ]] - then - export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://ingest.${SPLUNK_REALM}.signalfx.com/v2/trace/otlp" - elif [[ "$OTEL_TRACES_EXPORTER" = *"jaeger"* && -z "$OTEL_EXPORTER_JAEGER_ENDPOINT" ]] - then - export OTEL_EXPORTER_JAEGER_ENDPOINT="https://ingest.${SPLUNK_REALM}.signalfx.com/v2/trace" - fi -fi - -# validation - realm must have token -if [[ -n "$SPLUNK_REALM" && -z "$SPLUNK_ACCESS_TOKEN" ]] -then - echo "[ERROR] SPLUNK_REALM is set, but SPLUNK_ACCESS_TOKEN is not set. To export data to Splunk Observability Cloud, define a Splunk Access Token" -fi - -# validation - either realm or relevant exporter endpoint -if [[ -z "$SPLUNK_REALM" && ( "$OTEL_TRACES_EXPORTER" = *"otlp"* && -z "$OTEL_EXPORTER_OTLP_ENDPOINT" || "$OTEL_TRACES_EXPORTER" = *"jaeger"* && -z "$OTEL_EXPORTER_JAEGER_ENDPOINT" ) ]] -then - echo "[ERROR] Exporter endpoint must be set when SPLUNK_REALM is not set. To export data, either set a realm and access token or a custom exporter endpoint." -fi \ No newline at end of file From 36d135cb6fadefa48838eb837f98c9ff45d8bae5 Mon Sep 17 00:00:00 2001 From: John Bley Date: Tue, 7 Feb 2023 10:58:13 -0500 Subject: [PATCH 5/9] Empty commit to force build From 6337f07fb30864c3ccba0d98d7d2097ba35cbc35 Mon Sep 17 00:00:00 2001 From: John Bley Date: Tue, 7 Feb 2023 12:18:15 -0500 Subject: [PATCH 6/9] Empty commit to force build (2) From 3980016541e9c7e257d48321e685cdc17c4f4683 Mon Sep 17 00:00:00 2001 From: John Bley Date: Tue, 7 Feb 2023 13:28:26 -0500 Subject: [PATCH 7/9] Revert "Modify upstream python wrapper during build instead of forking it" This reverts commit c1bdb147f984f5524665a6881dae4d03693b5816. --- python/build-layer.sh | 6 +++--- python/otel-instrument | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100755 python/otel-instrument diff --git a/python/build-layer.sh b/python/build-layer.sh index 609abba..b1d670e 100755 --- a/python/build-layer.sh +++ b/python/build-layer.sh @@ -24,13 +24,13 @@ rm -rf build cd $DISTRO_DIR docker cp "$(docker ps --all | grep aws-otel-lambda-python-layer | cut -d' ' -f1 | head -1)":/out/layer.zip . unzip -qo layer.zip && rm layer.zip -# inject our script into upstream wrapper -sed -i '2isource /opt/splunk-default-config' otel-instrument +mv otel-instrument otel-instrument-upstream popd echo "Preparing Splunk layer" -# copy Splunk scripts +# copy Splunk scripts (delegating to OTEL ones) +cp otel-instrument $OTEL_PYTHON_DIR/$DISTRO_DIR/ cp ../scripts/* $OTEL_PYTHON_DIR/$DISTRO_DIR/ cp -r ./src/* $OTEL_PYTHON_DIR/$DISTRO_DIR/python/ cd $OTEL_PYTHON_DIR/$DISTRO_DIR diff --git a/python/otel-instrument b/python/otel-instrument new file mode 100755 index 0000000..12a6548 --- /dev/null +++ b/python/otel-instrument @@ -0,0 +1,17 @@ +#!/bin/bash + +source /opt/splunk-default-config + +# temporarily, until Python supports spec exporter/protocol values +if [[ $OTEL_TRACES_EXPORTER = *"otlp"* ]] +then + if [ "$OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" = "grpc" ] + then + export OTEL_TRACES_EXPORTER="otlp_proto_grpc" + elif [ "$OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" = "http/protobuf" ] + then + export OTEL_TRACES_EXPORTER="otlp_proto_http" + fi +fi + +/opt/otel-instrument-upstream "$@" From 02a44b4b5fc5915b2ce2503ae76a9bfac9d9a515 Mon Sep 17 00:00:00 2001 From: John Bley Date: Tue, 7 Feb 2023 15:38:58 -0500 Subject: [PATCH 8/9] Empty commit to force build (3) From 1096a3857a681ac5e6bb2e53a3a1b8932043f775 Mon Sep 17 00:00:00 2001 From: John Bley Date: Tue, 7 Feb 2023 16:08:03 -0500 Subject: [PATCH 9/9] Modify Java proxy handler in wrapper script to ours --- java/build-layer.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/java/build-layer.sh b/java/build-layer.sh index f8e8c3a..013f658 100755 --- a/java/build-layer.sh +++ b/java/build-layer.sh @@ -27,6 +27,9 @@ sed -i '2isource /opt/splunk-default-config' otel-proxy-handler sed -i '3isource /opt/splunk-java-config' otel-handler sed -i '3isource /opt/splunk-java-config' otel-stream-handler sed -i '3isource /opt/splunk-java-config' otel-proxy-handler +# proxy handler has one more special change +sed -i 's/io.opentelemetry.instrumentation.awslambdaevents.v2_2.TracingRequestApiGatewayWrapper/com.splunk.support.lambda.TracingRequestApiGatewayWrapper/g' otel-proxy-handler + popd # copy Splunk scripts (delegating to OTEL ones)