From 9fe998a43d26c0aa177df124d0cab2a32da5017a Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 23 Oct 2023 15:27:22 +0100 Subject: [PATCH] save logs to otel --- Examples/otel-dotnet/README.md | 2 +- .../obj/staticwebassets.pack.sentinel | 2 + Ingestor/API/OTelIngest.ts | 52 +++++++++++-------- Model/AnalyticsModels/Log.ts | 21 -------- Model/AnalyticsModels/Span.ts | 46 ---------------- 5 files changed, 33 insertions(+), 90 deletions(-) diff --git a/Examples/otel-dotnet/README.md b/Examples/otel-dotnet/README.md index 4e41b31235..1e14d03dd3 100644 --- a/Examples/otel-dotnet/README.md +++ b/Examples/otel-dotnet/README.md @@ -5,5 +5,5 @@ Please use ```bash -dotnet run +dotnet run --urls=http://localhost:7856/ ``` \ No newline at end of file diff --git a/Examples/otel-dotnet/obj/staticwebassets.pack.sentinel b/Examples/otel-dotnet/obj/staticwebassets.pack.sentinel index 0b6749ed3e..769d611a5f 100644 --- a/Examples/otel-dotnet/obj/staticwebassets.pack.sentinel +++ b/Examples/otel-dotnet/obj/staticwebassets.pack.sentinel @@ -6,3 +6,5 @@ 2.0 2.0 2.0 +2.0 +2.0 diff --git a/Ingestor/API/OTelIngest.ts b/Ingestor/API/OTelIngest.ts index bd78d2b9b2..1994a68d12 100644 --- a/Ingestor/API/OTelIngest.ts +++ b/Ingestor/API/OTelIngest.ts @@ -189,7 +189,7 @@ router.post( try { logger.info('OTel Ingestor API called'); - logger.info(req.body); + req.body = req.body.toJSON(); const resourceLogs = req.body['resourceLogs'] as JSONArray; @@ -228,7 +228,12 @@ router.post( dbLog.time = OneUptimeDate.fromUnixNano(log['timeUnixNano'] as number); dbLog.severityNumber = log['severityNumber'] as string; dbLog.severityText = log['severityText'] as string; - dbLog.body = log['body'] as string; + + const logBody: JSONObject = log['body'] as JSONObject; + + + dbLog.body = logBody['stringValue'] as string; + dbLog.traceId = log['traceId'] as string; dbLog.spanId = log['spanId'] as string; @@ -238,33 +243,36 @@ router.post( 'attributes' ] as JSONArray; - const dbattributes: Array = []; + if (attributes) { - for (const attribute of attributes) { - const dbattribute: KeyValueNestedModel = - new KeyValueNestedModel(); - dbattribute.key = attribute['key'] as string; + const dbattributes: Array = []; - const value: JSONObject = attribute[ - 'value' - ] as JSONObject; + for (const attribute of attributes) { + const dbattribute: KeyValueNestedModel = + new KeyValueNestedModel(); + dbattribute.key = attribute['key'] as string; - if (value['stringValue']) { - dbattribute.stringValue = value[ - 'stringValue' - ] as string; + const value: JSONObject = attribute[ + 'value' + ] as JSONObject; + + if (value['stringValue']) { + dbattribute.stringValue = value[ + 'stringValue' + ] as string; + } + + if (value['intValue']) { + dbattribute.numberValue = value[ + 'intValue' + ] as number; + } + dbattributes.push(dbattribute); } - if (value['intValue']) { - dbattribute.numberValue = value[ - 'intValue' - ] as number; - } - dbattributes.push(dbattribute); + dbLog.attributes = dbattributes; } - dbLog.attributes = dbattributes; - dbLogs.push(dbLog); } diff --git a/Model/AnalyticsModels/Log.ts b/Model/AnalyticsModels/Log.ts index 3bd5ebcb44..46777f67f2 100644 --- a/Model/AnalyticsModels/Log.ts +++ b/Model/AnalyticsModels/Log.ts @@ -1,24 +1,3 @@ -/** - * CREATE TABLE opentelemetry_logs -( - trace_id String, - span_id String, - name String, - time DateTime('UTC'), - body String, - attributes Nested - ( - key String, - value String - ), - flags Int32, - severity_number Int32, - severity_text String -) ENGINE = MergeTree() -ORDER BY (trace_id, span_id); - - */ - import AnalyticsBaseModel from 'Common/AnalyticsModels/BaseModel'; import AnalyticsTableColumn from 'Common/Types/AnalyticsDatabase/TableColumn'; import TableColumnType from 'Common/Types/AnalyticsDatabase/TableColumnType'; diff --git a/Model/AnalyticsModels/Span.ts b/Model/AnalyticsModels/Span.ts index 7eb9e3cacd..a7f3b15f78 100644 --- a/Model/AnalyticsModels/Span.ts +++ b/Model/AnalyticsModels/Span.ts @@ -1,49 +1,3 @@ -/** - * - * - * CREATE TABLE opentelemetry_spans -( - trace_id String, - span_id String, - trace_state String, - parent_span_id String, - name String, - kind Int32, - start_time DateTime('UTC'), - end_time DateTime('UTC'), - attributes Nested - ( - key String, - value String - ), - events Nested - ( - time DateTime('UTC'), - name String, - attributes Nested - ( - key String, - value String - ) - ), - links Nested - ( - trace_id String, - span_id String, - trace_state String, - attributes Nested - ( - key String, - value String - ) - ), - status_code Int32, - status_message String -) ENGINE = MergeTree() -ORDER BY (trace_id, span_id); - - */ - import AnalyticsBaseModel from 'Common/AnalyticsModels/BaseModel'; import AnalyticsTableColumn from 'Common/Types/AnalyticsDatabase/TableColumn'; import TableColumnType from 'Common/Types/AnalyticsDatabase/TableColumnType';