Skip to content

Commit

Permalink
resources map to jaeger process tags
Browse files Browse the repository at this point in the history
  • Loading branch information
danrusei committed Sep 8, 2020
1 parent a13a0fd commit fbbcb90
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions opentelemetry-jaeger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,23 @@ impl trace::SpanExporter for Exporter {
fn export(&self, batch: Vec<Arc<trace::SpanData>>) -> trace::ExportResult {
match self.uploader.lock() {
Ok(mut uploader) => {
let jaeger_spans = batch.into_iter().map(Into::into).collect();
uploader.upload(jaeger::Batch::new(self.process.clone(), jaeger_spans))
let mut jaeger_spans: Vec<jaeger::Span> = Vec::new();
let mut process_tags: Vec<jaeger::Tag> = Vec::new();

for span in batch.iter() {
jaeger_spans.push(span.into());
process_tags.extend(build_process_tags(span));
}
let mut process = self.process.clone();
let tags: Vec<jaeger::Tag> = match process.tags {
Some(mut item) => {
item.extend(process_tags);
item
}
None => process_tags,
};
process.tags = Some(tags);
uploader.upload(jaeger::Batch::new(process, jaeger_spans))
}
Err(_) => trace::ExportResult::FailedNotRetryable,
}
Expand Down Expand Up @@ -431,7 +446,7 @@ impl Into<jaeger::Log> for api::Event {
}
}

impl Into<jaeger::Span> for Arc<trace::SpanData> {
impl Into<jaeger::Span> for &Arc<trace::SpanData> {
/// Convert spans to jaeger thrift span for exporting.
fn into(self) -> jaeger::Span {
let trace_id = self.span_context.trace_id().to_u128();
Expand All @@ -455,7 +470,7 @@ impl Into<jaeger::Span> for Arc<trace::SpanData> {
.duration_since(self.start_time)
.unwrap_or_else(|_| Duration::from_secs(0))
.as_micros() as i64,
tags: build_tags(&self),
tags: build_span_tags(&self),
logs: events_to_logs(&self.message_events),
}
}
Expand Down Expand Up @@ -487,7 +502,16 @@ fn links_to_references(links: &sdk::EvictedQueue<api::Link>) -> Option<Vec<jaege
}
}

fn build_tags(span_data: &Arc<trace::SpanData>) -> Option<Vec<jaeger::Tag>> {
fn build_process_tags(span_data: &Arc<trace::SpanData>) -> Vec<jaeger::Tag> {
let tags = span_data
.resource
.iter()
.map(|(k, v)| api::KeyValue::new(k.clone(), v.clone()).into())
.collect::<Vec<_>>();
tags
}

fn build_span_tags(span_data: &Arc<trace::SpanData>) -> Option<Vec<jaeger::Tag>> {
let mut user_overrides = UserOverrides::default();
// TODO determine if namespacing is required to avoid collisions with set attributes
let mut tags = span_data
Expand All @@ -497,12 +521,6 @@ fn build_tags(span_data: &Arc<trace::SpanData>) -> Option<Vec<jaeger::Tag>> {
user_overrides.record_attr(k.as_str());
api::KeyValue::new(k.clone(), v.clone()).into()
})
.chain(
span_data
.resource
.iter()
.map(|(k, v)| api::KeyValue::new(k.clone(), v.clone()).into()),
)
.collect::<Vec<_>>();

// Ensure error status is set
Expand Down

0 comments on commit fbbcb90

Please sign in to comment.