-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: WASI Observe prototype #2485
Draft
calebschoepp
wants to merge
6
commits into
fermyon:main
Choose a base branch
from
calebschoepp:wasi-observe-prototype
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
186e3e3
feat(wasi-observe): A WIP WASI Observe host component
calebschoepp 6370291
Support setting attributes
calebschoepp bb9b0e7
Support sink mode in observe.wit
calebschoepp 4a5b89a
More progress along the exporter interface
calebschoepp a4ece30
Directly use exporter for sink rather than proxying through tracer
calebschoepp cdc22e2
Support processor
calebschoepp File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
name = "spin-observe" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
|
||
[dependencies] | ||
anyhow = "1.0" | ||
async-trait = "0.1" | ||
dotenvy = "0.15" | ||
once_cell = "1" | ||
spin-app = { path = "../app" } | ||
spin-core = { path = "../core" } | ||
spin-expressions = { path = "../expressions" } | ||
spin-world = { path = "../world" } | ||
spin-telemetry = { path = "../telemetry" } | ||
table = { path = "../table" } | ||
thiserror = "1" | ||
tokio = { version = "1", features = ["rt-multi-thread"] } | ||
vaultrs = "0.6.2" | ||
serde = "1.0.188" | ||
tracing = "0.1.40" | ||
tracing-opentelemetry = "0.23.0" | ||
pin-project-lite = "0.2" | ||
opentelemetry = { version = "0.22.0", features = [ "metrics", "trace"] } | ||
opentelemetry_sdk = { version = "0.22.1", features = ["rt-tokio"] } | ||
opentelemetry-otlp = { version = "0.15.0", default-features=false, features = ["http-proto", "trace", "http", "reqwest-client", "metrics", "grpc-tonic"] } | ||
futures-executor = "0.3" | ||
indexmap = "2.2.6" | ||
|
||
[dev-dependencies] | ||
toml = "0.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use anyhow::{Context, Result}; | ||
use pin_project_lite::pin_project; | ||
use std::{ | ||
future::Future, | ||
sync::{Arc, RwLock}, | ||
}; | ||
|
||
use spin_core::{Engine, Store}; | ||
|
||
use crate::{host_component::State, ObserveHostComponent}; | ||
|
||
pin_project! { | ||
struct Instrumented<F> { | ||
#[pin] | ||
inner: F, | ||
observe_context: ObserveContext, | ||
} | ||
|
||
impl<F> PinnedDrop for Instrumented<F> { | ||
fn drop(this: Pin<&mut Self>) { | ||
this.project().observe_context.drop_all(); | ||
} | ||
} | ||
} | ||
|
||
pub trait FutureExt: Future + Sized { | ||
/// Manage WASI Observe guest spans. | ||
fn manage_guest_spans( | ||
self, | ||
observe_context: ObserveContext, | ||
) -> Result<impl Future<Output = Self::Output>>; | ||
} | ||
|
||
impl<F: Future> FutureExt for F { | ||
fn manage_guest_spans( | ||
self, | ||
observe_context: ObserveContext, | ||
) -> Result<impl Future<Output = Self::Output>> { | ||
Ok(Instrumented { | ||
inner: self, | ||
observe_context, | ||
}) | ||
} | ||
} | ||
|
||
impl<F: Future> Future for Instrumented<F> { | ||
type Output = F::Output; | ||
|
||
/// Maintains the invariant that all active spans are entered before polling the inner future | ||
/// and exited otherwise. If we don't do this then the timing (among many other things) of the | ||
/// spans becomes wildly incorrect. | ||
fn poll( | ||
self: std::pin::Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
) -> std::task::Poll<Self::Output> { | ||
let this = self.project(); | ||
|
||
// Enter the active spans before entering the inner poll | ||
{ | ||
this.observe_context.state.write().unwrap().enter_all(); | ||
} | ||
|
||
let ret = this.inner.poll(cx); | ||
|
||
// Exit the active spans after exiting the inner poll | ||
{ | ||
this.observe_context.state.write().unwrap().exit_all(); | ||
} | ||
|
||
ret | ||
} | ||
} | ||
|
||
/// The context necessary for the observe host component to function. | ||
pub struct ObserveContext { | ||
state: Arc<RwLock<State>>, | ||
} | ||
|
||
impl ObserveContext { | ||
pub fn new<T>(store: &mut Store<T>, engine: &Engine<T>) -> Result<Self> { | ||
let handle = engine | ||
.find_host_component_handle::<Arc<ObserveHostComponent>>() | ||
.context("host component handle not found")?; | ||
let state = store | ||
.host_components_data() | ||
.get_or_insert(handle) | ||
.state | ||
.clone(); | ||
Ok(Self { state }) | ||
} | ||
|
||
fn drop_all(&self) { | ||
self.state.write().unwrap().close_from_back_to(0); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
manage_wasi_observe_spans
? At the call site it won't be obvious where this method comes from.