Skip to content

Commit 27c4e35

Browse files
remove x-p-log-source for otel ingestion, derive from endpoint (#1773)
1 parent 4144a3e commit 27c4e35

7 files changed

Lines changed: 28 additions & 29 deletions

File tree

‎scripts/ingest.ps1‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,7 @@ function Setup-Collector {
434434
" compression: none",
435435
" headers:",
436436
" X-API-Key: $apiKeyValue",
437-
" X-P-Stream: $streamNameValue",
438-
" X-P-Log-Source: otel-metrics"
437+
" X-P-Stream: $streamNameValue"
439438
)
440439

441440
if (-not [string]::IsNullOrWhiteSpace($TenantId)) {

‎scripts/ingest.sh‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ exporters:
409409
headers:
410410
X-API-Key: '$api_key_yaml'
411411
X-P-Stream: '$stream_name_yaml'
412-
X-P-Log-Source: otel-metrics
413412
${tenant_header}
414413
415414
service:

‎src/handlers/http/ingest.rs‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,11 @@ pub async fn ingest_internal_stream(
219219
Ok(())
220220
}
221221

222-
// Common validation and setup for OTEL ingestion
222+
// Common validation and setup for OTEL ingestion. The endpoint determines the log source, so
223+
// clients do not need to provide x-p-log-source.
223224
pub async fn setup_otel_stream(
224225
req: &HttpRequest,
225-
expected_log_source: LogSource,
226+
log_source: LogSource,
226227
known_fields: &[&str],
227228
telemetry_type: TelemetryType,
228229
dataset_tags: Vec<DatasetTag>,
@@ -232,18 +233,6 @@ pub async fn setup_otel_stream(
232233
return Err(PostError::Header(ParseHeaderError::MissingStreamName));
233234
};
234235

235-
let Some(log_source) = req.headers().get(LOG_SOURCE_KEY) else {
236-
return Err(PostError::Header(ParseHeaderError::MissingLogSource));
237-
};
238-
239-
let log_source = LogSource::from(log_source.to_str().unwrap());
240-
if log_source != expected_log_source {
241-
return Err(PostError::IncorrectLogSource(
242-
expected_log_source,
243-
telemetry_type.to_string(),
244-
));
245-
}
246-
247236
let stream_name = stream_name.to_str().unwrap().to_owned();
248237

249238
let log_source_entry = LogSourceEntry::new(
@@ -531,8 +520,6 @@ pub enum PostError {
531520
OtelNotSupported(String),
532521
#[error("The stream {0} is reserved for internal use and cannot be ingested into")]
533522
InternalStream(String),
534-
#[error(r#"Please use "x-p-log-source: {0}" for ingesting otel {1} data"#)]
535-
IncorrectLogSource(LogSource, String),
536523
#[error("Ingestion is not allowed in Query mode")]
537524
IngestionNotAllowed,
538525
#[error("Missing field for time partition in json: {0}")]
@@ -563,7 +550,6 @@ impl actix_web::ResponseError for PostError {
563550
| Header(_)
564551
| Invalid(_)
565552
| InternalStream(_)
566-
| IncorrectLogSource(_, _)
567553
| IngestionNotAllowed
568554
| MissingTimePartition(_)
569555
| KnownFormat(_)

‎src/handlers/http/modal/utils/ingest_utils.rs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub async fn process_otel_content(
8787
log_source: &LogSource,
8888
telemetry_type: TelemetryType,
8989
) -> Result<(), PostError> {
90-
let p_custom_fields = get_custom_fields_from_header(req);
90+
let p_custom_fields = get_otel_custom_fields_from_header(req, log_source);
9191
let content_type = req
9292
.headers()
9393
.get("Content-Type")
@@ -467,6 +467,15 @@ pub fn get_custom_fields_from_header(req: &HttpRequest) -> HashMap<String, Strin
467467
p_custom_fields
468468
}
469469

470+
pub fn get_otel_custom_fields_from_header(
471+
req: &HttpRequest,
472+
log_source: &LogSource,
473+
) -> HashMap<String, String> {
474+
let mut custom_fields = get_custom_fields_from_header(req);
475+
custom_fields.insert(FORMAT_KEY.to_string(), log_source.to_string());
476+
custom_fields
477+
}
478+
470479
fn verify_dataset_fields_count(
471480
stream_name: &str,
472481
tenant_id: &Option<String>,
@@ -583,6 +592,19 @@ mod tests {
583592
assert_eq!(custom_fields.get(FORMAT_KEY).unwrap(), "otel-logs");
584593
}
585594

595+
#[test]
596+
fn test_otel_custom_fields_use_endpoint_log_source() {
597+
let req = TestRequest::default().to_http_request();
598+
let custom_fields = get_otel_custom_fields_from_header(&req, &LogSource::OtelMetrics);
599+
assert_eq!(custom_fields.get(FORMAT_KEY).unwrap(), "otel-metrics");
600+
601+
let req = TestRequest::default()
602+
.insert_header((LOG_SOURCE_KEY, "otel-traces"))
603+
.to_http_request();
604+
let custom_fields = get_otel_custom_fields_from_header(&req, &LogSource::OtelMetrics);
605+
assert_eq!(custom_fields.get(FORMAT_KEY).unwrap(), "otel-metrics");
606+
}
607+
586608
#[test]
587609
fn test_get_custom_fields_empty_header_after_prefix() {
588610
let req = TestRequest::default()

‎src/otel_generator.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ async fn send_batch(endpoint: &str, auth: &str, tenant_id: Option<&str>, batch:
334334
send_signal(
335335
endpoint,
336336
"traces",
337-
"otel-traces",
338337
"otel-demo-traces",
339338
auth,
340339
tenant_id,
@@ -343,7 +342,6 @@ async fn send_batch(endpoint: &str, auth: &str, tenant_id: Option<&str>, batch:
343342
send_signal(
344343
endpoint,
345344
"metrics",
346-
"otel-metrics",
347345
"otel-demo-metrics",
348346
auth,
349347
tenant_id,
@@ -352,7 +350,6 @@ async fn send_batch(endpoint: &str, auth: &str, tenant_id: Option<&str>, batch:
352350
send_signal(
353351
endpoint,
354352
"logs",
355-
"otel-logs",
356353
"otel-demo-logs",
357354
auth,
358355
tenant_id,
@@ -370,7 +367,6 @@ async fn send_batch(endpoint: &str, auth: &str, tenant_id: Option<&str>, batch:
370367
async fn send_signal<T: Serialize + ?Sized>(
371368
endpoint: &str,
372369
signal: &str,
373-
log_source: &str,
374370
stream: &str,
375371
auth: &str,
376372
tenant_id: Option<&str>,
@@ -381,7 +377,6 @@ async fn send_signal<T: Serialize + ?Sized>(
381377
.post(format!("{endpoint}/v1/{signal}"))
382378
.header(AUTHORIZATION, auth)
383379
.header(CONTENT_TYPE, "application/json")
384-
.header("X-P-Log-Source", log_source)
385380
.header("X-P-Stream", stream)
386381
.body(body);
387382
if let Some(tenant_id) = tenant_id {

‎src/telemetry.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const OTEL_EXPORTER_OTLP_PROTOCOL: &str = "OTEL_EXPORTER_OTLP_PROTOCOL";
4848
/// Ignored when endpoint is \`stdout\`.
4949
/// - \`OTEL_EXPORTER_OTLP_HEADERS\` — comma-separated \`key=value\` pairs forwarded
5050
/// as gRPC metadata or HTTP headers, e.g.
51-
/// \`authorization=Basic <token>,x-p-stream=my-stream,x-p-log-source=otel-traces\`
51+
/// \`authorization=Basic <token>,x-p-stream=my-stream\`
5252
///
5353
/// Returns \`None\` when \`OTEL_EXPORTER_OTLP_ENDPOINT\` or `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` is not set (OTEL disabled).
5454
/// The caller must call \`provider.shutdown()\` before process exit.

‎src/utils/header_parsing.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ pub enum ParseHeaderError {
3333
SeperatorInValue(char),
3434
#[error("Stream name not found in header [x-p-stream]")]
3535
MissingStreamName,
36-
#[error("Log source not found in header [x-p-log-source]")]
37-
MissingLogSource,
3836
#[error("Tenant id not found in header [tenant]")]
3937
MissingTenantId,
4038
#[error("Invalid tenant id found in header [tenant]")]

0 commit comments

Comments
 (0)