1+ //! Span related definitions structs.
2+
3+ use crate :: v2:: attribute:: Attribute ;
4+ use schemars:: JsonSchema ;
5+ use serde:: { Deserialize , Serialize } ;
6+ use weaver_semconv:: {
7+ attribute:: RequirementLevel ,
8+ group:: SpanKindSpec ,
9+ v2:: { signal_id:: SignalId , span:: SpanName , CommonFields } ,
10+ } ;
11+
12+ /// The definition of a span signal.
13+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , JsonSchema ) ]
14+ #[ serde( deny_unknown_fields) ]
15+ pub struct Span {
16+ /// The type of the Span. This denotes the identity
17+ /// of the "shape" of this span, and must be unique.
18+ pub r#type : SignalId ,
19+ /// Specifies the kind of the span.
20+ pub kind : SpanKindSpec ,
21+ /// The name pattern for the span.
22+ pub name : SpanName ,
23+ /// List of attributes that should be included on this span.
24+ #[ serde( default ) ]
25+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
26+ pub attributes : Vec < SpanAttribute > ,
27+ /// Which resources this span should be associated with.
28+ ///
29+ /// This list is an "any of" list, where a span may be associated with one or more entities, but should
30+ /// be associated with at least one in this list.
31+ #[ serde( default ) ]
32+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
33+ pub entity_associations : Vec < String > ,
34+
35+ /// Common fields (like brief, note, annotations).
36+ #[ serde( flatten) ]
37+ pub common : CommonFields ,
38+ }
39+
40+ /// A special type of reference to attributes that remembers span-specicific information.
41+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , JsonSchema ) ]
42+ #[ serde( deny_unknown_fields) ]
43+ pub struct SpanAttribute {
44+ /// Base attribute definitions.
45+ #[ serde( flatten) ]
46+ pub base : Attribute ,
47+ /// Specifies if the attribute is mandatory. Can be "required",
48+ /// "conditionally_required", "recommended" or "opt_in". When omitted,
49+ /// the attribute is "recommended". When set to
50+ /// "conditionally_required", the string provided as <condition> MUST
51+ /// specify the conditions under which the attribute is required.
52+ ///
53+ /// Note: For attributes that are "recommended" or "opt-in" - not all metric source will
54+ /// create timeseries with these attributes, but for any given timeseries instance, the attributes that *were* present
55+ /// should *remain* present. That is - a metric timeseries cannot drop attributes during its lifetime.
56+ pub requirement_level : RequirementLevel ,
57+
58+ /// Specifies if the attribute is (especially) relevant for sampling
59+ /// and thus should be set at span start. It defaults to false.
60+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
61+ pub sampling_relevant : Option < bool > ,
62+ }
63+
64+ /// A refinement of a span signal, for use in code-gen or specific library application.
65+ ///
66+ /// A refinement represents a "view" of a Span that is highly optimised for a particular implementation.
67+ /// e.g. for HTTP spans, there may be a refinement that provides only the necessary information for dealing with Java's HTTP
68+ /// client library, and drops optional or extraneous information from the underlying http span.
69+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , JsonSchema ) ]
70+ pub struct SpanRefinement {
71+ /// The identity of the refinement.
72+ pub id : SignalId ,
73+
74+ // TODO - This is a lazy way of doing this. We use `type` to refer
75+ // to the underlying span defintiion, but override all fields here.
76+ // We probably should copy-paste all the "span" attributes here
77+ // including the `ty`
78+ /// The definition of the metric refinement.
79+ #[ serde( flatten) ]
80+ pub span : Span ,
81+ }
0 commit comments