ryerraguntla commented on code in PR #3516: URL: https://github.com/apache/iggy/pull/3516#discussion_r3448999599
########## core/connectors/sources/otlp_source/src/convert.rs: ########## @@ -0,0 +1,323 @@ +// 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 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(); + + 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_attrs.clone(), Review Comment: both at 52 and 130 line numbers - resource_attrs cloned per record/span: line 52 "resource": resource_attrs.clone() inside the innermost loop over log records; line 130 same pattern for spans. resource_attrs is Map<String, Value> = BTreeMap. For batch of 1000 log records sharing one resource with 20 attrs: 1000 BTreeMap clones. **Fix:** serialize resource_attrs to Value once before inner loop, clone pre-built Value per record. -- 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]
