Skip to content

Commit d4e30c4

Browse files
committed
A bit of cleanup
Signed-off-by: Caleb Schoepp <caleb.schoepp@fermyon.com>
1 parent 40be93f commit d4e30c4

File tree

1 file changed

+7
-56
lines changed

1 file changed

+7
-56
lines changed

crates/factor-otel/src/host.rs

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
// use std::time::SystemTime;
2-
31
use anyhow::anyhow;
42
use anyhow::Result;
53
use opentelemetry::trace::TraceContextExt;
6-
use opentelemetry::Context;
74
use opentelemetry_sdk::trace::SpanProcessor;
85
use spin_world::wasi::otel::tracing as wasi_otel;
9-
use spin_world::wasi::otel::tracing::SpanContext;
10-
use tracing::span;
116

127
use tracing_opentelemetry::OpenTelemetrySpanExt;
138

@@ -21,7 +16,7 @@ impl wasi_otel::Host for InstanceState {
2116
) -> Result<()> {
2217
let mut state = self.state.write().unwrap();
2318

24-
// Before we ever create any new spans make sure we track the original host span ID
19+
// Before we do anything make sure we track the original host span ID for reparenting
2520
if state.original_host_span_id.is_none() {
2621
state.original_host_span_id = Some(
2722
tracing::Span::current()
@@ -32,48 +27,8 @@ impl wasi_otel::Host for InstanceState {
3227
);
3328
}
3429

35-
// // Get span's parent based on whether it's a new root and whether there are any active spans
36-
// let parent_context = match (false, state.active_spans.is_empty()) {
37-
// // Not a new root && Active spans -> Last active guest span is parent
38-
// (false, false) => {
39-
// let span_context = state
40-
// .guest_spans
41-
// .get(*state.active_spans.last().unwrap())
42-
// .unwrap()
43-
// .inner
44-
// .span_context()
45-
// .clone();
46-
// Context::new().with_remote_span_context(span_context)
47-
// }
48-
// // Not a new root && No active spans -> Current host span is parent
49-
// (false, true) => tracing::Span::current().context(),
50-
// // New root && n/a -> No parent
51-
// (true, _) => Context::new(),
52-
// };
53-
54-
// Create the underlying opentelemetry span
55-
// let builder = self.tracer.span_builder(span_data.name);
56-
// if let Some(kind) = options.span_kind {
57-
// builder = builder.with_kind(kind.into());
58-
// }
59-
// if let Some(attributes) = options.attributes {
60-
// builder = builder.with_attributes(attributes.into_iter().map(Into::into));
61-
// }
62-
// if let Some(links) = options.links {
63-
// builder = builder.with_links(links.into_iter().map(Into::into).collect());
64-
// }
65-
// if let Some(timestamp) = options.timestamp {
66-
// builder = builder.with_start_time(timestamp);
67-
// }
68-
// let otel_span = builder.start_with_context(
69-
// &self.tracer,
70-
// &Context::new().with_remote_span_context(parent.into()),
71-
// );
72-
// let span_id = otel_span.span_context().span_id();
73-
74-
// Put the span in our map and push it on to our stack of active spans
75-
let span_context =
76-
std::convert::Into::<opentelemetry::trace::SpanContext>::into(span_data.span_context);
30+
// Put the span in our map and push it on to our stack of active spans TODO: Fix comment
31+
let span_context: opentelemetry::trace::SpanContext = span_data.span_context.into();
7732
let span_id = span_context.span_id();
7833
state.guest_span_contexts.insert(span_id, span_context);
7934
state.active_spans.insert(span_id);
@@ -84,15 +39,12 @@ impl wasi_otel::Host for InstanceState {
8439
async fn on_end(&mut self, span_data: wasi_otel::SpanData) -> Result<()> {
8540
let mut state = self.state.write().unwrap();
8641

87-
let span_id = std::convert::Into::<opentelemetry::trace::SpanContext>::into(
88-
span_data.span_context.clone(),
89-
)
90-
.span_id();
42+
let span_context: opentelemetry::trace::SpanContext = span_data.span_context.clone().into();
43+
let span_id: opentelemetry::trace::SpanId = span_context.span_id();
44+
9145
self.processor.on_end(span_data.into());
92-
if let Some(_guest_span) = state.guest_span_contexts.get_mut(&span_id) {
93-
// // TODO: Transfer all the data
94-
// guest_span.end_with_timestamp(span_data.end_time.into());
9546

47+
if let Some(_guest_span) = state.guest_span_contexts.get_mut(&span_id) {
9648
// Remove the span from active_spans
9749
state.active_spans.shift_remove(&span_id);
9850

@@ -101,7 +53,6 @@ impl wasi_otel::Host for InstanceState {
10153
// TODO: This seems to be wrong
10254
Err(anyhow!("BUG: cannot find resource in table"))
10355
}
104-
// Ok(())
10556
}
10657

10758
async fn current_span_context(&mut self) -> Result<wasi_otel::SpanContext> {

0 commit comments

Comments
 (0)