@@ -103,6 +103,7 @@ if [ "$distro_codename" = "stretch" ]; then
103
103
default_td_agent_version=" $default_td_agent_version_stretch "
104
104
fi
105
105
106
+ preload_path=" /etc/ld.so.preload"
106
107
default_instrumentation_version=" latest"
107
108
default_deployment_environment=" "
108
109
instrumentation_config_path=" /usr/lib/splunk-instrumentation/instrumentation.conf"
@@ -292,23 +293,24 @@ install_yum_package() {
292
293
ensure_not_installed () {
293
294
local with_fluentd=" $1 "
294
295
local with_instrumentation=" $2 "
295
- local agents=" otelcol"
296
+ local otelcol_path=$( command -v otelcol 2> /dev/null || true )
297
+ local td_agent_path=$( command -v td-agent 2> /dev/null || true )
296
298
297
- if [ " $with_fluentd " = " true" ]; then
298
- agents=" $agents td-agent"
299
+ if [ -n " $otelcol_path " ]; then
300
+ echo " $otelcol_path already exists which implies that the collector is already installed." >&2
301
+ echo " Please uninstall the collector, or try running this script with the '--uninstall' option." >&2
302
+ exit 1
299
303
fi
300
304
301
- for agent in $agents ; do
302
- if command -v $agent > /dev/null 2>&1 ; then
303
- echo " An agent binary already exists at $( command -v $agent ) which implies that the agent has already been installed." >&2
304
- echo " Please uninstall the agent and re-run this script." >&2
305
- exit 1
306
- fi
307
- done
305
+ if [ " $with_fluentd " = " true" ] && [ -n " $td_agent_path " ]; then
306
+ echo " $td_agent_path already exists which implies that fluentd/td-agent is already installed." >&2
307
+ echo " Please uninstall fluentd/td-agent, or try running this script with the '--uninstall' option." >&2
308
+ exit 1
309
+ fi
308
310
309
311
if [ " $with_instrumentation " = " true" ] && [ -f " $instrumentation_so_path " ]; then
310
- echo " $instrumentation_so_path already exists which implies that the instrumentation library has already been installed." >&2
311
- echo " Please uninstall the instrumentation library and re-run this script" >&2
312
+ echo " $instrumentation_so_path already exists which implies that auto instrumentation is already installed." >&2
313
+ echo " Please uninstall auto instrumentation, or try running this script with the '--uninstall' option. " >&2
312
314
exit 1
313
315
fi
314
316
}
@@ -411,71 +413,82 @@ configure_fluentd() {
411
413
fi
412
414
}
413
415
414
- update_deployment_environment () {
415
- local deployment_environment =" $1 "
416
+ backup_file () {
417
+ local path =" $1 "
416
418
417
- if grep -q -E " ^resource_attributes=.*deployment\.environment=${deployment_environment} (,|$)" " $instrumentation_config_path " ; then
418
- echo " The 'deployment.environment=${deployment_environment} ' resource attribute already exists in ${instrumentation_config_path} "
419
- else
420
- echo " Adding 'deployment.environment=${deployment_environment} ' resource attribute to $instrumentation_config_path "
421
- if grep -q ' ^resource_attributes=' " $instrumentation_config_path " ; then
422
- # traverse through existing resource attributes to add/update deployment.environment
423
- deployment_environment_found=" false"
424
- attributes=" "
425
- for i in $( grep ' ^resource_attributes=' " $instrumentation_config_path " | sed ' s|^resource_attributes=||' | sed ' s|,| |g' ) ; do
426
- key=" $( echo " $i " | cut -d= -f1) "
427
- value=" $( echo " $i " | cut -d= -f2) "
428
- if [ " $key " = " deployment.environment" ]; then
429
- deployment_environment_found=" true"
430
- value=" $deployment_environment "
431
- fi
432
- attributes=" ${attributes} ,${key} =${value} "
433
- done
434
- if [ " $deployment_environment_found " != " true" ]; then
435
- attributes=" ${attributes} ,deployment.environment=${deployment_environment} "
436
- fi
437
- sed -i " s|^resource_attributes=.*|resource_attributes=${attributes# ,} |" " $instrumentation_config_path "
438
- else
439
- # "resource_attributes=" line not found, simply append the line to the config file
440
- echo " resource_attributes=deployment.environment=${deployment_environment} " >> " $instrumentation_config_path "
441
- fi
419
+ if [ -f " $path " ]; then
420
+ ts=" $( date ' +%Y%m%d-%H%M%S' ) "
421
+ echo " Backing up $path as ${path} .bak.${ts} "
422
+ cp " $path " " ${path} .bak.${ts} "
442
423
fi
443
424
}
444
425
445
- update_instrumentation_option () {
446
- local option =" $1 "
447
- local value= " $2 "
426
+ get_package_version () {
427
+ local package =" $1 "
428
+ local version= " "
448
429
449
- if grep -q -E " ^${option} =.*" " $instrumentation_config_path " ; then
450
- # overwrite existing option=value
451
- sed -i " s|^${option} =.*|${option} =${value} |" " $instrumentation_config_path "
430
+ case " $distro " in
431
+ ubuntu|debian)
432
+ version=" $( dpkg-query --showformat=' ${Version}' --show $package ) "
433
+ ;;
434
+ * )
435
+ version=" $( rpm -q --queryformat=' %{VERSION}' $package ) "
436
+ ;;
437
+ esac
438
+
439
+ echo -n " $version "
440
+ }
441
+
442
+ enable_preload () {
443
+ if [ -f " $preload_path " ]; then
444
+ if ! grep -q " $instrumentation_so_path " " $preload_path " ; then
445
+ backup_file " $preload_path "
446
+ echo " Adding $instrumentation_so_path to $preload_path "
447
+ echo " $instrumentation_so_path " >> " $preload_path "
448
+ fi
452
449
else
453
- # append option=value
454
- echo " ${option} = ${value} " >> " $instrumentation_config_path "
450
+ echo " Adding $instrumentation_so_path to $preload_path "
451
+ echo " $instrumentation_so_path " >> " $preload_path "
455
452
fi
456
453
}
457
454
458
- update_instrumentation_config () {
455
+ disable_preload () {
456
+ if [ -f " $preload_path " ] && grep -q " $instrumentation_so_path " " $preload_path " ; then
457
+ backup_file " $preload_path "
458
+ echo " Removing ${instrumentation_so_path} from ${preload_path} "
459
+ sed -i -e " s|$instrumentation_so_path ||" " $preload_path "
460
+ if [ ! -s " $preload_path " ] || ! grep -q ' [^[:space:]]' " $preload_path " ; then
461
+ echo " Removing empty ${preload_path} "
462
+ rm -f " $preload_path "
463
+ fi
464
+ fi
465
+ }
466
+
467
+ create_instrumentation_config () {
459
468
local deployment_environment=" $1 "
469
+ local version=" $( get_package_version splunk-otel-auto-instrumentation ) "
470
+ local resource_attributes=" splunk.zc.method=splunk-otel-auto-instrumentation-${version} "
471
+
472
+ backup_file " $instrumentation_config_path "
473
+
474
+ echo " Creating ${instrumentation_config_path} "
475
+ cat << EOH > $instrumentation_config_path
476
+ java_agent_jar=${instrumentation_jar_path}
477
+ generate_service_name=${generate_service_name}
478
+ disable_telemetry=${disable_telemetry}
479
+ enable_profiler=${enable_profiler}
480
+ enable_profiler_memory=${enable_profiler_memory}
481
+ enable_metrics=${enable_metrics}
482
+ EOH
460
483
461
- if [ -f " $instrumentation_config_path " ]; then
462
- ts=" $( date ' +%Y%m%d-%H%M%S' ) "
463
- echo " Backing up $instrumentation_config_path as ${instrumentation_config_path} .bak.${ts} "
464
- cp " $instrumentation_config_path " " ${instrumentation_config_path} .bak.${ts} "
465
- if [ -n " $deployment_environment " ]; then
466
- update_deployment_environment " $deployment_environment "
467
- fi
468
- if [ -n " $service_name " ]; then
469
- update_instrumentation_option " service_name" " $service_name "
470
- fi
471
- update_instrumentation_option " generate_service_name" " $generate_service_name "
472
- update_instrumentation_option " disable_telemetry" " $disable_telemetry "
473
- update_instrumentation_option " enable_profiler" " $enable_profiler "
474
- update_instrumentation_option " enable_profiler_memory" " $enable_profiler_memory "
475
- update_instrumentation_option " enable_metrics" " $enable_metrics "
476
- else
477
- echo " $instrumentation_config_path not found!" >&2
478
- exit 1
484
+ if [ -n " $deployment_environment " ]; then
485
+ resource_attributes=" ${resource_attributes} ,deployment.environment=${deployment_environment} "
486
+ fi
487
+
488
+ echo " resource_attributes=${resource_attributes% ,} " >> $instrumentation_config_path
489
+
490
+ if [ -n " $service_name " ]; then
491
+ echo " service_name=${service_name} " >> $instrumentation_config_path
479
492
fi
480
493
}
481
494
@@ -626,6 +639,8 @@ If access_token is not provided, it will be prompted for on stdin.
626
639
627
640
Options:
628
641
642
+ Collector:
643
+ -- <access_token> Use '--' if access_token starts with '-'.
629
644
--api-url <url> Set the api endpoint URL explicitly instead of the endpoint inferred from the
630
645
specified realm.
631
646
(default: https://api.REALM.signalfx.com)
@@ -670,20 +685,28 @@ Options:
670
685
the collector deb/rpm package from $repo_base .
671
686
Specify this option to skip this step and use a pre-configured repo on the
672
687
target system that provides the 'splunk-otel-collector' deb/rpm package.
673
- --skip-fluentd-repo By default, a apt/yum repo definition file will be created to download the
674
- fluentd deb/rpm package from $td_agent_repo_base .
675
- Specify this option to skip this step and use a pre-configured repo on the
676
- target system that provides the 'td-agent' deb/rpm package.
677
688
--test Use the test package repo instead of the primary.
678
689
--trace-url <url> Set the trace endpoint URL explicitly instead of the endpoint inferred from the
679
690
specified realm.
680
691
(default: https://ingest.REALM.signalfx.com/v2/trace)
681
- --uninstall Removes the Splunk OpenTelemetry Collector for Linux.
692
+
693
+ Fluentd:
682
694
--with[out]-fluentd Whether to install and configure fluentd to forward log events to the collector.
683
695
(default: --without-fluentd)
684
- --with[out]-instrumentation Whether to install and configure the splunk-otel-auto-instrumentation package.
696
+ --skip-fluentd-repo By default, a apt/yum repo definition file will be created to download the
697
+ fluentd deb/rpm package from $td_agent_repo_base .
698
+ Specify this option to skip this step and use a pre-configured repo on the
699
+ target system that provides the 'td-agent' deb/rpm package.
700
+ Only applicable if the '--with-fluentd' is also specified.
701
+
702
+ Auto Instrumentation:
703
+ --with[out]-instrumentation Whether to install the splunk-otel-auto-instrumentation package and add the
704
+ libsplunk.so shared object library to /etc/ld.so.preload to enable auto
705
+ instrumentation for all supported processes on the host.
685
706
(default: --without-instrumentation)
686
707
--deployment-environment <value> Set the 'deployment.environment' resource attribute to the specified value.
708
+ If not specified, the "Environment" in the Splunk APM UI will appear as
709
+ "unknown" for the auto instrumented application(s).
687
710
Only applicable if the '--with-instrumentation' option is also specified.
688
711
(default: empty)
689
712
--service-name <name> Override the auto-generated service names for all instrumented Java applications
@@ -710,7 +733,10 @@ Options:
710
733
--instrumentation-version The splunk-otel-auto-instrumentation package version to install.
711
734
Only applicable if the '--with-instrumentation' option is also specified.
712
735
(default: $default_instrumentation_version )
713
- -- Use '--' if access_token starts with '-'.
736
+
737
+ Uninstall:
738
+ --uninstall Removes the Splunk OpenTelemetry Collector for Linux, Fluentd, and Splunk
739
+ OpenTelemetry Auto Instrumentation packages, if installed.
714
740
715
741
EOH
716
742
exit 0
@@ -950,11 +976,9 @@ parse_args_and_install() {
950
976
uninstall=" true"
951
977
;;
952
978
--with-fluentd)
979
+ with_fluentd=" true"
953
980
if ! fluentd_supported; then
954
981
echo " WARNING: Ignoring the --with-fluentd option since fluentd is currently not supported for ${distro} :${distro_version} ${distro_arch} ." >&2
955
- with_fluentd=" false"
956
- else
957
- with_fluentd=" true"
958
982
fi
959
983
;;
960
984
--without-fluentd)
@@ -1038,12 +1062,6 @@ parse_args_and_install() {
1038
1062
exit 0
1039
1063
fi
1040
1064
1041
- if ! fluentd_supported; then
1042
- with_fluentd=" false"
1043
- fi
1044
-
1045
- ensure_not_installed " $with_fluentd " " $with_instrumentation "
1046
-
1047
1065
if [ -z " $access_token " ]; then
1048
1066
access_token=$( request_access_token)
1049
1067
fi
@@ -1064,19 +1082,22 @@ parse_args_and_install() {
1064
1082
hec_url=" ${ingest_url} /v1/log"
1065
1083
fi
1066
1084
1067
- if [ " $with_fluentd " != " true" ]; then
1085
+ if [ " $with_fluentd " != " true" ] || ! fluentd_supported ; then
1068
1086
td_agent_version=" "
1069
1087
fi
1070
1088
1071
1089
if [ " $with_instrumentation " != " true" ]; then
1072
1090
instrumentation_version=" "
1073
- deployment_environment=" "
1074
1091
fi
1075
1092
1076
1093
if [ -z " $trace_url " ]; then
1077
1094
trace_url=" ${ingest_url} /v2/trace"
1078
1095
fi
1079
1096
1097
+ check_support
1098
+
1099
+ ensure_not_installed " $with_fluentd " " $with_instrumentation "
1100
+
1080
1101
echo " Splunk OpenTelemetry Collector Version: ${collector_version} "
1081
1102
if [ -n " $ballast " ]; then
1082
1103
echo " Ballast Size in MIB: $ballast "
@@ -1088,15 +1109,25 @@ parse_args_and_install() {
1088
1109
echo " API Endpoint: $api_url "
1089
1110
echo " Trace Endpoint: $trace_url "
1090
1111
echo " HEC Endpoint: $hec_url "
1091
- if [ " $with_fluentd " = " true " ]; then
1112
+ if [ -n " $td_agent_version " ]; then
1092
1113
echo " TD Agent (Fluentd) Version: $td_agent_version "
1093
1114
fi
1094
- if [ " $with_instrumentation " = " true " ]; then
1115
+ if [ -n " $instrumentation_version " ]; then
1095
1116
echo " Splunk OpenTelemetry Auto Instrumentation Version: $instrumentation_version "
1096
1117
if [ -n " $deployment_environment " ]; then
1097
- echo " Resource Attribute: deployment.environment=${deployment_environment} "
1118
+ echo " Deployment environment: $deployment_environment "
1119
+ else
1120
+ echo " Deployment environment: unknown"
1098
1121
fi
1122
+ if [ -n " $service_name " ]; then
1123
+ echo " Service name: $service_name "
1124
+ else
1125
+ echo " Service name: auto-generated"
1126
+ fi
1127
+ echo " AlwaysOn Profiling enabled: $enable_profiler "
1128
+ echo " AlwaysOn Memory Profiling enabled: $enable_profiler_memory "
1099
1129
fi
1130
+ echo
1100
1131
1101
1132
if [ " ${VERIFY_ACCESS_TOKEN:- true} " = " true" ] && ! verify_access_token " $access_token " " $ingest_url " " $insecure " ; then
1102
1133
echo " Your access token could not be verified. This may be due to a network connectivity issue or an invalid access token." >&2
@@ -1106,7 +1137,9 @@ parse_args_and_install() {
1106
1137
install " $stage " " $collector_version " " $td_agent_version " " $skip_collector_repo " " $skip_fluentd_repo " " $instrumentation_version "
1107
1138
1108
1139
if [ " $with_instrumentation " = " true" ]; then
1109
- update_instrumentation_config " $deployment_environment "
1140
+ # add libsplunk.so to /etc/ld.so.preload if it was not added automatically by the instrumentation package
1141
+ enable_preload
1142
+ create_instrumentation_config " $deployment_environment "
1110
1143
fi
1111
1144
1112
1145
create_user_group " $service_user " " $service_group "
@@ -1200,7 +1233,7 @@ parse_args_and_install() {
1200
1233
systemctl daemon-reload
1201
1234
systemctl restart splunk-otel-collector
1202
1235
1203
- if [ " $with_fluentd " = " true " ]; then
1236
+ if [ -n " $td_agent_version " ]; then
1204
1237
# only start fluentd with our custom config to avoid port conflicts within the default config
1205
1238
systemctl stop td-agent
1206
1239
if [ -f " $fluent_config_path " ]; then
@@ -1214,6 +1247,7 @@ parse_args_and_install() {
1214
1247
fi
1215
1248
fi
1216
1249
1250
+ echo
1217
1251
cat << EOH
1218
1252
The Splunk OpenTelemetry Collector for Linux has been successfully installed.
1219
1253
@@ -1229,7 +1263,7 @@ must be restarted to apply the changes by running the following command as root:
1229
1263
1230
1264
EOH
1231
1265
1232
- if [ " $with_fluentd " = " true " ] && [ -f " $fluent_config_path " ]; then
1266
+ if [ -n " $td_agent_version " ] && [ -f " $fluent_config_path " ]; then
1233
1267
cat << EOH
1234
1268
Fluentd has been installed and configured to forward log events to the Splunk OpenTelemetry Collector.
1235
1269
By default, all log events with the @SPLUNK label will be forwarded to the collector.
@@ -1259,13 +1293,19 @@ The Splunk OpenTelemetry Auto Instrumentation package has been installed.
1259
1293
/etc/ld.so.preload has been configured for the instrumentation library at $instrumentation_so_path .
1260
1294
The configuration file is located at $instrumentation_config_path .
1261
1295
1262
- The Java application(s) on the host need to be manually started/restarted.
1296
+ Reboot the system or restart the Java application(s) for auto instrumentation to take effect.
1297
+
1298
+ EOH
1299
+ fi
1300
+
1301
+ if [ " $with_fluentd " = " true" ] && ! fluentd_supported; then
1302
+ cat << EOH >&2
1303
+ WARNING: Fluentd was not installed since it is currently not supported for ${distro} :${distro_version} ${distro_arch}
1263
1304
1264
1305
EOH
1265
1306
fi
1307
+
1266
1308
exit 0
1267
1309
}
1268
1310
1269
- check_support
1270
-
1271
1311
parse_args_and_install $@
0 commit comments