-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add correlation to all requests and the logger (#222)
* feat: add correlation to all requests and the pattern layout * test: add tests for corelation id * chore: update backbone version * chore: revert eslint update * chore: fix eslint * chore: add more correlation id injections * chore: rename correlation id library * chore: update dependencies * chore: rename launcher output variable * chore: update dependencies in sdk * chore: bump runtime * chore: naming * chore: do not use object.assign * fix: merge conflict * chore: update package-lock * chore: remove tests * test: add test for correlation id via webhooks * chore: pr comments * chore: create new event with http headers * chore: update package-lock * chore: eslint * chore: test naming --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Julian König <[email protected]>
- Loading branch information
1 parent
ecec859
commit 320d07a
Showing
15 changed files
with
139 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
BACKBONE_VERSION=6.5.1 | ||
BACKBONE_VERSION=6.7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { AxiosInstance } from "axios"; | ||
import { randomUUID } from "crypto"; | ||
import { DateTime } from "luxon"; | ||
import { ConnectorClientWithMetadata, Launcher } from "./lib/Launcher"; | ||
import { getTimeout } from "./lib/setTimeout"; | ||
import { establishRelationship } from "./lib/testUtils"; | ||
|
||
const launcher = new Launcher(); | ||
let axiosClient: AxiosInstance; | ||
let connectorClient1: ConnectorClientWithMetadata; | ||
let connectorClient2: ConnectorClientWithMetadata; | ||
let account2Address: string; | ||
const uuidRegex = new RegExp("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"); | ||
|
||
beforeAll(async () => { | ||
[connectorClient1, connectorClient2] = await launcher.launch(2); | ||
axiosClient = connectorClient1["account"]["httpClient"]; | ||
await establishRelationship(connectorClient1, connectorClient2); | ||
account2Address = (await connectorClient2.account.getIdentityInfo()).result.address; | ||
}, getTimeout(30000)); | ||
|
||
afterAll(() => launcher.stop()); | ||
|
||
describe("test the correlation ids", () => { | ||
// eslint-disable-next-line jest/expect-expect | ||
test("should send a random correlation id via webhook", async () => { | ||
connectorClient1._eventBus?.reset(); | ||
|
||
await axiosClient.post<any>("/api/v2/Requests/Outgoing", { | ||
content: { | ||
items: [{ "@type": "ReadAttributeRequestItem", mustBeAccepted: false, query: { "@type": "IdentityAttributeQuery", valueType: "Surname" } }], | ||
expiresAt: DateTime.now().plus({ hour: 1 }).toISO() | ||
}, | ||
peer: account2Address | ||
}); | ||
|
||
await connectorClient1._eventBus?.waitForEvent("consumption.outgoingRequestCreated", (event: any) => { | ||
return uuidRegex.test(event.headers["x-correlation-id"]); | ||
}); | ||
}); | ||
|
||
// eslint-disable-next-line jest/expect-expect | ||
test("should send a custom correlation id via webhook", async () => { | ||
connectorClient1._eventBus?.reset(); | ||
|
||
const customCorrelationId = randomUUID(); | ||
|
||
await axiosClient.post<any>( | ||
"/api/v2/Requests/Outgoing", | ||
{ | ||
content: { | ||
items: [{ "@type": "ReadAttributeRequestItem", mustBeAccepted: false, query: { "@type": "IdentityAttributeQuery", valueType: "Surname" } }], | ||
expiresAt: DateTime.now().plus({ hour: 1 }).toISO() | ||
}, | ||
peer: account2Address | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
{ headers: { "x-correlation-id": customCorrelationId } } | ||
); | ||
|
||
await connectorClient1._eventBus?.waitForEvent("consumption.outgoingRequestCreated", (event: any) => { | ||
return event.headers["x-correlation-id"] === customCorrelationId; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { DataEvent } from "@js-soft/ts-utils"; | ||
import { IncomingHttpHeaders } from "node:http"; | ||
|
||
export class DataEventWithHeaders<T> extends DataEvent<T> { | ||
public readonly headers: IncomingHttpHeaders; | ||
|
||
public constructor(namespace: string, data: T, headers: IncomingHttpHeaders) { | ||
super(namespace, data); | ||
this.headers = headers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters