Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add correlation ID to all use cases and send it to backbone #268

Merged
merged 10 commits into from
Sep 13, 2024
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/transport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@nmshd/core-types": "*",
"@nmshd/crypto": "2.0.6",
"axios": "^1.7.7",
"correlation-id": "^5.2.0",
"fast-json-patch": "^3.1.1",
"form-data": "^4.0.0",
"https-proxy-agent": "^7.0.5",
Expand Down
7 changes: 7 additions & 0 deletions packages/transport/src/core/backbone/RESTClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ILogger } from "@js-soft/logging-abstractions";
import { CoreBuffer } from "@nmshd/crypto";
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
import correlationIdWrapper from "correlation-id";
import formDataLib from "form-data";
import { AgentOptions } from "http";
import { AgentOptions as HTTPSAgentOptions } from "https";
Expand Down Expand Up @@ -114,6 +115,12 @@ export class RESTClient {
this._logger = TransportLoggerFactory.getLogger(RESTClient);

this.axiosInstance = axios.create(resultingRequestConfig);
this.axiosInstance.interceptors.request.use((config) => {
const correlationId = correlationIdWrapper.getId();
config.headers["x-correlation-id"] = correlationId;
return config;
});

if (this.config.debug) {
this.addAxiosLoggingInterceptors(this.axiosInstance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe("AuthenticationTest", function () {
testAccount = accounts[0];
interceptor = new RequestInterceptor((testAccount.authenticator as any).authClient);
});

afterAll(async function () {
await testAccount.close();
await connection.close();
Expand Down