@@ -252,7 +252,7 @@ def maybe_read_prometheus_metric_value(metrics_text, metric_name, input_name):
252252 return None
253253
254254
255- def build_resource_collision_logs_payload (user_id , body ):
255+ def build_resource_collision_logs_payload (user_id , body , schema_url = None ):
256256 payload = {
257257 "resourceLogs" : [
258258 {
@@ -283,9 +283,49 @@ def build_resource_collision_logs_payload(user_id, body):
283283 ],
284284 }
285285
286+ if schema_url is not None :
287+ payload ["resourceLogs" ][0 ]["schemaUrl" ] = schema_url
288+
286289 return json_format .Parse (json .dumps (payload ), ExportLogsServiceRequest ()).SerializeToString ()
287290
288291
292+ def build_resource_collision_logs_json_payload (user_id , body , schema_url = None ):
293+ payload = {
294+ "resourceLogs" : [
295+ {
296+ "resource" : {
297+ "attributes" : [
298+ {
299+ "key" : "user.id" ,
300+ "value" : {
301+ "stringValue" : user_id ,
302+ },
303+ }
304+ ],
305+ },
306+ "scopeLogs" : [
307+ {
308+ "scope" : {},
309+ "logRecords" : [
310+ {
311+ "timeUnixNano" : "1640995200000000000" ,
312+ "body" : {
313+ "stringValue" : body ,
314+ },
315+ }
316+ ],
317+ }
318+ ],
319+ }
320+ ],
321+ }
322+
323+ if schema_url is not None :
324+ payload ["resourceLogs" ][0 ]["schemaUrl" ] = schema_url
325+
326+ return json .dumps (payload ).encode ("utf-8" )
327+
328+
289329class Service :
290330 def __init__ (self , config_file , * , use_auth_server = False ):
291331 # Compose the absolute path for the Fluent Bit configuration file
@@ -709,6 +749,49 @@ def test_in_opentelemetry_stdout_otlp_json_logs_preserve_resources_across_reques
709749 assert len (output ["resourceLogs" ]) == 2
710750
711751
752+ @pytest .mark .parametrize (
753+ "content_type,payload_builder" ,
754+ [
755+ ("application/x-protobuf" , build_resource_collision_logs_payload ),
756+ ("application/json" , build_resource_collision_logs_json_payload ),
757+ ],
758+ )
759+ def test_in_opentelemetry_stdout_otlp_json_logs_preserve_resource_schema_urls (
760+ content_type ,
761+ payload_builder ,
762+ ):
763+ service = Service ("stdout-otlp-json-slow-flush.yaml" )
764+ service .start ()
765+
766+ response = service .send_raw_request (
767+ "/v1/logs" ,
768+ payload_builder ("same-user" , "event-a" , "schema-a" ),
769+ content_type = content_type ,
770+ )
771+ assert 200 <= response .status_code < 300
772+
773+ response = service .send_raw_request (
774+ "/v1/logs" ,
775+ payload_builder ("same-user" , "event-b" , "schema-b" ),
776+ content_type = content_type ,
777+ )
778+ assert 200 <= response .status_code < 300
779+
780+ output = read_stdout_otlp_json (service , "resourceLogs" , timeout = 10 )
781+ service .stop ()
782+
783+ body_to_schema_url = {
784+ record ["body" ]["stringValue" ]: resource_log ["schemaUrl" ]
785+ for resource_log in output ["resourceLogs" ]
786+ for scope_log in resource_log ["scopeLogs" ]
787+ for record in scope_log ["logRecords" ]
788+ }
789+
790+ assert body_to_schema_url ["event-a" ] == "schema-a"
791+ assert body_to_schema_url ["event-b" ] == "schema-b"
792+ assert len (output ["resourceLogs" ]) == 2
793+
794+
712795def test_in_opentelemetry_stdout_otlp_json_metrics ():
713796 service = Service ("003-stdout-otlp-json.yaml" )
714797 service .start ()
0 commit comments