diff --git a/datasources/windows/localhost/windows/system/telemetry/logs/functions.ps1 b/datasources/windows/localhost/windows/system/telemetry/logs/functions.ps1 index abd1a440e..d3ce30772 100755 --- a/datasources/windows/localhost/windows/system/telemetry/logs/functions.ps1 +++ b/datasources/windows/localhost/windows/system/telemetry/logs/functions.ps1 @@ -609,6 +609,14 @@ function Add-LogsExporterToOtelConfig { return $ExitCode } + $Err = Set-YamlFileFieldValue "$script:OtelExportersDir\logzio_logs.yaml" '.logzio/logs.headers.user-agent' $script:UserAgentLogs + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0]))" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:SubType $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + return $ExitCode + } + $local:LogzioRegion = Get-LogzioRegion $ListenerUrl $Message = "Logz.io region is '$LogzioRegion'" diff --git a/datasources/windows/localhost/windows/system/telemetry/metrics/functions.ps1 b/datasources/windows/localhost/windows/system/telemetry/metrics/functions.ps1 index 65f2609b8..0adf307f1 100755 --- a/datasources/windows/localhost/windows/system/telemetry/metrics/functions.ps1 +++ b/datasources/windows/localhost/windows/system/telemetry/metrics/functions.ps1 @@ -416,6 +416,14 @@ function Add-MetricsExporterToOtelConfig { return $ExitCode } + $Err = Set-YamlFileFieldValue "$script:OtelExportersDir\prometheusremotewrite.yaml" '.prometheusremotewrite.headers.user-agent' $script:UserAgentMetrics + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0]))" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + return $ExitCode + } + $Err = Add-YamlFileFieldValueToAnotherYamlFileField "$script:OtelExportersDir\prometheusremotewrite.yaml" "$script:OtelResourcesDir\$script:OtelConfigName" '' '.exporters' if ($Err.Count -ne 0) { $Message = "metrics.ps1 ($ExitCode): $($Err[0]))" diff --git a/resources-linux/otel/datasource_logs_utils.bash b/resources-linux/otel/datasource_logs_utils.bash index 37829bebe..3ad6c8253 100755 --- a/resources-linux/otel/datasource_logs_utils.bash +++ b/resources-linux/otel/datasource_logs_utils.bash @@ -288,6 +288,15 @@ function add_logs_exporter_to_otel_config { return $EXIT_CODE fi + set_yaml_file_field_value "$OTEL_EXPORTERS_DIR/logzio_logs.yaml" '.logzio/logs.headers.user-agent' "$USER_AGENT_LOGS" + if [[ $? -ne 0 ]]; then + message="logs.bash ($EXIT_CODE): $(get_task_error_message)" + send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_LOGS" "$LOG_SCRIPT_LOGS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_task_post_run "write_error \"$message\"" + + return $EXIT_CODE + fi + local logzio_region=$(get_logzio_region "$LISTENER_URL") message="Logz.io region is '$logzio_region'" diff --git a/resources-linux/otel/datasource_metrics_utils.bash b/resources-linux/otel/datasource_metrics_utils.bash index a680bcf1c..efe5d769f 100755 --- a/resources-linux/otel/datasource_metrics_utils.bash +++ b/resources-linux/otel/datasource_metrics_utils.bash @@ -318,6 +318,15 @@ function add_metrics_exporter_to_otel_config { return $EXIT_CODE fi + set_yaml_file_field_value "$OTEL_EXPORTERS_DIR/prometheusremotewrite.yaml" '.prometheusremotewrite.headers.user-agent' "Bearer $USER_AGENT_METRICS" + if [[ $? -ne 0 ]]; then + message="metrics.bash ($EXIT_CODE): $(get_task_error_message)" + send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_task_post_run "write_error \"$message\"" + + return $EXIT_CODE + fi + add_yaml_file_field_value_to_another_yaml_file_field "$OTEL_EXPORTERS_DIR/prometheusremotewrite.yaml" "$OTEL_RESOURCES_DIR/$OTEL_CONFIG_NAME" '' '.exporters' if [[ $? -ne 0 ]]; then message="metrics.bash ($EXIT_CODE): $(get_task_error_message)" diff --git a/resources-mac/otel/datasource_logs_utils.bash b/resources-mac/otel/datasource_logs_utils.bash index 016abf472..ff5cd7d13 100755 --- a/resources-mac/otel/datasource_logs_utils.bash +++ b/resources-mac/otel/datasource_logs_utils.bash @@ -289,6 +289,15 @@ function add_logs_exporter_to_otel_config { return $EXIT_CODE fi + set_yaml_file_field_value "$OTEL_EXPORTERS_DIR/logzio_logs.yaml" '.logzio/logs.headers.user-agent' "$USER_AGENT_LOGS" + if [[ $? -ne 0 ]]; then + message="logs.bash ($EXIT_CODE): $(get_task_error_message)" + send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_LOGS" "$LOG_SCRIPT_LOGS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_task_post_run "write_error \"$message\"" + + return $EXIT_CODE + fi + local logzio_region=$(get_logzio_region "$LISTENER_URL") message="Logz.io region is '$logzio_region'" diff --git a/resources-mac/otel/datasource_metrics_utils.bash b/resources-mac/otel/datasource_metrics_utils.bash index eece73ac4..0e9d80cce 100755 --- a/resources-mac/otel/datasource_metrics_utils.bash +++ b/resources-mac/otel/datasource_metrics_utils.bash @@ -318,6 +318,15 @@ function add_metrics_exporter_to_otel_config { return $EXIT_CODE fi + set_yaml_file_field_value "$OTEL_EXPORTERS_DIR/prometheusremotewrite.yaml" '.prometheusremotewrite.headers.user-agent' "Bearer $USER_AGENT_METRICS" + if [[ $? -ne 0 ]]; then + message="metrics.bash ($EXIT_CODE): $(get_task_error_message)" + send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_task_post_run "write_error \"$message\"" + + return $EXIT_CODE + fi + add_yaml_file_field_value_to_another_yaml_file_field "$OTEL_EXPORTERS_DIR/prometheusremotewrite.yaml" "$OTEL_RESOURCES_DIR/$OTEL_CONFIG_NAME" '' '.exporters' if [[ $? -ne 0 ]]; then message="metrics.bash ($EXIT_CODE): $(get_task_error_message)" diff --git a/scripts/linux/consts.bash b/scripts/linux/consts.bash index 439edd5c5..9dec9bcf8 100755 --- a/scripts/linux/consts.bash +++ b/scripts/linux/consts.bash @@ -152,3 +152,8 @@ PURPLE_COLOR='\033[0;35m' WHITE_COLOR='\033[0;37m' RED_COLOR_BOLD='\033[1;31m' GREEN_COLOR_BOLD='\033[0;32m' + +## Headers +AGENT_VERSION=$(cat "$LOGZIO_TEMP_DIR/version") +USER_AGENT_LOGS="logzio-linux-version-$AGENT_VERSION-logs" +USER_AGENT_METRICS="logzio-linux-version-$AGENT_VERSION-metrics" \ No newline at end of file diff --git a/scripts/mac/consts.bash b/scripts/mac/consts.bash index 3e381a93b..178b54438 100755 --- a/scripts/mac/consts.bash +++ b/scripts/mac/consts.bash @@ -164,3 +164,9 @@ PURPLE_COLOR='\033[0;35m' WHITE_COLOR='\033[0;37m' RED_COLOR_BOLD='\033[1;31m' GREEN_COLOR_BOLD='\033[0;32m' + +## Headers +## Headers +AGENT_VERSION=$(cat "$LOGZIO_TEMP_DIR/version") +USER_AGENT_LOGS="logzio-mac-version-$AGENT_VERSION-logs" +USER_AGENT_METRICS="logzio-mac-version-$AGENT_VERSION-metrics" \ No newline at end of file diff --git a/scripts/windows/consts.ps1 b/scripts/windows/consts.ps1 index c782dad78..e72327c54 100755 --- a/scripts/windows/consts.ps1 +++ b/scripts/windows/consts.ps1 @@ -128,4 +128,9 @@ $script:LogScriptMetrics = 'metrics.ps1' $script:LogsScriptTraces = 'traces.ps1' $script:LogScriptPostrequisites = 'postrequisites.ps1' +## Headers +$script:AgentVersion = Get-Content "$env:TEMP\Logzio\version" +$script:UserAgentLogs = "logzio-windows-version-$script:AgentVersion-logs" +$script:UserAgentMetrics = "logzio-windows-version-$script:AgentVersion-metrics" + # Dynamic Consts (Will be added while the agent running)