@edirect/trace 9.0.21 → 9.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/.editorconfig +14 -14
  2. package/.eslintignore +1 -1
  3. package/.eslintrc.js +44 -44
  4. package/.eslintrc.json +159 -159
  5. package/.prettierrc +4 -4
  6. package/README.md +365 -357
  7. package/dist/constants/headers.d.ts +4 -4
  8. package/dist/constants/headers.js +5 -5
  9. package/dist/constants/index.d.ts +1 -1
  10. package/dist/constants/index.js +8 -8
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +31 -29
  13. package/dist/index.js.map +1 -1
  14. package/dist/middlewares/CLS.d.ts +5 -5
  15. package/dist/middlewares/CLS.js +33 -33
  16. package/dist/middlewares/body.d.ts +5 -5
  17. package/dist/middlewares/body.js +66 -54
  18. package/dist/middlewares/body.js.map +1 -1
  19. package/dist/middlewares/index.d.ts +4 -4
  20. package/dist/middlewares/index.js +14 -14
  21. package/dist/middlewares/nextjs.d.ts +5 -5
  22. package/dist/middlewares/nextjs.js +37 -37
  23. package/dist/middlewares/trace.d.ts +5 -5
  24. package/dist/middlewares/trace.js +26 -26
  25. package/dist/otel.d.ts +1 -1
  26. package/dist/otel.js +104 -102
  27. package/dist/otel.js.map +1 -1
  28. package/dist/tsconfig.build.tsbuildinfo +1 -1
  29. package/dist/utils/CLS.d.ts +5 -5
  30. package/dist/utils/CLS.js +41 -41
  31. package/dist/utils/body-prop-tools.d.ts +5 -5
  32. package/dist/utils/body-prop-tools.js +23 -23
  33. package/dist/utils/index.d.ts +3 -3
  34. package/dist/utils/index.js +12 -12
  35. package/dist/utils/trace.d.ts +5 -5
  36. package/dist/utils/trace.js +12 -12
  37. package/dist/version.d.ts +1 -0
  38. package/dist/version.js +5 -0
  39. package/dist/version.js.map +1 -0
  40. package/package.json +43 -41
  41. package/tsconfig.build.json +9 -9
  42. package/dist/services/APM.d.ts +0 -14
  43. package/dist/services/APM.js +0 -58
  44. package/dist/services/APM.js.map +0 -1
  45. package/dist/services/index.d.ts +0 -1
  46. package/dist/services/index.js +0 -9
  47. package/dist/services/index.js.map +0 -1
package/README.md CHANGED
@@ -1,357 +1,365 @@
1
- # Open Telemetry Trace
2
-
3
- ## Background
4
-
5
- Based on application logs and a sales checker service that triggers alerts on a slack channel, the current solution offers some insight into the application but falls short when it comes to deep understanding of exceptions and the general business flow.
6
-
7
- Due to the sheer amount of logs and complex integrations between the application microservices, it is not uncommon to find scenarios where the development team can spend hours tracing the problem back to its origin.
8
-
9
- - Non-standard logs
10
- - The log format and content depends on implementation and log uniformity is a challenge by itself.
11
- - Logs might be outdated or absent
12
- - As services shift, evolve and so should logs. This can be a source for inconsistencies as logs may not be updated or can be wrongly removed during the feature implementation.
13
- - Logs are difficult to query and trace
14
- - Even with the help of tools such Elasticsearch, querying and tracing logs can be a difficult task due to complex interactions among different services in the application.
15
- - As an example, an error response from quote-engine but we only dispose of the policy number to find the root cause. The data provided is not enough for a complete investigation, which may lead to long research.
16
- - Not able to trace all exception occurrences
17
- - In the case shown by the previous item the error was not logged or at least not easily accessible.
18
- - Sales triggers are not flexible
19
- - Triggers are configured as code in the sales checker service. Any change to the logic must be implemented, tested and deployed.
20
- - Sales alert do not provide insight into root causes
21
- - The alert contains only the basic information necessary for an investigation to start. It contains the lead, partner, vertical and a brief description of the problem.
22
- - Limited business process visibility
23
- - As the alerts are based on sale statuses, we have limited insight into the process. With such a limited view we cannot verify which steps represent bottlenecks or are more prone to errors. Useful information for maintaining and improving the system.
24
- - No concise view of the business flow
25
- - Currently there are no dashboards or easily accessible views that can provide correlated information about the many steps that compose the Bolttech business flow.
26
-
27
- ## Detailed Design
28
-
29
- To fill the gaps that the current approach, the proposed solution must fulfill some requirements:
30
-
31
- - Requires minimal code and service changes
32
- - Must be flexible and configurable
33
- - Must capable of querying multiple data sources
34
- - Must be an evolutive tool that can help multiple types of users
35
- - Must have a dashboard that shows useful information about business flow
36
-
37
- Taking the requirements in consideration, the proposed solutions employs an application monitoring tool named Open Telemetry, a microservice responsible for correlating the data captured by the tool and a comprehensive dashboard for the final user.
38
-
39
- ![image](./docs/architecture.png)
40
-
41
- ## Usage
42
-
43
- - Tracing Apps
44
- - Datadog
45
- - Services and Observability
46
- - [Service Visibility Frontend](https://bitbucket.org/gofrank/service-visibility-frontend/src/main/)
47
- - [Service Visibility Backend](https://bitbucket.org/gofrank/service-visibility-backend/src/main/)
48
-
49
- ## Sample application
50
-
51
- - [Service Visibility Samples](https://bitbucket.org/gofrank/service-visibility-samples/src/master/)
52
-
53
- ## NestJS Applications
54
-
55
- NestJs applications __should be upgraded to version 9.__
56
-
57
- - Just the fact of upgrade the nest-app to version 9 will able the service to ship all logs to the service visibility
58
-
59
- As we applied the `@edirect/trace` to the nest-app, we dont need to have the trace part of code on nest-app applications with nest-app version 9
60
-
61
- In case of impossibility to upgrade, use the "Other" instructions using `@edirect/trace` directly
62
-
63
- Integration Service was not able to upgrade because it uses a react-ssr that does not have compatibility with nestjs 9, so, even as a nestjs application, we implemented the "Other" way
64
-
65
- - [@edirect/nest-app:9](https://bitbucket.org/gofrank/nest-app/src/master/)
66
-
67
- 1. Upgrade nest-app, all edirect dependencies and all nestjs dependencies
68
-
69
- 2. We should initialize our application with `otel` as a requirement for node startup command:
70
-
71
- ```bash
72
- node --require ./node_modules/@edirect/trace/dist/otel.js dist/main
73
- ```
74
-
75
- (dist/main or your application entrypoint)
76
-
77
- 3. Remove the old client initialization as we moved it to the node require
78
-
79
- If the service was using old trace version
80
-
81
- ```js
82
- const config = require('config');
83
- const { services: { APM }, middlewares: traceMiddlewares } = require('@edirect/trace');
84
- const apmConfig = config.get('apm');
85
-
86
- if (apmConfig.enabled) {
87
- const apm = new APM(apmConfig.service, apmConfig.url, apmConfig.traceServer);
88
- apm.startTrace();
89
- }
90
- ```
91
-
92
- 4. Remove the middleware usage
93
-
94
- If the service was using old trace version
95
-
96
- Remove it completely as we moved it to inside of `@edirect/trace`:
97
-
98
- ```js
99
- if (apmConfig.enabled) {
100
- app.use(new traceMiddlewares.Body().body);
101
- }
102
- ```
103
-
104
- ## NextJS Applications
105
- NextJS applications __should be upgraded to version 12 or above__.
106
-
107
- 1. Install the trace package:
108
- ```bash
109
- npm install --save @edirect/trace
110
- ```
111
-
112
- 2. Create a middleware
113
-
114
- * When you upgrade the NextJS application to the version 12(or above) you will be able
115
- to use [Middlewares](https://nextjs.org/docs/advanced-features/middleware).
116
-
117
- Create a file called as `middleware.ts(or .js)` inside of the `src` folder.
118
-
119
- ```ts
120
- import { NextResponse } from 'next/server';
121
- import type { NextRequest } from 'next/server';
122
- import NextJsTracer from '@edirect/trace/dist/middlewares/nextjs';
123
-
124
- // This function can be marked `async` if using `await` inside
125
- export function middleware(request: NextRequest) {
126
- // @edirect/trace
127
- new NextJsTracer().body(req as unknown as Request & Record<string, unknown>);
128
- NextResponse.next();
129
- }
130
- ```
131
-
132
- 3. Install dotenv and create a dotenv.config
133
- ```bash
134
- npm install --save dotenv
135
- ```
136
- `dotenv.config.js`
137
- ```js
138
- const dotenv = require('dotenv');
139
- const nodeEnv = process.env.NODE_ENV || 'development';
140
-
141
- dotenv.config({ path: `.${nodeEnv}.env` });
142
- ```
143
-
144
- 4. Add the environment variables to your NextJS app:
145
- __Example:__`.development.env`
146
- ```yml
147
- ## OPEN TELEMETRY
148
- TRACE_TAG_OWNER=OWNER
149
- TRACE_TAG_SCOPE=ie
150
- TRACE_TAG_SERVICENAME=frontend-v2
151
- TRACE_TAG_TENANT={STAGE}-{INSTANCE}
152
- TRACE_SERVER_URL={URL}
153
- TRACE_TAG_SERVICE=frontend-v2-{STAGE}-{INSTANCE}
154
- TRACE_TAG_VERSION=1.0.0
155
- TRACE_TAG_CLUSTER=stag-ie
156
- TRACE_TAG_ENV=ie-stag-broker
157
- ```
158
-
159
- 5. Serve your production build on the standalone mode. Add this line to your `next.config.js` file
160
- ```js
161
- module.exports = {
162
- // ...myOtherSettings
163
- output: 'standalone'
164
- }
165
- ```
166
-
167
- 6. Change the __start__ and __dev__ command:
168
- ```json
169
- {
170
- "scripts": {
171
- "dev": "cross-env NODE_ENV=development node --require ./dotenv.config.js --require ./node_modules/@edirect/trace/dist/otel.js ./node_modules/next/dist/bin/next -p 3100",
172
- "start": "cross-env NODE_ENV=production node --require ./dotenv.config.js --require ./node_modules/@edirect/trace/dist/otel.js ./build/client/standalone/server.js -p 3100"
173
- }
174
- }
175
- ```
176
-
177
-
178
- ## Other (Not nest-app:9)
179
-
180
- ### If you are unable to update to nest 9 or is not nest (express)
181
-
182
- - [@edirect/trace](https://bitbucket.org/gofrank/trace/src/master/)
183
-
184
- The usage of `@edirect/trace` will need your care to inject our middleware to log all requests from the app
185
-
186
- 1. Install the trace package
187
-
188
- ```bash
189
- npm install --save @edirect/trace
190
- ```
191
-
192
- 2. Import the trace package
193
-
194
- ```js
195
- import { middlewares as traceMiddlewares } from '@edirect/trace';
196
- ```
197
-
198
- 3. Add the trace middleware to your application routes
199
-
200
- Express:
201
-
202
- ```js
203
- app.use(new traceMiddlewares.Body().body);
204
- ```
205
-
206
- NestJs with nest-app:
207
-
208
- ```js
209
- consumer
210
- .apply(new traceMiddlewares.Body().body)
211
- .forRoutes({path: '/**', method: RequestMethod.ALL});
212
- ```
213
-
214
- 4. We should initialize our application with `otel` as a requirement for node startup command:
215
-
216
- ```bash
217
- node --require ./node_modules/@edirect/trace/dist/otel.js dist/main
218
- ```
219
-
220
- (dist/main or your application entrypoint)
221
-
222
- 5. Remove the old client initialization as we moved it to the node require
223
-
224
- If the service was using old trace version
225
-
226
- ```js
227
- const config = require('config');
228
- const { services: { APM }, middlewares: traceMiddlewares } = require('@edirect/trace');
229
- const apmConfig = config.get('apm');
230
-
231
- if (apmConfig.enabled) {
232
- const apm = new APM(apmConfig.service, apmConfig.url, apmConfig.traceServer);
233
- apm.startTrace();
234
- }
235
- ```
236
-
237
- 6. Clean the middleware usage
238
-
239
- If the service was using old trace version
240
-
241
- Replace:
242
-
243
- ```js
244
- if (apmConfig.enabled) {
245
- app.use(new traceMiddlewares.Body().body);
246
- }
247
- ```
248
-
249
- with:
250
-
251
- ```js
252
- app.use(new traceMiddlewares.Body().body);
253
- ```
254
-
255
- ## Applying k8s configurations (Required)
256
-
257
- We created a standard way to deploy our application configurations and simplify its configurations:
258
-
259
- - Sometimes it could be already done by another team and you don't need to manage the configuration, just generate the configurations and apply it
260
- - `bolttech-broker-asia\staging\config-map.yaml` (or your environment config-map)
261
-
262
- ```yaml
263
- auth: #or your service
264
- trace:
265
- tags:
266
- scope: ie #your tech center
267
- env: ie-stag-broker #current k8s cluster environment
268
- cluster: stag-ie #current k8s cluster
269
- tenant: ${namespace}
270
- service: ${name}-${namespace}
271
- servicename: ${name}
272
- version: "1.0.0"
273
- owner: OWNER
274
- server: opentelemetry-collector.stag.bolttechbroker.net #cluster opentelemetry server
275
- ```
276
-
277
- Then you should generate and apply your brand new configurations:
278
-
279
- 1. Generate
280
-
281
- This command will generate the new configuration files for the services.
282
-
283
- ```bash
284
- # Staging Clusters
285
- edi infra bolttech-broker-asia k8s generate <ENVIRONMENT> <SERVICE>
286
- edi infra bolttech-broker-asia k8s generate stage1-vnbroker rules-engine # VN Example
287
-
288
- # Production Clusters
289
- edi infra <PRODUCTION_BROKER> k8s generate <ENVIRONMENT> <SERVICE>
290
- edi infra bolttech-broker-asia-hk k8s generate live-hkbroker-a policy-issuing-service --prod # HK Example
291
- ```
292
-
293
- 2. Apply
294
-
295
- This command will apply the new configurations and __redeploy__ the service on the cluster.
296
-
297
- ```bash
298
- # Staging Clusters
299
- edi infra bolttech-broker-asia k8s apply staging <STAGE/RC> <SERVICE> --redeploy
300
- edi infra bolttech-broker-asia k8s apply staging rc-vnbroker frontend-service --redeploy # VN Example
301
-
302
- # Production Clusters
303
- edi infra <PRODUCTION_BROKER> k8s apply <CLUSTER> <ENVIRONMENT> <SERVICE>
304
- edi infra bolttech-broker-asia-hk k8s apply cluster-a live-hkbroker-a plan-service --prod --redeploy # HK Example
305
- ```
306
-
307
- - Key notes when using the infrastructure repositories:
308
- - Before running any command make sure you have completed the setup of the `edi-cli` tool and that you have all the related projects (`infrastructure` and `k8s-templates`) inside the same root folder.
309
- - Make sure to have the most recent version of the `master` branch before running any commands.
310
- - Remember to __ALWAYS COMMIT AND PUSH YOUR CHANGES TO THE REPOSITORIES, OTHERWISE THE NEW CONFIGURATIONS WILL NOT BE APPLIED TO SERVICES WHEN THEY ARE DEPLOYED USING THE JENKINS PIPELINES__.
311
- - To make things easier, make sure to check the helper script on `edi-cli` project. Located at the `edi-cli-cli` folder.
312
- - Consider hiding the folders of the brokers you will not need to work with. This will greatly improve your navigation inside the project.
313
-
314
- ## Debugging
315
-
316
- - How to debug it on vscode:
317
-
318
- As we don't debug using node command directly, we suggest you to use this in your `.vscode/launch.json`
319
-
320
- ```json
321
- {
322
- "version": "0.2.0",
323
- "configurations": [
324
- {
325
- "type": "node",
326
- "request": "launch",
327
- "name": "Debug with OTEL",
328
- "args": ["${workspaceFolder}/src/main.ts"],
329
- "runtimeArgs": [
330
- "--inspect",
331
- "-r",
332
- "./node_modules/@edirect/trace/dist/otel.js",
333
- "-r",
334
- "tsconfig-paths/register",
335
- "-r",
336
- "ts-node/register",
337
- ],
338
- "console": "integratedTerminal",
339
- "envFile": "${workspaceFolder}/.development.env"
340
- },
341
- ]
342
- }
343
- ```
344
-
345
- and append the OTEL environment variables to your local environments file:
346
-
347
- ```conf
348
- TRACE_TAG_OWNER=OWNER
349
- TRACE_TAG_SCOPE=pgw
350
- TRACE_TAG_SERVICENAME=payment-gateway
351
- TRACE_TAG_TENANT=local-paythbroker
352
- TRACE_SERVER_URL=opentelemetry-collector.stag.bolttechpay.net
353
- TRACE_TAG_SERVICE=payment-gateway-local-paythbroker
354
- TRACE_TAG_VERSION=1.0.0
355
- TRACE_TAG_CLUSTER=localhost
356
- TRACE_TAG_ENV=development
357
- ```
1
+ # Open Telemetry Trace
2
+
3
+ ## Background
4
+
5
+ Based on application logs and a sales checker service that triggers alerts on a slack channel, the current solution offers some insight into the application but falls short when it comes to deep understanding of exceptions and the general business flow.
6
+
7
+ Due to the sheer amount of logs and complex integrations between the application microservices, it is not uncommon to find scenarios where the development team can spend hours tracing the problem back to its origin.
8
+
9
+ - Non-standard logs
10
+ - The log format and content depends on implementation and log uniformity is a challenge by itself.
11
+ - Logs might be outdated or absent
12
+ - As services shift, evolve and so should logs. This can be a source for inconsistencies as logs may not be updated or can be wrongly removed during the feature implementation.
13
+ - Logs are difficult to query and trace
14
+ - Even with the help of tools such Elasticsearch, querying and tracing logs can be a difficult task due to complex interactions among different services in the application.
15
+ - As an example, an error response from quote-engine but we only dispose of the policy number to find the root cause. The data provided is not enough for a complete investigation, which may lead to long research.
16
+ - Not able to trace all exception occurrences
17
+ - In the case shown by the previous item the error was not logged or at least not easily accessible.
18
+ - Sales triggers are not flexible
19
+ - Triggers are configured as code in the sales checker service. Any change to the logic must be implemented, tested and deployed.
20
+ - Sales alert do not provide insight into root causes
21
+ - The alert contains only the basic information necessary for an investigation to start. It contains the lead, partner, vertical and a brief description of the problem.
22
+ - Limited business process visibility
23
+ - As the alerts are based on sale statuses, we have limited insight into the process. With such a limited view we cannot verify which steps represent bottlenecks or are more prone to errors. Useful information for maintaining and improving the system.
24
+ - No concise view of the business flow
25
+ - Currently there are no dashboards or easily accessible views that can provide correlated information about the many steps that compose the Bolttech business flow.
26
+
27
+ ## Detailed Design
28
+
29
+ To fill the gaps that the current approach, the proposed solution must fulfill some requirements:
30
+
31
+ - Requires minimal code and service changes
32
+ - Must be flexible and configurable
33
+ - Must capable of querying multiple data sources
34
+ - Must be an evolutive tool that can help multiple types of users
35
+ - Must have a dashboard that shows useful information about business flow
36
+
37
+ Taking the requirements in consideration, the proposed solutions employs an application monitoring tool named Open Telemetry, a microservice responsible for correlating the data captured by the tool and a comprehensive dashboard for the final user.
38
+
39
+ ![image](./docs/architecture.png)
40
+
41
+ ## Usage
42
+
43
+ - Tracing Apps
44
+ - Datadog
45
+ - Services and Observability
46
+ - [Service Visibility Frontend](https://bitbucket.org/gofrank/service-visibility-frontend/src/main/)
47
+ - [Service Visibility Backend](https://bitbucket.org/gofrank/service-visibility-backend/src/main/)
48
+
49
+ ## Sample application
50
+
51
+ - [Service Visibility Samples](https://bitbucket.org/gofrank/service-visibility-samples/src/master/)
52
+
53
+ 1. Expressjs Sample
54
+
55
+ https://bitbucket.org/gofrank/service-visibility-samples/src/master/samples/api/
56
+
57
+ 2. Nest-app Sample
58
+
59
+ https://bitbucket.org/gofrank/service-visibility-samples/src/master/samples/quote-nestapp/
60
+
61
+ ## NestJS Applications
62
+
63
+ NestJs applications __should be upgraded to version 9.__
64
+
65
+ - Just the fact of upgrade the nest-app to version 9 will able the service to ship all logs to the service visibility
66
+
67
+ As we applied the `@edirect/trace` to the nest-app, we dont need to have the trace part of code on nest-app applications with nest-app version 9
68
+
69
+ In case of impossibility to upgrade, use the "Other" instructions using `@edirect/trace` directly
70
+
71
+ Integration Service was not able to upgrade because it uses a react-ssr that does not have compatibility with nestjs 9, so, even as a nestjs application, we implemented the "Other" way
72
+
73
+ - [@edirect/nest-app:9](https://bitbucket.org/gofrank/nest-app/src/master/)
74
+
75
+ 1. Upgrade nest-app, all edirect dependencies and all nestjs dependencies
76
+
77
+ 2. We should initialize our application with `otel` as a requirement for node startup command:
78
+
79
+ ```bash
80
+ node --require ./node_modules/@edirect/trace/dist/otel.js dist/main
81
+ ```
82
+
83
+ (dist/main or your application entrypoint)
84
+
85
+ 3. Remove the old client initialization as we moved it to the node require
86
+
87
+ If the service was using old trace version
88
+
89
+ ```js
90
+ const config = require('config');
91
+ const { services: { APM }, middlewares: traceMiddlewares } = require('@edirect/trace');
92
+ const apmConfig = config.get('apm');
93
+
94
+ if (apmConfig.enabled) {
95
+ const apm = new APM(apmConfig.service, apmConfig.url, apmConfig.traceServer);
96
+ apm.startTrace();
97
+ }
98
+ ```
99
+
100
+ 4. Remove the middleware usage
101
+
102
+ If the service was using old trace version
103
+
104
+ Remove it completely as we moved it to inside of `@edirect/trace`:
105
+
106
+ ```js
107
+ if (apmConfig.enabled) {
108
+ app.use(new traceMiddlewares.Body().body);
109
+ }
110
+ ```
111
+
112
+ ## NextJS Applications
113
+ NextJS applications __should be upgraded to version 12 or above__.
114
+
115
+ 1. Install the trace package:
116
+ ```bash
117
+ npm install --save @edirect/trace
118
+ ```
119
+
120
+ 2. Create a middleware
121
+
122
+ * When you upgrade the NextJS application to the version 12(or above) you will be able
123
+ to use [Middlewares](https://nextjs.org/docs/advanced-features/middleware).
124
+
125
+ Create a file called as `middleware.ts(or .js)` inside of the `src` folder.
126
+
127
+ ```ts
128
+ import { NextResponse } from 'next/server';
129
+ import type { NextRequest } from 'next/server';
130
+ import NextJsTracer from '@edirect/trace/dist/middlewares/nextjs';
131
+
132
+ // This function can be marked `async` if using `await` inside
133
+ export function middleware(request: NextRequest) {
134
+ // @edirect/trace
135
+ new NextJsTracer().body(req as unknown as Request & Record<string, unknown>);
136
+ NextResponse.next();
137
+ }
138
+ ```
139
+
140
+ 3. Install dotenv and create a dotenv.config
141
+ ```bash
142
+ npm install --save dotenv
143
+ ```
144
+ `dotenv.config.js`
145
+ ```js
146
+ const dotenv = require('dotenv');
147
+ const nodeEnv = process.env.NODE_ENV || 'development';
148
+
149
+ dotenv.config({ path: `.${nodeEnv}.env` });
150
+ ```
151
+
152
+ 4. Add the environment variables to your NextJS app:
153
+ __Example:__`.development.env`
154
+ ```yml
155
+ ## OPEN TELEMETRY
156
+ TRACE_TAG_OWNER=OWNER
157
+ TRACE_TAG_SCOPE=ie
158
+ TRACE_TAG_SERVICENAME=frontend-v2
159
+ TRACE_TAG_TENANT={STAGE}-{INSTANCE}
160
+ TRACE_SERVER_URL={URL}
161
+ TRACE_TAG_SERVICE=frontend-v2-{STAGE}-{INSTANCE}
162
+ TRACE_TAG_VERSION=1.0.0
163
+ TRACE_TAG_CLUSTER=stag-ie
164
+ TRACE_TAG_ENV=ie-stag-broker
165
+ ```
166
+
167
+ 5. Serve your production build on the standalone mode. Add this line to your `next.config.js` file
168
+ ```js
169
+ module.exports = {
170
+ // ...myOtherSettings
171
+ output: 'standalone'
172
+ }
173
+ ```
174
+
175
+ 6. Change the __start__ and __dev__ command:
176
+ ```json
177
+ {
178
+ "scripts": {
179
+ "dev": "cross-env NODE_ENV=development node --require ./dotenv.config.js --require ./node_modules/@edirect/trace/dist/otel.js ./node_modules/next/dist/bin/next -p 3100",
180
+ "start": "cross-env NODE_ENV=production node --require ./dotenv.config.js --require ./node_modules/@edirect/trace/dist/otel.js ./build/client/standalone/server.js -p 3100"
181
+ }
182
+ }
183
+ ```
184
+
185
+
186
+ ## Other (Not nest-app:9)
187
+
188
+ ### If you are unable to update to nest 9 or is not nest (express)
189
+
190
+ - [@edirect/trace](https://bitbucket.org/gofrank/trace/src/master/)
191
+
192
+ The usage of `@edirect/trace` will need your care to inject our middleware to log all requests from the app
193
+
194
+ 1. Install the trace package
195
+
196
+ ```bash
197
+ npm install --save @edirect/trace
198
+ ```
199
+
200
+ 2. Import the trace package
201
+
202
+ ```js
203
+ import { middlewares as traceMiddlewares } from '@edirect/trace';
204
+ ```
205
+
206
+ 3. Add the trace middleware to your application routes
207
+
208
+ Express:
209
+
210
+ ```js
211
+ app.use(new traceMiddlewares.Body().body);
212
+ ```
213
+
214
+ NestJs with nest-app:
215
+
216
+ ```js
217
+ consumer
218
+ .apply(new traceMiddlewares.Body().body)
219
+ .forRoutes({path: '/**', method: RequestMethod.ALL});
220
+ ```
221
+
222
+ 4. We should initialize our application with `otel` as a requirement for node startup command:
223
+
224
+ ```bash
225
+ node --require ./node_modules/@edirect/trace/dist/otel.js dist/main
226
+ ```
227
+
228
+ (dist/main or your application entrypoint)
229
+
230
+ 5. Remove the old client initialization as we moved it to the node require
231
+
232
+ If the service was using old trace version
233
+
234
+ ```js
235
+ const config = require('config');
236
+ const { services: { APM }, middlewares: traceMiddlewares } = require('@edirect/trace');
237
+ const apmConfig = config.get('apm');
238
+
239
+ if (apmConfig.enabled) {
240
+ const apm = new APM(apmConfig.service, apmConfig.url, apmConfig.traceServer);
241
+ apm.startTrace();
242
+ }
243
+ ```
244
+
245
+ 6. Clean the middleware usage
246
+
247
+ If the service was using old trace version
248
+
249
+ Replace:
250
+
251
+ ```js
252
+ if (apmConfig.enabled) {
253
+ app.use(new traceMiddlewares.Body().body);
254
+ }
255
+ ```
256
+
257
+ with:
258
+
259
+ ```js
260
+ app.use(new traceMiddlewares.Body().body);
261
+ ```
262
+
263
+ ## Applying k8s configurations (Required)
264
+
265
+ We created a standard way to deploy our application configurations and simplify its configurations:
266
+
267
+ - Sometimes it could be already done by another team and you don't need to manage the configuration, just generate the configurations and apply it
268
+ - `bolttech-broker-asia\staging\config-map.yaml` (or your environment config-map)
269
+
270
+ ```yaml
271
+ auth: #or your service
272
+ trace:
273
+ tags:
274
+ scope: ie #your tech center
275
+ env: ie-stag-broker #current k8s cluster environment
276
+ cluster: stag-ie #current k8s cluster
277
+ tenant: ${namespace}
278
+ service: ${name}-${namespace}
279
+ servicename: ${name}
280
+ version: "1.0.0"
281
+ owner: OWNER
282
+ server: opentelemetry-collector.stag.bolttechbroker.net #cluster opentelemetry server
283
+ ```
284
+
285
+ Then you should generate and apply your brand new configurations:
286
+
287
+ 1. Generate
288
+
289
+ This command will generate the new configuration files for the services.
290
+
291
+ ```bash
292
+ # Staging Clusters
293
+ edi infra bolttech-broker-asia k8s generate <ENVIRONMENT> <SERVICE>
294
+ edi infra bolttech-broker-asia k8s generate stage1-vnbroker rules-engine # VN Example
295
+
296
+ # Production Clusters
297
+ edi infra <PRODUCTION_BROKER> k8s generate <ENVIRONMENT> <SERVICE>
298
+ edi infra bolttech-broker-asia-hk k8s generate live-hkbroker-a policy-issuing-service --prod # HK Example
299
+ ```
300
+
301
+ 2. Apply
302
+
303
+ This command will apply the new configurations and __redeploy__ the service on the cluster.
304
+
305
+ ```bash
306
+ # Staging Clusters
307
+ edi infra bolttech-broker-asia k8s apply staging <STAGE/RC> <SERVICE> --redeploy
308
+ edi infra bolttech-broker-asia k8s apply staging rc-vnbroker frontend-service --redeploy # VN Example
309
+
310
+ # Production Clusters
311
+ edi infra <PRODUCTION_BROKER> k8s apply <CLUSTER> <ENVIRONMENT> <SERVICE>
312
+ edi infra bolttech-broker-asia-hk k8s apply cluster-a live-hkbroker-a plan-service --prod --redeploy # HK Example
313
+ ```
314
+
315
+ - Key notes when using the infrastructure repositories:
316
+ - Before running any command make sure you have completed the setup of the `edi-cli` tool and that you have all the related projects (`infrastructure` and `k8s-templates`) inside the same root folder.
317
+ - Make sure to have the most recent version of the `master` branch before running any commands.
318
+ - Remember to __ALWAYS COMMIT AND PUSH YOUR CHANGES TO THE REPOSITORIES, OTHERWISE THE NEW CONFIGURATIONS WILL NOT BE APPLIED TO SERVICES WHEN THEY ARE DEPLOYED USING THE JENKINS PIPELINES__.
319
+ - To make things easier, make sure to check the helper script on `edi-cli` project. Located at the `edi-cli-cli` folder.
320
+ - Consider hiding the folders of the brokers you will not need to work with. This will greatly improve your navigation inside the project.
321
+
322
+ ## Debugging
323
+
324
+ - How to debug it on vscode:
325
+
326
+ As we don't debug using node command directly, we suggest you to use this in your `.vscode/launch.json`
327
+
328
+ ```json
329
+ {
330
+ "version": "0.2.0",
331
+ "configurations": [
332
+ {
333
+ "type": "node",
334
+ "request": "launch",
335
+ "name": "Debug with OTEL",
336
+ "args": ["${workspaceFolder}/src/main.ts"],
337
+ "runtimeArgs": [
338
+ "--inspect",
339
+ "-r",
340
+ "./node_modules/@edirect/trace/dist/otel.js",
341
+ "-r",
342
+ "tsconfig-paths/register",
343
+ "-r",
344
+ "ts-node/register",
345
+ ],
346
+ "console": "integratedTerminal",
347
+ "envFile": "${workspaceFolder}/.development.env"
348
+ },
349
+ ]
350
+ }
351
+ ```
352
+
353
+ and append the OTEL environment variables to your local environments file:
354
+
355
+ ```conf
356
+ TRACE_TAG_OWNER=OWNER
357
+ TRACE_TAG_SCOPE=pgw
358
+ TRACE_TAG_SERVICENAME=payment-gateway
359
+ TRACE_TAG_TENANT=local-paythbroker
360
+ TRACE_SERVER_URL=opentelemetry-collector.stag.bolttechpay.net
361
+ TRACE_TAG_SERVICE=payment-gateway-local-paythbroker
362
+ TRACE_TAG_VERSION=1.0.0
363
+ TRACE_TAG_CLUSTER=localhost
364
+ TRACE_TAG_ENV=development
365
+ ```