Skip to content

Commit 622b9a2

Browse files
nikhilsinhaparseableDevdutt Shenoi
andauthored
feat: Custom Flattening for OTEL logs, metrics and traces (#1043)
custom flattening for OTEL data add proto files for metrics and trace add compiled rust files for metrics and trace protobuf files add separate handlers for OTEL logs, metrics and traces custom flattening added for OTEL logs and metrics custom flattening for OTEL traces use endpoints `/v1/logs` for OTEL logs `/v1/metrics` for OTEL metrics `/v1/traces` for OTEL traces add custom header X-P-Log-Source when using endpint `api/v1/ingest` `otel-logs` for OTEL logs `otel-metrics` for OTEL metrics `otel-traces` for OTEL traces --------- Signed-off-by: Nikhil Sinha <[email protected]> Co-authored-by: Devdutt Shenoi <[email protected]>
1 parent 450bac2 commit 622b9a2

File tree

23 files changed

+1548
-894
lines changed

23 files changed

+1548
-894
lines changed

Cargo.lock

Lines changed: 107 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ humantime-serde = "1.1"
6464
itertools = "0.13.0"
6565
num_cpus = "1.15"
6666
once_cell = "1.17.1"
67+
opentelemetry-proto = {git = "https://github.com/parseablehq/opentelemetry-rust", branch="fix-metrics-u64-serialization"}
6768
prometheus = { version = "0.13", features = ["process"] }
6869
rand = "0.8.5"
69-
rdkafka = {version = "0.36.2", default-features = false, features = ["tokio"]}
70+
rdkafka = { version = "0.36.2", default-features = false, features = ["tokio"] }
7071
regex = "1.7.3"
7172
relative-path = { version = "1.7", features = ["serde"] }
7273
reqwest = { version = "0.11.27", default-features = false, features = [
@@ -80,7 +81,7 @@ serde = { version = "1.0", features = ["rc", "derive"] }
8081
serde_json = "1.0"
8182
static-files = "0.2"
8283
sysinfo = "0.31.4"
83-
thiserror = "1.0.64"
84+
thiserror = "2.0.0"
8485
thread-priority = "1.0.0"
8586
tokio = { version = "1.28", default-features = false, features = [
8687
"sync",

src/event/format/json.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use serde_json::Value;
2929
use std::{collections::HashMap, sync::Arc};
3030
use tracing::error;
3131

32-
use super::{EventFormat, Metadata, Tags};
32+
use super::{EventFormat, LogSource, Metadata, Tags};
3333
use crate::{
3434
metadata::SchemaVersion,
3535
utils::{arrow::get_field, json::flatten_json_body},
@@ -52,8 +52,17 @@ impl EventFormat for Event {
5252
static_schema_flag: Option<&String>,
5353
time_partition: Option<&String>,
5454
schema_version: SchemaVersion,
55+
log_source: &LogSource,
5556
) -> Result<(Self::Data, Vec<Arc<Field>>, bool, Tags, Metadata), anyhow::Error> {
56-
let data = flatten_json_body(self.data, None, None, None, schema_version, false)?;
57+
let data = flatten_json_body(
58+
self.data,
59+
None,
60+
None,
61+
None,
62+
schema_version,
63+
false,
64+
log_source,
65+
)?;
5766
let stream_schema = schema;
5867

5968
// incoming event may be a single json or a json array

src/event/format/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,38 @@ type Tags = String;
4343
type Metadata = String;
4444
type EventSchema = Vec<Arc<Field>>;
4545

46+
/// Source of the logs, used to perform special processing for certain sources
47+
#[derive(Default, Debug, Clone, PartialEq, Eq)]
48+
pub enum LogSource {
49+
// AWS Kinesis sends logs in the format of a json array
50+
Kinesis,
51+
// OpenTelemetry sends logs according to the specification as explained here
52+
// https://github.com/open-telemetry/opentelemetry-proto/tree/v1.0.0/opentelemetry/proto/logs/v1
53+
OtelLogs,
54+
// OpenTelemetry sends traces according to the specification as explained here
55+
// https://github.com/open-telemetry/opentelemetry-proto/blob/v1.0.0/opentelemetry/proto/trace/v1/trace.proto
56+
OtelMetrics,
57+
// OpenTelemetry sends traces according to the specification as explained here
58+
// https://github.com/open-telemetry/opentelemetry-proto/tree/v1.0.0/opentelemetry/proto/metrics/v1
59+
OtelTraces,
60+
#[default]
61+
// Json object or array
62+
Json,
63+
Custom(String),
64+
}
65+
66+
impl From<&str> for LogSource {
67+
fn from(s: &str) -> Self {
68+
match s {
69+
"kinesis" => LogSource::Kinesis,
70+
"otel-logs" => LogSource::OtelLogs,
71+
"otel-metrics" => LogSource::OtelMetrics,
72+
"otel-traces" => LogSource::OtelTraces,
73+
custom => LogSource::Custom(custom.to_owned()),
74+
}
75+
}
76+
}
77+
4678
// Global Trait for event format
4779
// This trait is implemented by all the event formats
4880
pub trait EventFormat: Sized {
@@ -54,6 +86,7 @@ pub trait EventFormat: Sized {
5486
static_schema_flag: Option<&String>,
5587
time_partition: Option<&String>,
5688
schema_version: SchemaVersion,
89+
log_source: &LogSource,
5790
) -> Result<(Self::Data, EventSchema, bool, Tags, Metadata), AnyError>;
5891

5992
fn decode(data: Self::Data, schema: Arc<Schema>) -> Result<RecordBatch, AnyError>;
@@ -64,12 +97,14 @@ pub trait EventFormat: Sized {
6497
static_schema_flag: Option<&String>,
6598
time_partition: Option<&String>,
6699
schema_version: SchemaVersion,
100+
log_source: &LogSource,
67101
) -> Result<(RecordBatch, bool), AnyError> {
68102
let (data, mut schema, is_first, tags, metadata) = self.to_data(
69103
storage_schema,
70104
static_schema_flag,
71105
time_partition,
72106
schema_version,
107+
log_source,
73108
)?;
74109

75110
// DEFAULT_TAGS_KEY, DEFAULT_METADATA_KEY and DEFAULT_TIMESTAMP_KEY are reserved field names

0 commit comments

Comments
 (0)