save logs to otel

This commit is contained in:
Simon Larsen 2023-10-23 15:27:22 +01:00
parent 3841b655e5
commit 9fe998a43d
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
5 changed files with 33 additions and 90 deletions

View File

@ -5,5 +5,5 @@
Please use
```bash
dotnet run
dotnet run --urls=http://localhost:7856/
```

View File

@ -6,3 +6,5 @@
2.0
2.0
2.0
2.0
2.0

View File

@ -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<KeyValueNestedModel> = [];
if (attributes) {
for (const attribute of attributes) {
const dbattribute: KeyValueNestedModel =
new KeyValueNestedModel();
dbattribute.key = attribute['key'] as string;
const dbattributes: Array<KeyValueNestedModel> = [];
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);
}

View File

@ -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';

View File

@ -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';