150150from sentry .users .models .useremail import UserEmail
151151from sentry .utils import json
152152from sentry .utils .auth import SsoSession
153+ from sentry .utils .eap import encode_value
153154from sentry .utils .json import dumps_htmlsafe
154155from sentry .utils .not_set import NOT_SET , NotSet , default_if_not_set
155156from sentry .utils .samples import load_data
@@ -3316,20 +3317,6 @@ class _OptionalOurLogData(TypedDict, total=False):
33163317 item_id : int
33173318
33183319
3319- def scalar_to_any_value (value : Any ) -> AnyValue :
3320- if isinstance (value , str ):
3321- return AnyValue (string_value = value )
3322- if isinstance (value , int ):
3323- return AnyValue (int_value = value )
3324- if isinstance (value , float ):
3325- return AnyValue (double_value = value )
3326- if isinstance (value , bool ):
3327- return AnyValue (bool_value = value )
3328- if isinstance (value , dict ):
3329- return AnyValue (** value )
3330- raise Exception (f"cannot convert { value } of type { type (value )} to AnyValue" )
3331-
3332-
33333320def span_to_trace_item (span ) -> TraceItem :
33343321 client_sample_rate = 1.0
33353322 server_sample_rate = 1.0
@@ -3339,15 +3326,15 @@ def span_to_trace_item(span) -> TraceItem:
33393326 for k , v in span .get (field , {}).items ():
33403327 if v is None :
33413328 continue
3342- attributes [k ] = scalar_to_any_value (v )
3329+ attributes [k ] = encode_value (v )
33433330
33443331 for k , v in span .get ("sentry_tags" , {}).items ():
33453332 if v is None :
33463333 continue
33473334 if k == "description" :
33483335 k = "normalized_description"
33493336
3350- attributes [f"sentry.{ k } " ] = scalar_to_any_value (v )
3337+ attributes [f"sentry.{ k } " ] = encode_value (v )
33513338
33523339 for k , v in span .get ("measurements" , {}).items ():
33533340 if v is None or v ["value" ] is None :
@@ -3357,10 +3344,10 @@ def span_to_trace_item(span) -> TraceItem:
33573344 elif k == "server_sample_rate" :
33583345 server_sample_rate = v ["value" ]
33593346 else :
3360- attributes [k ] = scalar_to_any_value (float (v ["value" ]))
3347+ attributes [k ] = encode_value (float (v ["value" ]))
33613348
33623349 if "description" in span and span ["description" ] is not None :
3363- description = scalar_to_any_value (span ["description" ])
3350+ description = encode_value (span ["description" ])
33643351 attributes ["sentry.raw_description" ] = description
33653352
33663353 for field in {
@@ -3382,7 +3369,7 @@ def span_to_trace_item(span) -> TraceItem:
33823369 double_value = float (is_segment ),
33833370 )
33843371 else :
3385- value = scalar_to_any_value (span [field ])
3372+ value = encode_value (span [field ])
33863373 attributes [f"sentry.{ field } " ] = value
33873374
33883375 timestamp = Timestamp ()
@@ -3453,10 +3440,10 @@ def create_ourlog(
34533440 attributes_proto = {}
34543441
34553442 for k , v in attributes .items ():
3456- attributes_proto [k ] = scalar_to_any_value (v )
3443+ attributes_proto [k ] = encode_value (v )
34573444
34583445 for k , v in extra_data .items ():
3459- attributes_proto [f"sentry.{ k } " ] = scalar_to_any_value (v )
3446+ attributes_proto [f"sentry.{ k } " ] = encode_value (v )
34603447
34613448 timestamp_proto = Timestamp ()
34623449
@@ -3532,7 +3519,7 @@ def create_trace_metric(
35323519
35333520 if attributes :
35343521 for k , v in attributes .items ():
3535- attributes_proto [k ] = scalar_to_any_value (v )
3522+ attributes_proto [k ] = encode_value (v )
35363523
35373524 return TraceItem (
35383525 organization_id = organization .id ,
@@ -3577,7 +3564,7 @@ def create_profile_function(
35773564
35783565 if attributes :
35793566 for k , v in attributes .items ():
3580- attributes_proto [k ] = scalar_to_any_value (v )
3567+ attributes_proto [k ] = encode_value (v )
35813568
35823569 return TraceItem (
35833570 organization_id = organization .id ,
@@ -3892,7 +3879,7 @@ def create_eap_uptime_result(
38923879 attributes_proto = {}
38933880 for k , v in attributes_data .items ():
38943881 if v is not None :
3895- attributes_proto [k ] = scalar_to_any_value (v )
3882+ attributes_proto [k ] = encode_value (v )
38963883
38973884 timestamp_proto = Timestamp ()
38983885 timestamp_proto .FromDatetime (scheduled_check_time )
0 commit comments