Skip to content

Commit 4e73b58

Browse files
committed
Move OTLP source code functions to common to allow Relay/Decoder to use
1 parent d47b4ee commit 4e73b58

File tree

13 files changed

+31
-38
lines changed

13 files changed

+31
-38
lines changed

lib/saluki-components/src/sources/otlp/attributes/mod.rs renamed to lib/saluki-components/src/common/otlp/attributes/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use otlp_protos::opentelemetry::proto::common::v1::{self as otlp_common, any_val
77
use saluki_common::collections::{FastHashMap, FastHashSet};
88
use saluki_context::{origin::RawOrigin, tags::TagSet};
99

10-
use crate::common::otlp::util::{extract_container_tags_from_resource_attributes, resource_to_source};
10+
use crate::common::otlp::util::extract_container_tags_from_resource_attributes;
1111

12-
pub mod source;
1312
pub mod translator;
1413

1514
static CORE_MAPPING: LazyLock<FastHashMap<&'static str, &'static str>> = LazyLock::new(|| {
@@ -122,7 +121,7 @@ static KUBERNETES_DD_TAGS: LazyLock<FastHashSet<&'static str>> = LazyLock::new(|
122121

123122
// HTTPMappings defines the mapping between OpenTelemetry semantic conventions
124123
// and Datadog Agent conventions for HTTP attributes.
125-
pub(crate) static HTTP_MAPPINGS: LazyLock<FastHashMap<&'static str, &'static str>> = LazyLock::new(|| {
124+
pub static HTTP_MAPPINGS: LazyLock<FastHashMap<&'static str, &'static str>> = LazyLock::new(|| {
126125
let mut m = FastHashMap::default();
127126
m.insert(CLIENT_ADDRESS, "http.client_ip");
128127
m.insert(HTTP_RESPONSE_BODY_SIZE, "http.response.content_length");
@@ -138,7 +137,7 @@ pub(crate) static HTTP_MAPPINGS: LazyLock<FastHashMap<&'static str, &'static str
138137
m
139138
});
140139

141-
pub(super) fn tags_from_attributes(attributes: &[otlp_common::KeyValue]) -> TagSet {
140+
pub fn tags_from_attributes(attributes: &[otlp_common::KeyValue]) -> TagSet {
142141
let mut tags = TagSet::default();
143142

144143
for kv in attributes {
@@ -266,7 +265,7 @@ fn try_get_int_from_value(value: Option<&otlp_common::any_value::Value>) -> Opti
266265
}
267266
}
268267

269-
pub(super) fn get_int_attribute<'a>(attributes: &'a [otlp_common::KeyValue], key: &str) -> Option<&'a i64> {
268+
pub fn get_int_attribute<'a>(attributes: &'a [otlp_common::KeyValue], key: &str) -> Option<&'a i64> {
270269
attributes.iter().find_map(|kv| {
271270
if kv.key == key {
272271
if let Some(Value::IntValue(i_val)) = kv.value.as_ref().and_then(|v| v.value.as_ref()) {

lib/saluki-components/src/sources/otlp/attributes/translator.rs renamed to lib/saluki-components/src/common/otlp/attributes/translator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use otlp_protos::opentelemetry::proto::common::v1 as otlp_common;
22
use saluki_context::tags::TagSet;
33

4-
use super::{origin_id_from_attributes, resource_to_source, tags_from_attributes};
5-
use crate::sources::otlp::attributes::source::Source;
4+
use super::{origin_id_from_attributes, tags_from_attributes};
5+
use crate::common::otlp::util::{resource_to_source, Source};
66

77
pub struct AttributeTranslator {}
88

lib/saluki-components/src/common/otlp/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
//!
33
//! Provides shared server setup code for both OTLP receiver (proxy mode) and OTLP source (translation mode).
44
5+
pub mod attributes;
56
pub mod config;
7+
pub mod origin;
8+
pub mod traces;
69
pub mod util;
710

811
use std::sync::Arc;

lib/saluki-components/src/sources/otlp/origin.rs renamed to lib/saluki-components/src/common/otlp/origin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use saluki_env::WorkloadProvider;
88
use tracing::trace;
99

1010
#[derive(Clone)]
11-
pub(super) struct OtlpOriginTagResolver {
11+
pub struct OtlpOriginTagResolver {
1212
workload_provider: Arc<dyn WorkloadProvider + Send + Sync>,
1313
}
1414

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! OTLP traces translation logic (shared between source and decoder)
2+
3+
pub mod normalize;
4+
pub mod transform;
5+
pub mod translator;

lib/saluki-components/src/sources/otlp/traces/normalize.rs renamed to lib/saluki-components/src/common/otlp/traces/normalize.rs

File renamed without changes.

lib/saluki-components/src/sources/otlp/traces/transform.rs renamed to lib/saluki-components/src/common/otlp/traces/transform.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ use serde_json::{Map as JsonMap, Value as JsonValue};
2020
use stringtheory::MetaString;
2121
use tracing::error;
2222

23+
use crate::common::otlp::attributes::{get_int_attribute, HTTP_MAPPINGS};
24+
use crate::common::otlp::traces::normalize::{normalize_service, normalize_tag_value};
25+
use crate::common::otlp::traces::normalize::{truncate_utf8, MAX_RESOURCE_LEN};
26+
use crate::common::otlp::traces::translator::{convert_span_id, convert_trace_id};
2327
use crate::common::otlp::util::get_string_attribute;
2428
use crate::common::otlp::util::{
2529
DEPLOYMENT_ENVIRONMENT_KEY, KEY_DATADOG_CONTAINER_ID, KEY_DATADOG_ENVIRONMENT, KEY_DATADOG_VERSION,
2630
};
27-
use crate::sources::otlp::attributes::{get_int_attribute, HTTP_MAPPINGS};
28-
use crate::sources::otlp::traces::normalize::{normalize_service, normalize_tag_value};
29-
use crate::sources::otlp::traces::normalize::{truncate_utf8, MAX_RESOURCE_LEN};
30-
use crate::sources::otlp::traces::translator::{convert_span_id, convert_trace_id};
3131

3232
pub(crate) const SAMPLING_PRIORITY_METRIC_KEY: &str = "_sampling_priority_v1";
3333
const EVENT_EXTRACTION_METRIC_KEY: &str = "_dd1.sr.eausr";

lib/saluki-components/src/sources/otlp/traces/translator.rs renamed to lib/saluki-components/src/common/otlp/traces/translator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use saluki_core::data_model::event::trace::{Span as DdSpan, Trace};
77
use saluki_core::data_model::event::Event;
88

99
use crate::common::otlp::config::TracesConfig;
10-
use crate::sources::otlp::traces::transform::otel_span_to_dd_span;
11-
use crate::sources::otlp::traces::transform::otlp_value_to_string;
12-
use crate::sources::otlp::Metrics;
10+
use crate::common::otlp::traces::transform::otel_span_to_dd_span;
11+
use crate::common::otlp::traces::transform::otlp_value_to_string;
12+
use crate::common::otlp::Metrics;
1313

1414
pub fn convert_trace_id(trace_id: &[u8]) -> u64 {
1515
if trace_id.len() < 8 {

lib/saluki-components/src/sources/otlp/attributes/source/mod.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

lib/saluki-components/src/sources/otlp/logs/translator.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ use saluki_context::tags::{SharedTagSet, Tag};
99
use saluki_core::data_model::event::Event;
1010
use stringtheory::MetaString;
1111

12-
use super::super::attributes::raw_origin_from_attributes;
13-
use crate::common::otlp::util::{get_string_attribute, resource_to_source};
14-
use crate::sources::otlp::attributes::source::SourceKind;
15-
use crate::sources::otlp::attributes::tags_from_attributes;
12+
use crate::common::otlp::attributes::raw_origin_from_attributes;
13+
use crate::common::otlp::attributes::tags_from_attributes;
14+
use crate::common::otlp::origin::OtlpOriginTagResolver;
15+
use crate::common::otlp::util::{get_string_attribute, resource_to_source, SourceKind};
1616
use crate::sources::otlp::logs::transform::transform_log_record;
17-
use crate::sources::otlp::origin::OtlpOriginTagResolver;
1817

1918
static OTEL_SOURCE_TAG: Tag = Tag::from_static("otel_source:datadog_agent");
2019

0 commit comments

Comments
 (0)