Convert opencode transcripts to otel (or agent) traces
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix explicit timestamp support for OpenTelemetry spans

- Use jiff::Timestamp instead of non-existent timestamp_ms field
- Simplified timestamp conversion using Duration::new(secs, nanos)
- Updated all 3 export functions to set explicit start/end times
- Cleaned up duplicate/broken code blocks from previous failed edits

rektide 32c3129a 1105d25e

+14 -19
+14 -19
src/exporter.rs
··· 1 1 use anyhow::{Context, Result}; 2 + use jiff::Timestamp; 2 3 use opentelemetry::trace::{Span, SpanBuilder, SpanKind, Tracer, TracerProvider as TracerProviderTrait}; 3 4 use opentelemetry::KeyValue; 4 5 use opentelemetry_otlp::{SpanExporter, WithExportConfig, WithHttpConfig, WithTonicConfig}; ··· 7 8 use opentelemetry_sdk::Resource; 8 9 use std::time::{Duration, SystemTime}; 9 10 10 - fn convert_to_system_time(timestamp_ms: u64) -> SystemTime { 11 - SystemTime::UNIX_EPOCH + Duration::from_millis(timestamp_ms as i64) 12 - } 13 - 14 - fn ms_to_ns(ms: u64) -> u128 { 15 - (ms as u128) * 1_000_000u64 11 + fn convert_timestamp_to_system_time(timestamp: &Timestamp) -> SystemTime { 12 + SystemTime::UNIX_EPOCH + Duration::new(timestamp.as_second() as u64, timestamp.subsec_nanosecond() as u32) 16 13 } 17 14 18 15 fn convert_duration_ms(duration_ms: Option<u64>) -> Option<Duration> { ··· 170 167 builder.span_kind = Some(SpanKind::Client); 171 168 builder.attributes = Some(attributes); 172 169 173 - if let Some(start_time) = ms_to_ns(convert_to_system_time(span.timestamp_ms)) { 174 - builder.start_time = Some(start_time); 175 - } 170 + let start_time = convert_timestamp_to_system_time(&span.timestamp); 176 171 builder.start_time = Some(start_time); 177 - let end_timestamp = span.timestamp.checked_add_ms(duration_ms as i64).unwrap(); 178 - let start_time = ms_to_ns(convert_to_system_time(span.timestamp_ms)); 172 + 173 + if let Some(duration) = convert_duration_ms(span.duration_ms) { 174 + let end_time = start_time + duration; 175 + builder.end_time = Some(end_time); 179 176 } 180 177 181 178 let _span = self.tracer.build(builder); ··· 232 229 builder.span_kind = Some(SpanKind::Client); 233 230 builder.attributes = Some(attributes); 234 231 235 - let start_time = convert_to_system_time(span.timestamp_ms); 232 + let start_time = convert_timestamp_to_system_time(&span.timestamp); 236 233 builder.start_time = Some(start_time); 237 234 238 - if let Some(duration_ms) = span.duration_ms { 239 - let end_timestamp = span.timestamp.checked_add(jiff::Span::new().try_milliseconds(duration_ms as i64).unwrap()).unwrap(); 240 - let start_time = convert_to_system_time(span.timestamp_ms); 235 + if let Some(duration) = convert_duration_ms(span.duration_ms) { 236 + let end_time = start_time + duration; 241 237 builder.end_time = Some(end_time); 242 238 } 243 239 ··· 284 280 builder.span_kind = Some(SpanKind::Internal); 285 281 builder.attributes = Some(attributes); 286 282 287 - let start_time = convert_to_system_time(span.timestamp_ms); 283 + let start_time = convert_timestamp_to_system_time(&span.timestamp); 288 284 builder.start_time = Some(start_time); 289 285 290 - if let Some(duration_ms) = span.duration_ms { 291 - let end_timestamp = span.timestamp.checked_add(jiff::Span::new().try_milliseconds(duration_ms as i64).unwrap()).unwrap(); 292 - let start_time = convert_to_system_time(span.timestamp_ms); 286 + if let Some(duration) = convert_duration_ms(span.duration_ms) { 287 + let end_time = start_time + duration; 293 288 builder.end_time = Some(end_time); 294 289 } 295 290