Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion serverless/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use env_logger::{Builder, Env, Target};
use log::{error, info};
use std::sync::Arc;
use std::{env, sync::Arc};

use datadog_trace_mini_agent::{
config, env_verifier, mini_agent, stats_flusher, stats_processor, trace_flusher,
Expand All @@ -16,6 +16,9 @@ pub fn main() {

info!("Starting serverless trace mini agent");

let mini_agent_version = env!("CARGO_PKG_VERSION").to_string();
env::set_var("DD_MINI_AGENT_VERSION", mini_agent_version);

let env_verifier = Arc::new(env_verifier::ServerlessEnvVerifier::default());

let trace_flusher = Arc::new(trace_flusher::ServerlessTraceFlusher {});
Expand Down
6 changes: 4 additions & 2 deletions trace-mini-agent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[package]
name = "datadog-trace-mini-agent"
description = "A subset of the trace agent that is shipped alongside tracers in a few serverless use cases (Google Cloud Functions and Azure Functions)"
version = "0.5.0"
edition = "2021"
edition.workspace = true
version.workspace = true
rust-version.workspace = true
license.workspace = true
autobenches = false

[lib]
Expand Down
4 changes: 0 additions & 4 deletions trace-mini-agent/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub struct Config {
pub env_type: trace_utils::EnvironmentType,
pub function_name: Option<String>,
pub max_request_content_length: usize,
pub mini_agent_version: String,
pub obfuscation_config: obfuscation_config::ObfuscationConfig,
pub os: String,
/// how often to flush stats, in seconds
Expand Down Expand Up @@ -62,8 +61,6 @@ impl Config {
)
})?;

let mini_agent_version: String = env!("CARGO_PKG_VERSION").to_string();

Ok(Config {
function_name: Some(function_name),
env_type,
Expand All @@ -84,7 +81,6 @@ impl Config {
..Default::default()
},
obfuscation_config,
mini_agent_version,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions trace-mini-agent/src/env_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl ServerlessEnvVerifier {
gcp_region: Some(get_region_from_gcp_region_string(
gcp_metadata.instance.region,
)),
version: trace_utils::MiniAgentMetadata::default().version,
}
}
}
Expand Down Expand Up @@ -466,6 +467,7 @@ mod tests {
trace_utils::MiniAgentMetadata {
gcp_project_id: Some("unknown".to_string()),
gcp_region: Some("unknown".to_string()),
version: None
}
);
}
Expand Down
6 changes: 1 addition & 5 deletions trace-mini-agent/src/trace_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ impl TraceChunkProcessor for ChunkProcessor {
);
for span in chunk.spans.iter_mut() {
trace_utils::enrich_span_with_mini_agent_metadata(span, &self.mini_agent_metadata);
trace_utils::enrich_span_with_azure_metadata(
span,
self.config.mini_agent_version.as_str(),
);
trace_utils::enrich_span_with_azure_metadata(span);
obfuscate_span(span, &self.config.obfuscation_config);
}
}
Expand Down Expand Up @@ -174,7 +171,6 @@ mod tests {
env_type: trace_utils::EnvironmentType::CloudFunction,
os: "linux".to_string(),
obfuscation_config: ObfuscationConfig::new().unwrap(),
mini_agent_version: "0.1.0".to_string(),
}
}

Expand Down
23 changes: 20 additions & 3 deletions trace-utils/src/trace_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rmpv::decode::read_value;
use rmpv::{Integer, Value};
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::env;

pub use crate::send_data::send_data_result::SendDataResult;
pub use crate::send_data::SendData;
Expand Down Expand Up @@ -453,10 +454,21 @@ pub enum EnvironmentType {
LambdaFunction,
}

#[derive(Clone, Default, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MiniAgentMetadata {
pub gcp_project_id: Option<String>,
pub gcp_region: Option<String>,
pub version: Option<String>,
}

impl Default for MiniAgentMetadata {
fn default() -> Self {
MiniAgentMetadata {
gcp_project_id: Default::default(),
gcp_region: Default::default(),
version: env::var("DD_MINI_AGENT_VERSION").ok(),
}
}
}

pub fn enrich_span_with_mini_agent_metadata(
Expand All @@ -471,9 +483,15 @@ pub fn enrich_span_with_mini_agent_metadata(
span.meta
.insert("location".to_string(), gcp_region.to_string());
}
if let Some(mini_agent_version) = &mini_agent_metadata.version {
span.meta.insert(
"_dd.mini_agent_version".to_string(),

@duncanista duncanista Jul 25, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this tag been approved? I'm not sure if we should continue using the name mini_agent when this is trace agent.

I mention it because this will now be added to all spans, meaning that anything using this library, like Bottlecap, will result with this tracing agent tag included.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I jus read Azure Functions, Google Cloud Functions, and Azure Spring Apps.

But still, maybe we should switch to a better naming 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ideas for a better name? The packages are all named some variation of "mini agent" so at least it's consistent for now. And the tag will only be set when the environment variable DD_MINI_AGENT_VERSION is set, which should not be the case for Bottlecap.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to sort this out at a later point.

mini_agent_version.to_string(),
);
}
}

pub fn enrich_span_with_azure_metadata(span: &mut pb::Span, mini_agent_version: &str) {
pub fn enrich_span_with_azure_metadata(span: &mut pb::Span) {
if let Some(aas_metadata) = azure_app_services::get_function_metadata() {
let aas_tags = [
("aas.resource.id", aas_metadata.get_resource_id()),
Expand All @@ -486,7 +504,6 @@ pub fn enrich_span_with_azure_metadata(span: &mut pb::Span, mini_agent_version:
aas_metadata.get_instance_name(),
),
("aas.subscription.id", aas_metadata.get_subscription_id()),
("aas.environment.mini_agent_version", mini_agent_version),
("aas.environment.os", aas_metadata.get_operating_system()),
("aas.environment.runtime", aas_metadata.get_runtime()),
(
Expand Down