1
- use std:: time:: Duration ;
2
1
use std:: time:: SystemTime ;
3
- use std:: time:: UNIX_EPOCH ;
4
2
5
3
use anyhow:: anyhow;
6
4
use anyhow:: Result ;
@@ -21,6 +19,7 @@ impl traces::Host for InstanceState {}
21
19
#[ async_trait]
22
20
impl traces:: HostSpan for InstanceState {
23
21
// TODO(Caleb): Make this implicit logic make more sense (the indexmap seems wrong)
22
+ // TODO(Caleb): Properly implement this
24
23
async fn start (
25
24
& mut self ,
26
25
name : String ,
@@ -122,9 +121,7 @@ impl traces::HostSpan for InstanceState {
122
121
. get_mut ( resource. rep ( ) )
123
122
{
124
123
let timestamp = if let Some ( timestamp) = timestamp {
125
- UNIX_EPOCH
126
- + Duration :: from_secs ( timestamp. seconds )
127
- + Duration :: from_nanos ( timestamp. nanoseconds as u64 )
124
+ timestamp. into ( )
128
125
} else {
129
126
SystemTime :: now ( )
130
127
} ;
@@ -148,16 +145,21 @@ impl traces::HostSpan for InstanceState {
148
145
async fn add_link (
149
146
& mut self ,
150
147
resource : Resource < traces:: Span > ,
151
- _link : traces:: Link ,
148
+ link : traces:: Link ,
152
149
) -> Result < ( ) > {
153
- if let Some ( _guest_span ) = self
150
+ if let Some ( guest_span ) = self
154
151
. state
155
152
. write ( )
156
153
. unwrap ( )
157
154
. guest_spans
158
155
. get_mut ( resource. rep ( ) )
159
156
{
160
- todo ! ( "update otel versions -> guest_span.inner.add_link(link.into());" ) ;
157
+ guest_span. inner . add_link (
158
+ // TODO(Caleb): Do I actually want to cause a trap in this case or should it be fallible?
159
+ link. span_context . try_into ( ) ?,
160
+ link. attributes . into_iter ( ) . map ( Into :: into) . collect ( ) ,
161
+ ) ;
162
+ Ok ( ( ) )
161
163
} else {
162
164
Err ( anyhow ! ( "BUG: cannot find resource in table" ) )
163
165
}
@@ -200,7 +202,7 @@ impl traces::HostSpan for InstanceState {
200
202
async fn end (
201
203
& mut self ,
202
204
resource : Resource < traces:: Span > ,
203
- _timestamp : Option < traces:: Datetime > ,
205
+ timestamp : Option < traces:: Datetime > ,
204
206
) -> Result < ( ) > {
205
207
if let Some ( guest_span) = self
206
208
. state
@@ -209,7 +211,11 @@ impl traces::HostSpan for InstanceState {
209
211
. guest_spans
210
212
. get_mut ( resource. rep ( ) )
211
213
{
212
- guest_span. inner . end ( ) ;
214
+ if let Some ( timestamp) = timestamp {
215
+ guest_span. inner . end_with_timestamp ( timestamp. into ( ) ) ;
216
+ } else {
217
+ guest_span. inner . end ( ) ;
218
+ }
213
219
Ok ( ( ) )
214
220
} else {
215
221
Err ( anyhow ! ( "BUG: cannot find resource in table" ) )
@@ -223,6 +229,6 @@ impl traces::HostSpan for InstanceState {
223
229
}
224
230
}
225
231
226
- // TODO(Caleb): Improve debug tracing in failure cases
227
232
// TODO(Caleb): Move the tests from integration.rs to here
228
233
// TODO(Caleb): Write tests somewhere for all the finicky type conversion stuff
234
+ // TODO(Caleb): Maybe introduce macro to reduce boilerplate of finding resource
0 commit comments