Skip to content

Commit

Permalink
Merge pull request #81 from liammclennan/add-traceid-spanid
Browse files Browse the repository at this point in the history
Add traceid spanid
  • Loading branch information
liammclennan authored Mar 19, 2024
2 parents 560e964 + c6cc52a commit 0cbcadf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface RemoteConfig {
export interface SeqEvent {
timestamp: Date
level?: string
traceId?: string
spanId?: string
messageTemplate?: string
properties?: object
exception?: string
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions seq_logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ module.exports = function (safeGlobalBlob, safeGlobalFetch, safeGlobalAbortContr
return {
Timestamp: timestamp,
Level: level,
TraceId: event.traceId?.toString(),
SpanId: event.spanId?.toString(),
MessageTemplate: messageTemplate,
Exception: exception,
Properties: properties
Expand Down
15 changes: 10 additions & 5 deletions test/seq_logger_integration_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {

Expand Down Expand Up @@ -47,21 +47,23 @@ 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);
}

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 + '")'})
Expand All @@ -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;
}
Expand Down

0 comments on commit 0cbcadf

Please sign in to comment.