Skip to content

Commit

Permalink
adds azure app service tags to serverless mini agent traces for azure…
Browse files Browse the repository at this point in the history
… functions
  • Loading branch information
duncanpharvey committed May 29, 2024
1 parent de8d3b6 commit 62433bc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
38 changes: 27 additions & 11 deletions ddcommon/src/azure_app_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,7 @@ impl AzureMetadata {
}
}

pub fn new<T: QueryEnv>(query: T) -> Option<Self> {
let is_relevant = query
.get_var(SERVICE_CONTEXT)
.map(|s| s.to_bool())
.unwrap_or(false);

if !is_relevant {
return None;
}

fn build_metadata<T: QueryEnv>(query: T) -> Option<Self> {
let subscription_id =
AzureMetadata::extract_subscription_id(query.get_var(WEBSITE_ONWER_NAME));
let site_name = query.get_var(WEBSITE_SITE_NAME);
Expand All @@ -141,7 +132,7 @@ impl AzureMetadata {
let instance_name = query.get_var(INSTANCE_NAME);
let instance_id = query.get_var(INSTANCE_ID);

Some(AzureMetadata {
return Some(AzureMetadata {
resource_id,
subscription_id,
site_name,
Expand All @@ -155,6 +146,24 @@ impl AzureMetadata {
})
}


pub fn new<T: QueryEnv>(query: T) -> Option<Self> {
let is_relevant = query
.get_var(SERVICE_CONTEXT)
.map(|s| s.to_bool())
.unwrap_or(false);

if !is_relevant {
return None;
}

return AzureMetadata::build_metadata(query);
}

pub fn new_function<T: QueryEnv>(query: T) -> Option<Self> {
return AzureMetadata::build_metadata(query);
}

pub fn get_resource_id(&self) -> &str {
get_value_or_unknown!(self.resource_id)
}
Expand Down Expand Up @@ -203,6 +212,13 @@ pub fn get_metadata() -> &'static Option<AzureMetadata> {
&AAS_METATDATA
}

pub fn get_function_metadata() -> &'static Option<AzureMetadata> {
lazy_static! {
static ref AAS_METATDATA: Option<AzureMetadata> = AzureMetadata::new_function(RealEnv {});
}
&AAS_METATDATA
}

#[cfg(test)]
mod tests {

Expand Down
31 changes: 31 additions & 0 deletions trace-mini-agent/src/trace_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use datadog_trace_obfuscation::obfuscate::obfuscate_span;
use datadog_trace_utils::trace_utils;
use datadog_trace_utils::trace_utils::SendData;

use ddcommon::azure_app_services;

use crate::{
config::Config,
http_utils::{self, log_and_create_http_response},
Expand Down Expand Up @@ -78,6 +80,35 @@ impl TraceProcessor for ServerlessTraceProcessor {
);
for span in chunk.spans.iter_mut() {
trace_utils::enrich_span_with_mini_agent_metadata(span, &mini_agent_metadata);
match azure_app_services::get_function_metadata() {
Some(aas_metadata) => {
let aas_tags = [
("aas.resource.id", aas_metadata.get_resource_id()),
(
"aas.environment.extension_version",
aas_metadata.get_extension_version(),
),
(
"aas.environment.instance_id",
aas_metadata.get_instance_id(),
),
(
"aas.environment.instance_name",
aas_metadata.get_instance_name(),
),
("aas.environment.os", aas_metadata.get_operating_system()),
("aas.resource.group", aas_metadata.get_resource_group()),
("aas.site.name", aas_metadata.get_site_name()),
("aas.site.kind", aas_metadata.get_site_kind()),
("aas.site.type", aas_metadata.get_site_type()),
("aas.subscription.id", aas_metadata.get_subscription_id()),
];
aas_tags.into_iter().for_each(|(name, value)| {
span.meta.insert(name.to_string(), value.to_string());
});
}
None => (),
}
obfuscate_span(span, &config.obfuscation_config);
}
},
Expand Down

0 comments on commit 62433bc

Please sign in to comment.