Skip to content

Commit 573aa54

Browse files
authored
RUST-1501 Update faas metadata collection (#857)
1 parent f80171e commit 573aa54

File tree

1 file changed

+20
-18
lines changed
  • src/cmap/establish/handshake

1 file changed

+20
-18
lines changed

src/cmap/establish/handshake/mod.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,9 @@ impl FaasEnvironment {
205205
}
206206
}
207207
FaasEnvironmentName::Vercel => {
208-
let url = env::var("VERCEL_URL").ok();
209208
let region = env::var("VERCEL_REGION").ok();
210209
Self {
211210
name,
212-
url,
213211
region,
214212
..Self::UNSET
215213
}
@@ -225,24 +223,28 @@ fn var_set(name: &str) -> bool {
225223
impl FaasEnvironmentName {
226224
fn new() -> Option<Self> {
227225
use FaasEnvironmentName::*;
228-
let mut found = vec![];
226+
let mut found: Option<Self> = None;
229227
if var_set("AWS_EXECUTION_ENV") || var_set("AWS_LAMBDA_RUNTIME_API") {
230-
found.push(AwsLambda);
228+
found = Some(AwsLambda);
231229
}
230+
if var_set("VERCEL") {
231+
// Vercel takes precedence over AwsLambda.
232+
found = Some(Vercel);
233+
}
234+
// Any other conflict is treated as unset.
232235
if var_set("FUNCTIONS_WORKER_RUNTIME") {
233-
found.push(AzureFunc);
236+
match found {
237+
None => found = Some(AzureFunc),
238+
_ => return None,
239+
}
234240
}
235241
if var_set("K_SERVICE") || var_set("FUNCTION_NAME") {
236-
found.push(GcpFunc);
237-
}
238-
if var_set("VERCEL") {
239-
found.push(Vercel);
240-
}
241-
if found.len() != 1 {
242-
None
243-
} else {
244-
Some(found[0])
242+
match found {
243+
None => found = Some(GcpFunc),
244+
_ => return None,
245+
}
245246
}
247+
found
246248
}
247249

248250
fn name(&self) -> &'static str {
@@ -282,10 +284,6 @@ lazy_static! {
282284
type Truncation = fn(&mut ClientMetadata);
283285

284286
const METADATA_TRUNCATIONS: &[Truncation] = &[
285-
// truncate `platform`
286-
|metadata| {
287-
metadata.platform = rustc_version_runtime::version_meta().short_version_string;
288-
},
289287
// clear `env.*` except `name`
290288
|metadata| {
291289
if let Some(env) = &mut metadata.env {
@@ -308,6 +306,10 @@ const METADATA_TRUNCATIONS: &[Truncation] = &[
308306
|metadata| {
309307
metadata.env = None;
310308
},
309+
// truncate `platform`
310+
|metadata| {
311+
metadata.platform = rustc_version_runtime::version_meta().short_version_string;
312+
},
311313
];
312314

313315
/// Contains the logic needed to handshake a connection.

0 commit comments

Comments
 (0)