File tree Expand file tree Collapse file tree 3 files changed +20
-30
lines changed Expand file tree Collapse file tree 3 files changed +20
-30
lines changed Original file line number Diff line number Diff line change 1+ use std:: fmt:: format;
2+
13use anyhow:: anyhow;
24use anyhow:: Result ;
35use opentelemetry:: trace:: TraceContextExt ;
6+ use opentelemetry_sdk:: error:: OTelSdkError ;
47use opentelemetry_sdk:: metrics:: exporter:: PushMetricExporter ;
58use opentelemetry_sdk:: trace:: SpanProcessor ;
69use spin_world:: wasi;
@@ -58,14 +61,23 @@ impl wasi::otel::tracing::Host for InstanceState {
5861}
5962
6063impl wasi:: otel:: metrics:: Host for InstanceState {
61- async fn collect (
64+ async fn export (
6265 & mut self ,
6366 metrics : wasi:: otel:: metrics:: ResourceMetrics ,
64- ) -> spin_core:: wasmtime:: Result < std:: result:: Result < ( ) , wasi:: otel:: metrics:: OtelError > > {
67+ ) -> spin_core:: wasmtime:: Result < std:: result:: Result < ( ) , wasi:: otel:: metrics:: Error > > {
6568 let mut rm: opentelemetry_sdk:: metrics:: data:: ResourceMetrics = metrics. into ( ) ;
6669 match self . metric_exporter . export ( & mut rm) . await {
6770 Ok ( _) => Ok ( Ok ( ( ) ) ) ,
68- Err ( e) => Ok ( Err ( e. into ( ) ) ) ,
71+ Err ( e) => match e {
72+ OTelSdkError :: AlreadyShutdown => {
73+ Ok ( Err ( "Shutdown has already been invoked" . to_string ( ) ) )
74+ }
75+ OTelSdkError :: InternalFailure ( e) => Ok ( Err ( "Internal failure: " . to_string ( ) + & e) ) ,
76+ OTelSdkError :: Timeout ( d) => Ok ( Err ( format ! (
77+ "Operation timed out after {} seconds" ,
78+ d. as_secs( )
79+ ) ) ) ,
80+ } ,
6981 }
7082 }
7183}
Original file line number Diff line number Diff line change @@ -557,7 +557,6 @@ mod llm {
557557mod otel {
558558 use super :: * ;
559559 use opentelemetry:: StringValue ;
560- use opentelemetry_sdk:: error:: OTelSdkError ;
561560 use opentelemetry_sdk:: trace:: { SpanEvents , SpanLinks } ;
562561 use std:: borrow:: Cow ;
563562 use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
@@ -566,18 +565,6 @@ mod otel {
566565 use wasi:: otel:: tracing as wasi_tracing;
567566 use wasi:: otel:: types as wasi_types;
568567
569- impl From < OTelSdkError > for wasi:: otel:: metrics:: OtelError {
570- fn from ( value : OTelSdkError ) -> Self {
571- match value {
572- OTelSdkError :: AlreadyShutdown => wasi:: otel:: metrics:: OtelError :: AlreadyShutdown ,
573- OTelSdkError :: InternalFailure ( v) => {
574- wasi:: otel:: metrics:: OtelError :: InternalFailure ( v)
575- }
576- OTelSdkError :: Timeout ( d) => wasi:: otel:: metrics:: OtelError :: Timeout ( d. as_secs ( ) ) ,
577- }
578- }
579- }
580-
581568 impl From < wasi_metrics:: ResourceMetrics > for opentelemetry_sdk:: metrics:: data:: ResourceMetrics {
582569 fn from ( value : wasi_metrics:: ResourceMetrics ) -> Self {
583570 Self {
Original file line number Diff line number Diff line change @@ -4,13 +4,13 @@ interface metrics {
44 use types . {key-value , instrumentation-scope };
55 use tracing . {span-id , trace-id };
66
7- /// `collect` gathers all metric data related to a Reader from the SDK
8- collect : func (metrics : resource-metrics ) -> result <_ , otel-error >;
7+ /// `export` sends all metric data related to a Reader from the SDK
8+ %export : func (metrics : resource-metrics ) -> result <_ , error >;
9+
10+ type error = string ;
911
1012 /// `resource-metrics` is a collection of `scope-metrics` and the associated `resource`
1113 /// that created them.
12- ///
13- /// See https://github.com/open-telemetry/opentelemetry-rust/blob/c811cde1ae21c624870c1b952190e687b16f76b8/opentelemetry-sdk/src/metrics/data/mod.rs#L13
1414 record resource-metrics {
1515 /// The entity that collected the metrics.
1616 %resource : %resource ,
@@ -255,13 +255,4 @@ interface metrics {
255255 %s64 (s64 ),
256256 %u64 (u64 ),
257257 }
258-
259- /// The WASI representation of the `OTelSdkError` .
260- ///
261- /// See https://github.com/open-telemetry/opentelemetry-rust/blob/353bbb0d80fc35a26a00b4f4fed0dcaed23e5523/opentelemetry-sdk/src/error.rs#L15
262- variant otel-error {
263- already-shutdown ,
264- timeout (duration ),
265- internal-failure (string ),
266- }
267- }
258+ }
You can’t perform that action at this time.
0 commit comments