-
Notifications
You must be signed in to change notification settings - Fork 291
WASI OTel #3346
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
Open
asteurer
wants to merge
15
commits into
spinframework:main
Choose a base branch
from
asteurer:wasi-otel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
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.
Open
WASI OTel #3346
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
919fcac
feat(wasi-otel): A WASI OTel host component
calebschoepp 4428232
fix(wasi-otel): misc refactoring
asteurer 84f1bd4
Update crates/factor-otel/src/lib.rs
asteurer 9d88add
Update crates/factor-otel/src/lib.rs
asteurer 00d6ac9
fix: misc refactors
asteurer 3f38752
fix: misc refactors
asteurer 0332cb9
feat(wasi-otel): more refactoring
asteurer 0010ec6
feat(test): adding tests
asteurer e9017ea
removing unhelpful comments
asteurer bdbc5d4
fix: removing empty test
asteurer 355cee5
fix: removing empty test
asteurer 879f70a
fix: removing empty test
asteurer d69860d
fix: linting
asteurer 4fc11c4
fix: fixing tests
asteurer 91084bd
fix(wasi-otel): partial fixes to integration tests
asteurer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,25 @@ | ||
| [package] | ||
| name = "spin-factor-otel" | ||
| version = { workspace = true } | ||
| authors = { workspace = true } | ||
| edition = { workspace = true } | ||
|
|
||
| [dependencies] | ||
| anyhow = { workspace = true } | ||
| indexmap = "2.2.6" | ||
| opentelemetry = { workspace = true } | ||
| opentelemetry_sdk = { workspace = true } | ||
| opentelemetry-otlp = { workspace = true } | ||
| spin-core = { path = "../core" } | ||
| spin-factors = { path = "../factors" } | ||
| spin-resource-table = { path = "../table" } | ||
| spin-telemetry = { path = "../telemetry" } | ||
| wasi-otel = { path = "../wasi-otel" } | ||
| tracing = { workspace = true } | ||
| tracing-opentelemetry = { workspace = true } | ||
|
|
||
| [dev-dependencies] | ||
| toml = "0.5" | ||
|
|
||
| [lints] | ||
| workspace = true |
This file contains hidden or 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,88 @@ | ||
| use crate::InstanceState; | ||
| use anyhow::anyhow; | ||
| use anyhow::Result; | ||
| use opentelemetry::trace::TraceContextExt; | ||
| use opentelemetry_sdk::error::OTelSdkError; | ||
| use opentelemetry_sdk::metrics::exporter::PushMetricExporter; | ||
| use opentelemetry_sdk::trace::SpanProcessor; | ||
| use tracing_opentelemetry::OpenTelemetrySpanExt; | ||
| // TODO: This feels weird. I'm wondering if it can be fixed by wrangling the bindgen macro in `crates/wasi_otel/lib.rs`. | ||
| use wasi_otel::wasi; | ||
|
|
||
| impl wasi::otel::tracing::Host for InstanceState { | ||
| async fn on_start(&mut self, context: wasi::otel::tracing::SpanContext) -> Result<()> { | ||
| let mut state = self.state.write().unwrap(); | ||
|
|
||
| // Before we do anything make sure we track the original host span ID for reparenting | ||
| if state.original_host_span_id.is_none() { | ||
| state.original_host_span_id = Some( | ||
| tracing::Span::current() | ||
| .context() | ||
| .span() | ||
| .span_context() | ||
| .span_id(), | ||
| ); | ||
| } | ||
|
|
||
| // Track the guest spans context in our ordered map | ||
| let span_context: opentelemetry::trace::SpanContext = context.into(); | ||
| state | ||
| .guest_span_contexts | ||
| .insert(span_context.span_id(), span_context); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| async fn on_end(&mut self, span_data: wasi::otel::tracing::SpanData) -> Result<()> { | ||
| let mut state = self.state.write().unwrap(); | ||
|
|
||
| let span_context: opentelemetry::trace::SpanContext = span_data.span_context.clone().into(); | ||
| let span_id: opentelemetry::trace::SpanId = span_context.span_id(); | ||
|
|
||
| if state.guest_span_contexts.shift_remove(&span_id).is_none() { | ||
| Err(anyhow!("Trying to end a span that was not started"))?; | ||
| } | ||
|
|
||
| self.span_processor.on_end(span_data.into()); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| async fn outer_span_context(&mut self) -> Result<wasi::otel::tracing::SpanContext> { | ||
| Ok(tracing::Span::current() | ||
| .context() | ||
| .span() | ||
| .span_context() | ||
| .clone() | ||
| .into()) | ||
| } | ||
| } | ||
|
|
||
| impl wasi::otel::metrics::Host for InstanceState { | ||
| async fn export( | ||
| &mut self, | ||
| metrics: wasi::otel::metrics::ResourceMetrics, | ||
| ) -> spin_core::wasmtime::Result<std::result::Result<(), wasi::otel::metrics::Error>> { | ||
| let mut rm: opentelemetry_sdk::metrics::data::ResourceMetrics = metrics.into(); | ||
| match self.metric_exporter.export(&mut rm).await { | ||
| Ok(_) => Ok(Ok(())), | ||
| Err(e) => match e { | ||
| OTelSdkError::AlreadyShutdown => { | ||
| let msg = "Shutdown has already been invoked"; | ||
| tracing::error!(msg); | ||
| Ok(Err(msg.to_string())) | ||
| } | ||
| OTelSdkError::InternalFailure(e) => { | ||
| let detailed_msg = format!("Internal failure: {}", e); | ||
| tracing::error!(detailed_msg); | ||
| Ok(Err("Internal failure.".to_string())) | ||
| } | ||
| OTelSdkError::Timeout(d) => { | ||
| let detailed_msg = format!("Operation timed out after {} seconds", d.as_secs()); | ||
| tracing::error!(detailed_msg); | ||
| Ok(Err("Operation timed out.".to_string())) | ||
| } | ||
| }, | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.