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


##########
core/connectors/sources/otlp_source/src/convert.rs:
##########
@@ -0,0 +1,330 @@
+// 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();
+
+        let resource_value = Value::Object(resource_attrs);
+        for scope_logs in resource_logs.scope_logs {
+            for record in scope_logs.log_records {
+                let body = record.body.as_ref().map(any_value_to_json);
+                let mut doc = json!({
+                    "signal": "log",
+                    "timestamp_ns": record.time_unix_nano,
+                    "observed_timestamp_ns": record.observed_time_unix_nano,
+                    "severity": 
severity_number_to_text(record.severity_number),
+                    "severity_text": record.severity_text,
+                    "body": body,
+                    "trace_id": bytes_to_hex(&record.trace_id),
+                    "span_id": bytes_to_hex(&record.span_id),
+                    "service_name": service_name,
+                    "resource": resource_value.clone(),
+                    "attributes": extract_attrs(&record.attributes),
+                });
+                if let Some(obj) = doc.as_object_mut() {
+                    obj.retain(|_, v| !v.is_null() && v != 
&Value::String(String::new()));
+                }
+                match serde_json::to_vec(&doc) {
+                    Ok(payload) => messages.push(ProducedMessage {
+                        id: None,
+                        checksum: None,

Review Comment:
   Zero time_unix_nano treated as valid timestamp: timestamp: 
Some(record.time_unix_nano) at line 62. Proto scalar default for unset 
timestamp is 0. Code emits timestamp: Some(0) = Unix 
     epoch 1970-01-01T00:00:00Z instead of "unset". Corrupts time-based 
queries. **Fix:** timestamp: if record.time_unix_nano == 0 { None } else { 
Some(record.time_unix_nano) }. Same applies to line 140 
     (span.start_time_unix_nano).



-- 
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