Skip to content

Commit 1224750

Browse files
bobrikTheJokr
authored andcommitted
Cleanup tags when OTLP sink is used
* Remove `otel.status` if it's just "OK" as it is not really helpful. * Remove `otel.scope.name` as it just mirrors service name as a tag. * Replace `otel.scope.version` with a process level `service.version`, which is more a appropriate and a stable version.
1 parent 7b2c1c2 commit 1224750

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

foundations/src/telemetry/otlp_conversion/common.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,10 @@ use crate::ServiceInfo;
22
use opentelemetry_proto::tonic as otlp;
33
use std::time::{Duration, SystemTime, UNIX_EPOCH};
44

5-
pub(super) fn convert_service_info_to_instrumentation_scope(
6-
service_info: &ServiceInfo,
7-
) -> otlp::common::v1::InstrumentationScope {
8-
otlp::common::v1::InstrumentationScope {
9-
name: service_info.name.to_string(),
10-
version: service_info.version.to_string(),
11-
..Default::default()
12-
}
13-
}
14-
155
pub(super) fn convert_service_info_to_resource(
166
service_info: &ServiceInfo,
177
) -> otlp::resource::v1::Resource {
18-
let service_name_attr = otlp::common::v1::KeyValue {
8+
let service_name = otlp::common::v1::KeyValue {
199
key: "service.name".to_string(),
2010
value: Some(otlp::common::v1::AnyValue {
2111
value: Some(otlp::common::v1::any_value::Value::StringValue(
@@ -24,8 +14,17 @@ pub(super) fn convert_service_info_to_resource(
2414
}),
2515
};
2616

17+
let service_version = otlp::common::v1::KeyValue {
18+
key: "service.version".to_string(),
19+
value: Some(otlp::common::v1::AnyValue {
20+
value: Some(otlp::common::v1::any_value::Value::StringValue(
21+
service_info.version.to_string(),
22+
)),
23+
}),
24+
};
25+
2726
otlp::resource::v1::Resource {
28-
attributes: vec![service_name_attr],
27+
attributes: vec![service_name, service_version],
2928
dropped_attributes_count: 0,
3029
entity_refs: vec![],
3130
}

foundations/src/telemetry/otlp_conversion/tracing.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use super::common::{
2-
convert_service_info_to_instrumentation_scope, convert_service_info_to_resource, convert_time,
3-
};
1+
use super::common::{convert_service_info_to_resource, convert_time};
42
use crate::ServiceInfo;
53
use cf_rustracing::log::Log;
64
use cf_rustracing::span::SpanReference;
@@ -104,12 +102,19 @@ pub(crate) fn convert_span(
104102
let span_state = span.context().state();
105103
let (status_code, attributes) = convert_tags(&span);
106104

105+
let status = (status_code == otlp::trace::v1::status::StatusCode::Error).then(|| {
106+
otlp::trace::v1::Status {
107+
code: status_code.into(),
108+
message: Default::default(),
109+
}
110+
});
111+
107112
otlp::trace::v1::ResourceSpans {
108113
resource: Some(convert_service_info_to_resource(service_info)),
109114
schema_url: Default::default(),
110115
scope_spans: vec![otlp::trace::v1::ScopeSpans {
111116
schema_url: Default::default(),
112-
scope: Some(convert_service_info_to_instrumentation_scope(service_info)),
117+
scope: None,
113118
spans: vec![otlp::trace::v1::Span {
114119
trace_id: convert_trace_id(span_state),
115120
span_id: span_state.span_id().to_be_bytes().to_vec(),
@@ -126,10 +131,7 @@ pub(crate) fn convert_span(
126131
events: span.logs().iter().map(convert_log_entry).collect(),
127132
dropped_links_count: Default::default(),
128133
links: Default::default(),
129-
status: Some(otlp::trace::v1::Status {
130-
code: status_code.into(),
131-
message: Default::default(),
132-
}),
134+
status,
133135
}],
134136
}],
135137
}

0 commit comments

Comments
 (0)