diff --git a/internal/pkg/otel/translate/otelconfig.go b/internal/pkg/otel/translate/otelconfig.go index 4081e373fbc..3c67b0fa269 100644 --- a/internal/pkg/otel/translate/otelconfig.go +++ b/internal/pkg/otel/translate/otelconfig.go @@ -551,6 +551,15 @@ func getBeatsAuthExtensionConfig(outputCfg *config.C) (map[string]any, error) { return nil, err } + // proxy_url on newConfig is of type url.URL. Beatsauth extension expects it to be of string type instead + // this logic here converts url.URL to string type similar to what a user would set on filebeat config + if defaultTransportSettings.Proxy.URL != nil { + err = newConfig.SetString("proxy_url", -1, defaultTransportSettings.Proxy.URL.String()) + if err != nil { + return nil, fmt.Errorf("error settingg proxy url:%w ", err) + } + } + var newMap map[string]any err = newConfig.Unpack(&newMap) if err != nil { diff --git a/internal/pkg/otel/translate/otelconfig_test.go b/internal/pkg/otel/translate/otelconfig_test.go index 5ad1b411cd0..258ba3eda65 100644 --- a/internal/pkg/otel/translate/otelconfig_test.go +++ b/internal/pkg/otel/translate/otelconfig_test.go @@ -225,6 +225,7 @@ func TestGetOtelConfig(t *testing.T) { "preset": "balanced", "queue.mem.events": 3200, "ssl.enabled": true, + "proxy_url": "https://example.com", } for _, v := range extra { @@ -238,6 +239,7 @@ func TestGetOtelConfig(t *testing.T) { "continue_on_error": true, "idle_connection_timeout": "3s", "proxy_disable": false, + "proxy_url": "https://example.com", "ssl": map[string]interface{}{ "ca_sha256": []interface{}{}, "ca_trusted_fingerprint": "", diff --git a/internal/pkg/otel/translate/output_elasticsearch.go b/internal/pkg/otel/translate/output_elasticsearch.go index f3b6960431d..4b3c1df0020 100644 --- a/internal/pkg/otel/translate/output_elasticsearch.go +++ b/internal/pkg/otel/translate/output_elasticsearch.go @@ -8,6 +8,7 @@ import ( "encoding/base64" "errors" "fmt" + "net/url" "reflect" "strings" "time" @@ -20,6 +21,7 @@ import ( "github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue" "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" "github.com/elastic/elastic-agent-libs/transport/tlscommon" ) @@ -256,6 +258,12 @@ func cfgDecodeHookFunc() mapstructure.DecodeHookFunc { return nil, fmt.Errorf("failed parsing TLS verification mode: %w", err) } return verificationMode, nil + case t == reflect.TypeOf(httpcommon.ProxyURI(url.URL{})): + proxyURL := httpcommon.ProxyURI(url.URL{}) + if err := proxyURL.Unpack(data.(string)); err != nil { + return nil, fmt.Errorf("failed parsing proxy_url: %w", err) + } + return proxyURL, nil default: return data, nil }