mfyuce commented on code in PR #3516:
URL: https://github.com/apache/iggy/pull/3516#discussion_r3711254923


##########
core/connectors/sources/otlp_source/src/convert.rs:
##########
@@ -0,0 +1,331 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use iggy_connector_sdk::ProducedMessage;
+use opentelemetry_proto::tonic::collector::logs::v1::ExportLogsServiceRequest;
+use 
opentelemetry_proto::tonic::collector::metrics::v1::ExportMetricsServiceRequest;
+use 
opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
+use opentelemetry_proto::tonic::common::v1::{AnyValue, KeyValue, any_value};
+use opentelemetry_proto::tonic::metrics::v1::{Metric, metric, 
number_data_point};
+use opentelemetry_proto::tonic::resource::v1::Resource;
+use serde_json::{Map, Value, json};
+use std::fmt::Write as _;
+use tracing::warn;
+
+pub fn export_logs_to_messages(req: ExportLogsServiceRequest) -> 
Vec<ProducedMessage> {
+    let mut messages = Vec::new();
+    for resource_logs in req.resource_logs {
+        let resource_attrs = 
extract_resource_attrs(resource_logs.resource.as_ref());
+        let service_name = resource_attrs
+            .get("service.name")
+            .and_then(Value::as_str)
+            .unwrap_or("")
+            .to_owned();
+

Review Comment:
   The clone is gone rather than reduced. The intermediate `Value` document is 
replaced by `#[derive(Serialize)]` structs (`LogDoc`, `SpanDoc`, `MetricDoc`) 
that hold `resource: &'a Map<String, Value>`, so serde walks the borrowed map 
once per record and never copies it. That also removed the build-then-`retain` 
pass, since the pruning is now per-field `skip_serializing_if`.
   
   One consequence worth flagging: output key order changed from alphabetical 
(`Map` is a `BTreeMap`) to struct declaration order. Key order is not 
significant in JSON and the sinks re-parse, but if you would rather keep the 
bytes identical, declaring the fields alphabetically restores it at no cost.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to