@@ -45,7 +45,7 @@ use crate::services::global_config::GlobalConfigHandle;
45
45
use crate :: services:: outcome:: { DiscardItemType , DiscardReason , Outcome , TrackOutcome } ;
46
46
use crate :: services:: processor:: Processed ;
47
47
use crate :: statsd:: { RelayCounters , RelayGauges , RelayTimers } ;
48
- use crate :: utils:: FormDataIter ;
48
+ use crate :: utils:: { self , FormDataIter , PickResult } ;
49
49
50
50
/// Fallback name used for attachment items without a `filename` header.
51
51
const UNNAMED_ATTACHMENT : & str = "Unnamed Attachment" ;
@@ -1055,7 +1055,8 @@ impl StoreService {
1055
1055
span. start_timestamp_ms = ( span. start_timestamp_precise * 1e3 ) as u64 ;
1056
1056
span. key_id = scoping. key_id ;
1057
1057
1058
- if self . config . produce_protobuf_spans ( ) {
1058
+ let spans_target = self . spans_target ( span. organization_id ) ;
1059
+ if spans_target. is_protobuf ( ) {
1059
1060
self . inner_produce_protobuf_span (
1060
1061
scoping,
1061
1062
received_at,
@@ -1075,13 +1076,32 @@ impl StoreService {
1075
1076
} ) ;
1076
1077
}
1077
1078
1078
- if self . config . produce_json_spans ( ) {
1079
+ if spans_target . is_json ( ) {
1079
1080
self . inner_produce_json_span ( scoping, span) ?;
1080
1081
}
1081
1082
1082
1083
Ok ( ( ) )
1083
1084
}
1084
1085
1086
+ fn spans_target ( & self , org_id : u64 ) -> SpansTarget {
1087
+ let config = self . config . span_producers ( ) ;
1088
+ if config. produce_json_orgs . contains ( & org_id) {
1089
+ return SpansTarget :: Json ;
1090
+ } else if let Some ( rate) = config. produce_json_sample_rate {
1091
+ return match utils:: is_rolled_out ( org_id, rate) {
1092
+ PickResult :: Keep => SpansTarget :: Json ,
1093
+ PickResult :: Discard => SpansTarget :: Protobuf ,
1094
+ } ;
1095
+ }
1096
+
1097
+ match ( config. produce_json , config. produce_protobuf ) {
1098
+ ( true , true ) => SpansTarget :: Both ,
1099
+ ( true , false ) => SpansTarget :: Json ,
1100
+ ( false , true ) => SpansTarget :: Protobuf ,
1101
+ ( false , false ) => SpansTarget :: default ( ) ,
1102
+ }
1103
+ }
1104
+
1085
1105
fn inner_produce_json_span (
1086
1106
& self ,
1087
1107
scoping : Scoping ,
@@ -2005,6 +2025,24 @@ fn safe_timestamp(timestamp: DateTime<Utc>) -> u64 {
2005
2025
Utc :: now ( ) . timestamp ( ) as u64
2006
2026
}
2007
2027
2028
+ #[ derive( Clone , Copy , Debug , Default , PartialEq , Eq ) ]
2029
+ enum SpansTarget {
2030
+ #[ default]
2031
+ Protobuf ,
2032
+ Json ,
2033
+ Both ,
2034
+ }
2035
+
2036
+ impl SpansTarget {
2037
+ fn is_protobuf ( & self ) -> bool {
2038
+ matches ! ( self , SpansTarget :: Protobuf | SpansTarget :: Both )
2039
+ }
2040
+
2041
+ fn is_json ( & self ) -> bool {
2042
+ matches ! ( self , SpansTarget :: Json | SpansTarget :: Both )
2043
+ }
2044
+ }
2045
+
2008
2046
#[ cfg( test) ]
2009
2047
mod tests {
2010
2048
0 commit comments