Skip to content

Commit 45bdfe6

Browse files
committed
Namespacing and wit update
Signed-off-by: Caleb Schoepp <[email protected]>
1 parent c9b29b0 commit 45bdfe6

File tree

4 files changed

+46
-43
lines changed

4 files changed

+46
-43
lines changed

crates/factor-observe/src/host.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,22 @@ use opentelemetry::trace::Tracer;
99
use opentelemetry::Context;
1010
use spin_core::async_trait;
1111
use spin_core::wasmtime::component::Resource;
12-
use spin_world::wasi::observe::traces::Datetime;
13-
use spin_world::wasi::observe::traces::{self, KeyValue, Span as WitSpan};
12+
use spin_world::wasi::observe::traces;
1413
use tracing_opentelemetry::OpenTelemetrySpanExt;
1514

1615
use crate::{GuestSpan, InstanceState};
1716

1817
#[async_trait]
1918
impl traces::Host for InstanceState {}
2019

21-
// TODO: Figure out a standard import scheme for my wit types vs otel types
22-
2320
#[async_trait]
2421
impl traces::HostSpan for InstanceState {
2522
// TODO(Caleb): Make this implicit logic make more sense (the indexmap seems wrong)
2623
async fn start(
2724
&mut self,
2825
name: String,
29-
_parent: traces::SpanParent,
3026
_options: Option<traces::StartOptions>,
31-
) -> Result<Resource<WitSpan>> {
27+
) -> Result<Resource<traces::Span>> {
3228
let mut state = self.state.write().unwrap();
3329

3430
if state.active_spans.is_empty() {
@@ -70,11 +66,14 @@ impl traces::HostSpan for InstanceState {
7066
Ok(Resource::new_own(resource_id))
7167
}
7268

73-
async fn span_context(&mut self, _resource: Resource<WitSpan>) -> Result<traces::SpanContext> {
69+
async fn span_context(
70+
&mut self,
71+
_resource: Resource<traces::Span>,
72+
) -> Result<traces::SpanContext> {
7473
todo!()
7574
}
7675

77-
async fn is_recording(&mut self, resource: Resource<WitSpan>) -> Result<bool> {
76+
async fn is_recording(&mut self, resource: Resource<traces::Span>) -> Result<bool> {
7877
if let Some(guest_span) = self.state.read().unwrap().guest_spans.get(resource.rep()) {
7978
Ok(guest_span.inner.is_recording())
8079
} else {
@@ -85,8 +84,8 @@ impl traces::HostSpan for InstanceState {
8584

8685
async fn set_attributes(
8786
&mut self,
88-
resource: Resource<WitSpan>,
89-
attributes: Vec<KeyValue>,
87+
resource: Resource<traces::Span>,
88+
attributes: Vec<traces::KeyValue>,
9089
) -> Result<()> {
9190
if let Some(guest_span) = self
9291
.state
@@ -106,10 +105,10 @@ impl traces::HostSpan for InstanceState {
106105

107106
async fn add_event(
108107
&mut self,
109-
resource: Resource<WitSpan>,
108+
resource: Resource<traces::Span>,
110109
name: String,
111-
timestamp: Option<Datetime>,
112-
attributes: Option<Vec<KeyValue>>,
110+
timestamp: Option<traces::Datetime>,
111+
attributes: Option<Vec<traces::KeyValue>>,
113112
) -> Result<()> {
114113
if let Some(guest_span) = self
115114
.state
@@ -141,19 +140,23 @@ impl traces::HostSpan for InstanceState {
141140
Ok(())
142141
}
143142

144-
async fn add_link(&mut self, _resource: Resource<WitSpan>, _link: traces::Link) -> Result<()> {
143+
async fn add_link(
144+
&mut self,
145+
_resource: Resource<traces::Span>,
146+
_link: traces::Link,
147+
) -> Result<()> {
145148
todo!()
146149
}
147150

148151
async fn set_status(
149152
&mut self,
150-
_resource: Resource<WitSpan>,
153+
_resource: Resource<traces::Span>,
151154
_status: traces::Status,
152155
) -> Result<()> {
153156
todo!()
154157
}
155158

156-
async fn update_name(&mut self, resource: Resource<WitSpan>, name: String) -> Result<()> {
159+
async fn update_name(&mut self, resource: Resource<traces::Span>, name: String) -> Result<()> {
157160
if let Some(guest_span) = self
158161
.state
159162
.write()
@@ -170,8 +173,8 @@ impl traces::HostSpan for InstanceState {
170173

171174
async fn end(
172175
&mut self,
173-
resource: Resource<WitSpan>,
174-
_timestamp: Option<Datetime>,
176+
resource: Resource<traces::Span>,
177+
_timestamp: Option<traces::Datetime>,
175178
) -> Result<()> {
176179
if let Some(guest_span) = self
177180
.state
@@ -187,7 +190,7 @@ impl traces::HostSpan for InstanceState {
187190
Ok(())
188191
}
189192

190-
fn drop(&mut self, _resource: Resource<WitSpan>) -> Result<()> {
193+
fn drop(&mut self, _resource: Resource<traces::Span>) -> Result<()> {
191194
// TODO(Caleb): What do we want the dropping behavior to be?
192195
// TODO(Caleb): How is the drop semantics test passing?
193196
Ok(())

crates/world/src/conversions.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -220,34 +220,32 @@ mod llm {
220220
}
221221

222222
mod observe {
223-
use opentelemetry::StringValue;
224-
225223
use super::*;
224+
use opentelemetry::StringValue;
225+
use wasi::observe::traces;
226226

227-
impl From<wasi::observe::traces::Value> for opentelemetry::Value {
228-
fn from(value: wasi::observe::traces::Value) -> Self {
227+
impl From<traces::Value> for opentelemetry::Value {
228+
fn from(value: traces::Value) -> Self {
229229
match value {
230-
wasi::observe::traces::Value::String(v) => v.into(),
231-
wasi::observe::traces::Value::Bool(v) => v.into(),
232-
wasi::observe::traces::Value::Float64(v) => v.into(),
233-
wasi::observe::traces::Value::S64(v) => v.into(),
234-
wasi::observe::traces::Value::StringArray(v) => opentelemetry::Value::Array(
230+
traces::Value::String(v) => v.into(),
231+
traces::Value::Bool(v) => v.into(),
232+
traces::Value::Float64(v) => v.into(),
233+
traces::Value::S64(v) => v.into(),
234+
traces::Value::StringArray(v) => opentelemetry::Value::Array(
235235
v.into_iter()
236236
.map(StringValue::from)
237237
.collect::<Vec<_>>()
238238
.into(),
239239
),
240-
wasi::observe::traces::Value::BoolArray(v) => opentelemetry::Value::Array(v.into()),
241-
wasi::observe::traces::Value::Float64Array(v) => {
242-
opentelemetry::Value::Array(v.into())
243-
}
244-
wasi::observe::traces::Value::S64Array(v) => opentelemetry::Value::Array(v.into()),
240+
traces::Value::BoolArray(v) => opentelemetry::Value::Array(v.into()),
241+
traces::Value::Float64Array(v) => opentelemetry::Value::Array(v.into()),
242+
traces::Value::S64Array(v) => opentelemetry::Value::Array(v.into()),
245243
}
246244
}
247245
}
248246

249-
impl From<wasi::observe::traces::KeyValue> for opentelemetry::KeyValue {
250-
fn from(kv: wasi::observe::traces::KeyValue) -> Self {
247+
impl From<traces::KeyValue> for opentelemetry::KeyValue {
248+
fn from(kv: traces::KeyValue) -> Self {
251249
opentelemetry::KeyValue::new(kv.key, kv.value)
252250
}
253251
}

tests/test-components/components/wasi-observe-tracing/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ fn handle(req: http::Request<()>) -> Response {
2525
}
2626

2727
fn nested_spans(_req: Request, _params: Params) -> Response {
28-
let span = Span::start("outer_func", &SpanParent::Implicit, None);
28+
let span = Span::start("outer_func", None);
2929
inner_func();
3030
span.end(None);
3131
Response::new(200, "")
3232
}
3333

3434
fn inner_func() {
35-
let span = Span::start("inner_func", &SpanParent::Implicit, None);
35+
let span = Span::start("inner_func", None);
3636
span.end(None);
3737
}
3838

3939
fn drop_semantics(_req: Request, _params: Params) -> Response {
40-
let _span = Span::start("drop_semantics", &SpanParent::Implicit, None);
40+
let _span = Span::start("drop_semantics", None);
4141
Response::new(200, "")
4242
// _span will drop here and should be ended
4343
}
4444

4545
fn setting_attributes(_req: Request, _params: Params) -> Response {
46-
let span = Span::start("setting_attributes", &SpanParent::Implicit, None);
46+
let span = Span::start("setting_attributes", None);
4747
span.set_attributes(&[KeyValue {
4848
key: "foo".to_string(),
4949
value: Value::String("bar".to_string()),
@@ -63,7 +63,7 @@ fn setting_attributes(_req: Request, _params: Params) -> Response {
6363
}
6464

6565
async fn host_guest_host(_req: Request, _params: Params) -> Response {
66-
let span = Span::start("guest", &SpanParent::Implicit, None);
66+
let span = Span::start("guest", None);
6767

6868
let req = Request::builder()
6969
.method(Method::Get)
@@ -76,7 +76,7 @@ async fn host_guest_host(_req: Request, _params: Params) -> Response {
7676
}
7777

7878
fn events(_req: Request, _params: Params) -> Response {
79-
let span = Span::start("events", &SpanParent::Implicit, None);
79+
let span = Span::start("events", None);
8080
span.add_event("basic-event", None, None);
8181
span.add_event(
8282
"event-with-attributes",

wit/deps/observe/traces.wit

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ interface traces {
33

44
/// Represents a unit of work or operation.
55
resource span {
6-
/// Starts a new span with the given name, parent, and options.
7-
start: static func(name: string, parent: span-parent, options: option<start-options>) -> span;
6+
/// Starts a new span with the given name and options.
7+
start: static func(name: string, options: option<start-options>) -> span;
88

99
/// Get the `span-context` for this `span`.
1010
span-context: func() -> span-context;
@@ -39,6 +39,8 @@ interface traces {
3939

4040
/// Configuration for starting a `span`.
4141
record start-options {
42+
/// Parent for the new `span`. If this is not defined it defaults to implicit.
43+
parent: option<span-parent>,
4244
/// `span-kind` for the new `span`.
4345
span-kind: option<span-kind>,
4446
/// Attributes for the new `span`.

0 commit comments

Comments
 (0)