|
1 | | -use relay_protocol::{Annotated, Array, Empty, Error, FromValue, Getter, IntoValue, Object, Value}; |
| 1 | +use relay_protocol::{Annotated, Array, Empty, FromValue, Getter, IntoValue, Object, Value}; |
2 | 2 |
|
3 | 3 | use std::fmt; |
4 | | -use std::str::FromStr; |
5 | 4 |
|
6 | 5 | use serde::Serialize; |
7 | 6 |
|
8 | 7 | use crate::processor::ProcessValue; |
9 | | -use crate::protocol::{Attributes, OperationType, SpanId, Timestamp, TraceId}; |
| 8 | +use crate::protocol::{Attributes, OperationType, SpanId, SpanKind, Timestamp, TraceId}; |
10 | 9 |
|
11 | 10 | /// A version 2 (transactionless) span. |
12 | 11 | #[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)] |
@@ -46,7 +45,7 @@ pub struct SpanV2 { |
46 | 45 | /// |
47 | 46 | /// See <https://opentelemetry.io/docs/specs/otel/trace/api/#spankind> |
48 | 47 | #[metastructure(skip_serialization = "empty", trim = false)] |
49 | | - pub kind: Annotated<SpanV2Kind>, |
| 48 | + pub kind: Annotated<SpanKind>, |
50 | 49 |
|
51 | 50 | /// Timestamp when the span started. |
52 | 51 | #[metastructure(required = true)] |
@@ -177,116 +176,6 @@ impl IntoValue for SpanV2Status { |
177 | 176 | } |
178 | 177 | } |
179 | 178 |
|
180 | | -/// The kind of a V2 span. |
181 | | -/// |
182 | | -/// This corresponds to OTEL's kind enum, plus a |
183 | | -/// catchall variant for forward compatibility. |
184 | | -#[derive(Clone, Debug, PartialEq, ProcessValue)] |
185 | | -pub enum SpanV2Kind { |
186 | | - /// An operation internal to an application. |
187 | | - Internal, |
188 | | - /// Server-side processing requested by a client. |
189 | | - Server, |
190 | | - /// A request from a client to a server. |
191 | | - Client, |
192 | | - /// Scheduling of an operation. |
193 | | - Producer, |
194 | | - /// Processing of a scheduled operation. |
195 | | - Consumer, |
196 | | -} |
197 | | - |
198 | | -impl SpanV2Kind { |
199 | | - pub fn as_str(&self) -> &'static str { |
200 | | - match self { |
201 | | - Self::Internal => "internal", |
202 | | - Self::Server => "server", |
203 | | - Self::Client => "client", |
204 | | - Self::Producer => "producer", |
205 | | - Self::Consumer => "consumer", |
206 | | - } |
207 | | - } |
208 | | -} |
209 | | - |
210 | | -impl Empty for SpanV2Kind { |
211 | | - fn is_empty(&self) -> bool { |
212 | | - false |
213 | | - } |
214 | | -} |
215 | | - |
216 | | -impl Default for SpanV2Kind { |
217 | | - fn default() -> Self { |
218 | | - Self::Internal |
219 | | - } |
220 | | -} |
221 | | - |
222 | | -impl fmt::Display for SpanV2Kind { |
223 | | - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
224 | | - write!(f, "{}", self.as_str()) |
225 | | - } |
226 | | -} |
227 | | - |
228 | | -#[derive(Debug, Clone, Copy)] |
229 | | -pub struct ParseSpanV2KindError; |
230 | | - |
231 | | -impl fmt::Display for ParseSpanV2KindError { |
232 | | - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
233 | | - write!(f, "invalid span kind") |
234 | | - } |
235 | | -} |
236 | | - |
237 | | -impl FromStr for SpanV2Kind { |
238 | | - type Err = ParseSpanV2KindError; |
239 | | - |
240 | | - fn from_str(s: &str) -> Result<Self, Self::Err> { |
241 | | - let kind = match s { |
242 | | - "internal" => Self::Internal, |
243 | | - "server" => Self::Server, |
244 | | - "client" => Self::Client, |
245 | | - "producer" => Self::Producer, |
246 | | - "consumer" => Self::Consumer, |
247 | | - _ => return Err(ParseSpanV2KindError), |
248 | | - }; |
249 | | - Ok(kind) |
250 | | - } |
251 | | -} |
252 | | - |
253 | | -impl FromValue for SpanV2Kind { |
254 | | - fn from_value(Annotated(value, meta): Annotated<Value>) -> Annotated<Self> |
255 | | - where |
256 | | - Self: Sized, |
257 | | - { |
258 | | - match &value { |
259 | | - Some(Value::String(s)) => match s.parse() { |
260 | | - Ok(kind) => Annotated(Some(kind), meta), |
261 | | - Err(_) => Annotated::from_error(Error::expected("a span kind"), value), |
262 | | - }, |
263 | | - Some(_) => Annotated::from_error(Error::expected("a span kind"), value), |
264 | | - None => Annotated::empty(), |
265 | | - } |
266 | | - } |
267 | | -} |
268 | | - |
269 | | -impl IntoValue for SpanV2Kind { |
270 | | - fn into_value(self) -> Value |
271 | | - where |
272 | | - Self: Sized, |
273 | | - { |
274 | | - Value::String(self.to_string()) |
275 | | - } |
276 | | - |
277 | | - fn serialize_payload<S>( |
278 | | - &self, |
279 | | - s: S, |
280 | | - _behavior: relay_protocol::SkipSerialization, |
281 | | - ) -> Result<S::Ok, S::Error> |
282 | | - where |
283 | | - Self: Sized, |
284 | | - S: serde::Serializer, |
285 | | - { |
286 | | - s.serialize_str(self.as_str()) |
287 | | - } |
288 | | -} |
289 | | - |
290 | 179 | /// A link from a span to another span. |
291 | 180 | #[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)] |
292 | 181 | #[metastructure(trim = false)] |
@@ -428,7 +317,7 @@ mod tests { |
428 | 317 | span_id: Annotated::new("438f40bd3b4a41ee".parse().unwrap()), |
429 | 318 | parent_span_id: Annotated::empty(), |
430 | 319 | status: Annotated::new(SpanV2Status::Ok), |
431 | | - kind: Annotated::new(SpanV2Kind::Server), |
| 320 | + kind: Annotated::new(SpanKind::Server), |
432 | 321 | is_remote: Annotated::new(true), |
433 | 322 | links: Annotated::new(links), |
434 | 323 | attributes: Annotated::new(attributes), |
|
0 commit comments