From 6288f442e42f7ea9faefd8f3271353f1e9bb5af2 Mon Sep 17 00:00:00 2001 From: Liam McLennan Date: Tue, 19 Mar 2024 13:33:54 +1000 Subject: [PATCH 1/3] Add support for traceId and spanId --- index.d.ts | 2 ++ seq_logger.js | 2 ++ test/seq_logger_integration_tests.js | 15 ++++++++++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index bc6ea7a..d3abc96 100644 --- a/index.d.ts +++ b/index.d.ts @@ -20,6 +20,8 @@ export interface RemoteConfig { export interface SeqEvent { timestamp: Date level?: string + traceId?: string + spanId?: string messageTemplate?: string properties?: object exception?: string diff --git a/seq_logger.js b/seq_logger.js index 2920828..2325d9d 100644 --- a/seq_logger.js +++ b/seq_logger.js @@ -117,6 +117,8 @@ module.exports = function (safeGlobalBlob, safeGlobalFetch, safeGlobalAbortContr return { Timestamp: timestamp, Level: level, + TraceId: event.traceId, + SpanId: event.spanId, MessageTemplate: messageTemplate, Exception: exception, Properties: properties diff --git a/test/seq_logger_integration_tests.js b/test/seq_logger_integration_tests.js index 5e252c8..dcda1e9 100644 --- a/test/seq_logger_integration_tests.js +++ b/test/seq_logger_integration_tests.js @@ -10,7 +10,7 @@ const serverUrlHttp = '[CONFIGURE_URL_HERE]'; const serverUrlHttps = '[CONFIGURE_URL_HERE]'; const storeGracePeriodInMs = 1000; // required if authentication is turned on -const apiKeyWithUserLevelPermissions = null; +const apiKeyWithUserLevelPermissions = null; describe('SeqLogger', () => { @@ -47,7 +47,7 @@ function testEmitAndVerifyStored(url, apiKey, done) { logger.emit(event); setTimeout(() => { - verifyMarkerStored(event.properties.testMarker, url, apiKey, done); + verifyMarkerStored(event.properties.testMarker, event.traceId, event.spanId, url, apiKey, done); }, storeGracePeriodInMs); } @@ -55,13 +55,15 @@ function makeTestEvent() { return { level: 'Error', timestamp: new Date(), + traceId: '6112be4ab9f113c499dbf4817e503a69', + spanId: '2f2b39a596fc76cd', messageTemplate: 'Event produced by integration test', exception: 'Some error at some file on some line', properties: { testMarker: uuid.v4() } }; } -function verifyMarkerStored(testMarker, url, apiKey, callback) { +function verifyMarkerStored(testMarker, traceId, spanId, url, apiKey, callback) { request.get(url + '/api/events') .query({count: 1, filter: 'Equal(testMarker, @"' + testMarker + '")'}) @@ -71,11 +73,14 @@ function verifyMarkerStored(testMarker, url, apiKey, callback) { callback(err); return; } - + if(res.body instanceof Array && res.body.length === 1 && res.body[0].Properties - && res.body[0].Properties.some(item => item.Name === "testMarker" && item.Value === testMarker)) { + && res.body[0].Properties.some(item => item.Name === "testMarker" && item.Value === testMarker) + && res.body[0].TraceId === traceId + && res.body[0].SpanId === spanId + ) { callback(); return; } From 1cf0d6c981c8f1fce54450be35201a449cbf9902 Mon Sep 17 00:00:00 2001 From: Liam McLennan Date: Tue, 19 Mar 2024 13:42:28 +1000 Subject: [PATCH 2/3] update version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1ec929f..23ec144 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "seq-logging", - "version": "2.1.1", + "version": "2.2.0", "description": "Sends structured log events to the Seq HTTP ingestion API", "keywords": [ "seq", From c6cc52a47928d403e8c19d1d705dda639d5f269c Mon Sep 17 00:00:00 2001 From: Liam McLennan Date: Tue, 19 Mar 2024 13:42:47 +1000 Subject: [PATCH 3/3] handle non-string traceid and spanid --- seq_logger.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seq_logger.js b/seq_logger.js index 2325d9d..710f6f6 100644 --- a/seq_logger.js +++ b/seq_logger.js @@ -117,8 +117,8 @@ module.exports = function (safeGlobalBlob, safeGlobalFetch, safeGlobalAbortContr return { Timestamp: timestamp, Level: level, - TraceId: event.traceId, - SpanId: event.spanId, + TraceId: event.traceId?.toString(), + SpanId: event.spanId?.toString(), MessageTemplate: messageTemplate, Exception: exception, Properties: properties