@@ -114,28 +114,33 @@ func (si *signingRoundTripper) inferServiceAndRegion(r *http.Request) (service s
114
114
service = si .service
115
115
region = si .region
116
116
117
- h := r .Host
118
- if strings .HasPrefix (h , "aps-workspaces" ) {
119
- if service == "" {
120
- service = "aps"
121
- }
122
- rest := h [strings .Index (h , "." )+ 1 :]
123
- if region == "" {
124
- region = rest [0 :strings .Index (rest , "." )]
125
- }
126
- } else if strings .HasPrefix (h , "search-" ) {
127
- if service == "" {
128
- service = "es"
129
- }
130
- rest := h [strings .Index (h , "." )+ 1 :]
131
- if region == "" {
132
- region = rest [0 :strings .Index (rest , "." )]
133
- }
117
+ host := r .Host
118
+ switch {
119
+ case strings .HasPrefix (host , "aps-workspaces" ):
120
+ service , region = extractServiceAndRegion (service , region , host , "aps" )
121
+ case strings .HasPrefix (host , "search-" ):
122
+ service , region = extractServiceAndRegion (service , region , host , "es" )
123
+ case strings .HasPrefix (host , "logs" ):
124
+ service , region = extractServiceAndRegion (service , region , host , "logs" )
125
+ case strings .HasPrefix (host , "xray" ):
126
+ service , region = extractServiceAndRegion (service , region , host , "xray" )
134
127
}
135
128
136
129
if service == "" || region == "" {
137
130
si .logger .Warn ("Unable to infer region and/or service from the URL. Please provide values for region and/or service in the collector configuration." )
138
131
}
132
+
133
+ return service , region
134
+ }
135
+
136
+ func extractServiceAndRegion (service , region , host , defaultService string ) (string , string ) {
137
+ if service == "" {
138
+ service = defaultService
139
+ }
140
+ rest := host [strings .Index (host , "." )+ 1 :]
141
+ if region == "" {
142
+ region = rest [0 :strings .Index (rest , "." )]
143
+ }
139
144
return service , region
140
145
}
141
146
0 commit comments