diff --git a/core/pipeline/serializer/SLSSerializer.cpp b/core/pipeline/serializer/SLSSerializer.cpp index ebcedb710f..5e00449479 100644 --- a/core/pipeline/serializer/SLSSerializer.cpp +++ b/core/pipeline/serializer/SLSSerializer.cpp @@ -93,7 +93,8 @@ bool SLSEventGroupSerializer::Serialize(BatchedEvents&& group, string& res, stri size_t contentSZ = 0; contentSZ += GetLogContentSize(METRIC_RESERVED_KEY_NAME.size(), e.GetName().size()); - contentSZ += GetLogContentSize(METRIC_RESERVED_KEY_VALUE.size(), metricEventContentCache[i].first.size()); + contentSZ + += GetLogContentSize(METRIC_RESERVED_KEY_VALUE.size(), metricEventContentCache[i].first.size()); contentSZ += GetLogContentSize(METRIC_RESERVED_KEY_TIME_NANO.size(), e.GetTimestampNanosecond() ? 19U : 10U); contentSZ += GetLogContentSize(METRIC_RESERVED_KEY_LABELS.size(), metricEventContentCache[i].second); @@ -123,32 +124,38 @@ bool SLSEventGroupSerializer::Serialize(BatchedEvents&& group, string& res, stri static LogGroupSerializer serializer; serializer.Prepare(logGroupSZ); - for (size_t i = 0; i < group.mEvents.size(); ++i) { - if (group.mEvents[i].Is()) { - const auto& logEvent = group.mEvents[i].Cast(); - serializer.StartToAddLog(logSZ[i]); - serializer.AddLogTime(logEvent.GetTimestamp()); - for (const auto& kv : logEvent) { - serializer.AddLogContent(kv.first, kv.second); - } - if (enableNs && logEvent.GetTimestampNanosecond()) { - serializer.AddLogTimeNs(logEvent.GetTimestampNanosecond().value()); + switch (eventType) { + case PipelineEvent::Type::LOG: + for (size_t i = 0; i < group.mEvents.size(); ++i) { + const auto& logEvent = group.mEvents[i].Cast(); + serializer.StartToAddLog(logSZ[i]); + serializer.AddLogTime(logEvent.GetTimestamp()); + for (const auto& kv : logEvent) { + serializer.AddLogContent(kv.first, kv.second); + } + if (enableNs && logEvent.GetTimestampNanosecond()) { + serializer.AddLogTimeNs(logEvent.GetTimestampNanosecond().value()); + } } - } else if (group.mEvents[i].Is()) { - const auto& metricEvent = group.mEvents[i].Cast(); - if (metricEvent.Is()) { - continue; + break; + case PipelineEvent::Type::METRIC: + for (size_t i = 0; i < group.mEvents.size(); ++i) { + const auto& metricEvent = group.mEvents[i].Cast(); + if (metricEvent.Is()) { + continue; + } + serializer.StartToAddLog(logSZ[i]); + serializer.AddLogTime(metricEvent.GetTimestamp()); + serializer.AddLogContentMetricLabel(metricEvent, metricEventContentCache[i].second); + serializer.AddLogContentMetricTimeNano(metricEvent); + serializer.AddLogContent(METRIC_RESERVED_KEY_VALUE, metricEventContentCache[i].first); + serializer.AddLogContent(METRIC_RESERVED_KEY_NAME, metricEvent.GetName()); } - serializer.StartToAddLog(logSZ[i]); - serializer.AddLogTime(metricEvent.GetTimestamp()); - serializer.AddLogContentMetricLabel(metricEvent, metricEventContentCache[i].second); - serializer.AddLogContentMetricTimeNano(metricEvent); - serializer.AddLogContent(METRIC_RESERVED_KEY_VALUE, metricEventContentCache[i].first); - serializer.AddLogContent(METRIC_RESERVED_KEY_NAME, metricEvent.GetName()); - } else { - errorMsg = "unsupported event type in event group"; - return false; - } + break; + case PipelineEvent::Type::SPAN: + break; + default: + break; } for (const auto& tag : group.mTags.mInner) { if (tag.first == LOG_RESERVED_KEY_TOPIC) {