Skip to content
5 changes: 3 additions & 2 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ where
let proxy_connector = build_proxy_connector(tls_settings.into(), proxy_config)?;
let client = client_builder.build(proxy_connector.clone());

let app_name = crate::get_app_name();
let version = crate::get_version();
let user_agent = HeaderValue::from_str(&format!("Vector/{}", version))
.expect("Invalid header value for version!");
let user_agent = HeaderValue::from_str(&format!("{}/{}", app_name, version))
.expect("Invalid header value for user-agent!");

Ok(HttpClient {
client,
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ pub use source_sender::SourceSender;
pub use vector_common::{shutdown, Error, Result};
pub use vector_core::{event, metrics, schema, tcp, tls};

/// The name used to identify this Vector application.
///
/// This can be set at compile-time through the VECTOR_APP_NAME env variable.
/// Defaults to "Vector".
pub fn get_app_name() -> &'static str {

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 can see this coming in handy in other places too in the future.

option_env!("VECTOR_APP_NAME").unwrap_or("Vector")
}

/// The current version of Vector in simplified format.
/// `<version-number>-nightly`.
pub fn vector_version() -> impl std::fmt::Display {
Expand Down
29 changes: 22 additions & 7 deletions src/sinks/datadog/logs/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct LogApiService {
client: HttpClient,
uri: Uri,
user_provided_headers: IndexMap<HeaderName, HeaderValue>,
default_headers: IndexMap<HeaderName, HeaderValue>,
}

impl LogApiService {
Expand All @@ -103,12 +104,26 @@ impl LogApiService {
uri: Uri,
headers: IndexMap<String, String>,
) -> crate::Result<Self> {
let headers = validate_headers(&headers)?;
let user_provided_headers = validate_headers(&headers)?;

// Note that these headers cannot be overriden by the user.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this documented?

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.

No. I'm not sure if we'd want to document this. The user should never want to modify these values unless for some nefarious reasons.

let default_headers = &[
(CONTENT_TYPE.to_string(), "application/json".to_string()),
(
"DD-EVP-ORIGIN".to_string(),
crate::get_app_name().to_lowercase().replace(' ', "_"),

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 know it's only used in one place at the moment, but I could definitely see this being used in other places in the future if we wanted to pull it up.

),
("DD-EVP-ORIGIN-VERSION".to_string(), crate::get_version()),
]
.into_iter()
.collect();
let default_headers = validate_headers(default_headers)?;

Ok(Self {
client,
uri,
user_provided_headers: headers,
user_provided_headers,
default_headers,
})
}
}
Expand All @@ -126,11 +141,8 @@ impl Service<LogApiRequest> for LogApiService {
// Emission of Error internal event is handled upstream by the caller
fn call(&mut self, mut request: LogApiRequest) -> Self::Future {
let mut client = self.client.clone();
let http_request = Request::post(&self.uri)
.header(CONTENT_TYPE, "application/json")
.header("DD-EVP-ORIGIN", "vector")
.header("DD-EVP-ORIGIN-VERSION", crate::get_version())
.header("DD-API-KEY", request.api_key.to_string());
let http_request =
Request::post(&self.uri).header("DD-API-KEY", request.api_key.to_string());

let http_request = if let Some(ce) = request.compression.content_encoding() {
http_request.header(CONTENT_ENCODING, ce)
Expand All @@ -149,6 +161,9 @@ impl Service<LogApiRequest> for LogApiService {
// Replace rather than append to any existing header values
headers.insert(name, value.clone());
}
for (name, value) in &self.default_headers {
headers.insert(name, value.clone());
}
}

let http_request = http_request
Expand Down