@edirect/trace 11.0.44 → 11.0.45

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edirect/trace",
3
- "version": "11.0.44",
3
+ "version": "11.0.45",
4
4
  "description": "Edirect trace",
5
5
  "packageScope": "@edirect",
6
6
  "main": "./dist/src/index.js",
package/dist/README.md DELETED
@@ -1,417 +0,0 @@
1
- # @edirect/trace
2
-
3
- **DEPRECATED! Stop Using it!**
4
-
5
- `@edirect/trace` provides OpenTelemetry-based distributed tracing for Node.js, NestJS, Express, and NextJS applications in the Bolttech ecosystem. It enables deep visibility into business flows, exceptions, and service interactions, supporting both automatic and manual instrumentation.
6
-
7
- ---
8
-
9
- ## Background
10
-
11
- 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.
12
-
13
- 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.
14
-
15
- - Non-standard logs
16
- - The log format and content depends on implementation and log uniformity is a challenge by itself.
17
- - Logs might be outdated or absent
18
- - 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.
19
- - Logs are difficult to query and trace
20
- - 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.
21
- - 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.
22
- - Not able to trace all exception occurrences
23
- - In the case shown by the previous item the error was not logged or at least not easily accessible.
24
- - Sales triggers are not flexible
25
- - Triggers are configured as code in the sales checker service. Any change to the logic must be implemented, tested and deployed.
26
- - Sales alert do not provide insight into root causes
27
- - 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.
28
- - Limited business process visibility
29
- - 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.
30
- - No concise view of the business flow
31
- - Currently there are no dashboards or easily accessible views that can provide correlated information about the many steps that compose the Bolttech business flow.
32
-
33
- ## Detailed Design
34
-
35
- To fill the gaps that the current approach, the proposed solution must fulfill some requirements:
36
-
37
- - Requires minimal code and service changes
38
- - Must be flexible and configurable
39
- - Must capable of querying multiple data sources
40
- - Must be an evolutive tool that can help multiple types of users
41
- - Must have a dashboard that shows useful information about business flow
42
-
43
- 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.
44
-
45
- ![image](./docs/architecture.png)
46
-
47
- ## Usage
48
-
49
- - Tracing Apps
50
- - Datadog
51
- - Services and Observability
52
- - [Service Visibility Frontend](https://bitbucket.org/gofrank/service-visibility-frontend/src/main/)
53
- - [Service Visibility Backend](https://bitbucket.org/gofrank/service-visibility-backend/src/main/)
54
-
55
- ## Sample Application
56
-
57
- - [Service Visibility Samples](https://bitbucket.org/gofrank/service-visibility-samples/src/master/)
58
- 1. Expressjs Sample
59
-
60
- https://bitbucket.org/gofrank/service-visibility-samples/src/master/samples/api/
61
-
62
- 2. Nest-app Sample
63
-
64
- https://bitbucket.org/gofrank/service-visibility-samples/src/master/samples/quote-nestapp/
65
-
66
- ## NestJS Applications
67
-
68
- NestJs applications **should be upgraded to version 9.**
69
-
70
- - Just the fact of upgrade the nest-app to version 9 will able the service to ship all logs to the service visibility
71
-
72
- 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
73
-
74
- In case of impossibility to upgrade, use the "Other" instructions using `@edirect/trace` directly
75
-
76
- 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
77
-
78
- - [@edirect/nest-app:9](https://bitbucket.org/gofrank/nest-app/src/master/)
79
- 1. Upgrade nest-app, all edirect dependencies and all nestjs dependencies
80
-
81
- 2. We should initialize our application with `otel` as a requirement for node startup command:
82
-
83
- ```bash
84
- node --require ./node_modules/@edirect/trace/dist/otel.js dist/main
85
- ```
86
-
87
- (dist/main or your application entrypoint)
88
-
89
- 3. Remove the old client initialization as we moved it to the node require
90
-
91
- If the service was using old trace version
92
-
93
- ```js
94
- const config = require('config');
95
- const {
96
- services: { APM },
97
- middlewares: traceMiddlewares,
98
- } = require('@edirect/trace');
99
- const apmConfig = config.get('apm');
100
-
101
- if (apmConfig.enabled) {
102
- const apm = new APM(
103
- apmConfig.service,
104
- apmConfig.url,
105
- apmConfig.traceServer
106
- );
107
- apm.startTrace();
108
- }
109
- ```
110
-
111
- 4. Remove the middleware usage
112
-
113
- If the service was using old trace version
114
-
115
- Remove it completely as we moved it to inside of `@edirect/trace`:
116
-
117
- ```js
118
- if (apmConfig.enabled) {
119
- app.use(new traceMiddlewares.Body().body);
120
- }
121
- ```
122
-
123
- ## NextJS Applications
124
-
125
- NextJS applications **should be upgraded to version 12 or above**.
126
-
127
- 1. Install the trace package:
128
-
129
- ```bash
130
- npm install --save @edirect/trace
131
- ```
132
-
133
- 2. Create a middleware
134
- - When you upgrade the NextJS application to the version 12(or above) you will be able
135
- to use [Middlewares](https://nextjs.org/docs/advanced-features/middleware).
136
-
137
- Create a file called as `middleware.ts(or .js)` inside of the `src` folder.
138
-
139
- ```ts
140
- import { NextResponse } from 'next/server';
141
- import type { NextRequest } from 'next/server';
142
- import NextJsTracer from '@edirect/trace/dist/middlewares/nextjs';
143
-
144
- // This function can be marked `async` if using `await` inside
145
- export function middleware(request: NextRequest) {
146
- // @edirect/trace
147
- new NextJsTracer().body(req as unknown as Request & Record<string, unknown>);
148
- NextResponse.next();
149
- }
150
- ```
151
-
152
- 3. Install dotenv and create a dotenv.config
153
-
154
- ```bash
155
- npm install --save dotenv
156
- ```
157
-
158
- `dotenv.config.js`
159
-
160
- ```js
161
- const dotenv = require('dotenv');
162
- const nodeEnv = process.env.NODE_ENV || 'development';
163
-
164
- dotenv.config({ path: `.${nodeEnv}.env` });
165
- ```
166
-
167
- 4. Add the environment variables to your NextJS app:
168
- **Example:**`.development.env`
169
-
170
- ```yml
171
- ## OPEN TELEMETRY
172
- TRACE_TAG_OWNER=OWNER
173
- TRACE_TAG_SCOPE=ie
174
- TRACE_TAG_SERVICENAME=frontend-v2
175
- TRACE_TAG_TENANT={STAGE}-{INSTANCE}
176
- TRACE_SERVER_URL={URL}
177
- TRACE_TAG_SERVICE=frontend-v2-{STAGE}-{INSTANCE}
178
- TRACE_TAG_VERSION=1.0.0
179
- TRACE_TAG_CLUSTER=stag-ie
180
- TRACE_TAG_ENV=ie-stag-broker
181
- ```
182
-
183
- 5. Serve your production build on the standalone mode. Add this line to your `next.config.js` file
184
-
185
- ```js
186
- module.exports = {
187
- // ...myOtherSettings
188
- output: 'standalone',
189
- };
190
- ```
191
-
192
- 6. Change the **start** and **dev** command:
193
- ```json
194
- {
195
- "scripts": {
196
- "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",
197
- "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"
198
- }
199
- }
200
- ```
201
-
202
- ## Other (Not nest-app:9)
203
-
204
- ### If you are unable to update to nest 9 or is not nest (express)
205
-
206
- - [@edirect/trace](https://bitbucket.org/gofrank/trace/src/master/)
207
-
208
- The usage of `@edirect/trace` will need your care to inject our middleware to log all requests from the app
209
- 1. Install the trace package
210
-
211
- ```bash
212
- npm install --save @edirect/trace
213
- ```
214
-
215
- 2. Import the trace package
216
-
217
- ```js
218
- import { middlewares as traceMiddlewares } from '@edirect/trace';
219
- ```
220
-
221
- 3. Add the trace middleware to your application routes
222
-
223
- Express:
224
-
225
- ```js
226
- app.use(new traceMiddlewares.Body().body);
227
- ```
228
-
229
- NestJs with nest-app:
230
-
231
- ```js
232
- consumer
233
- .apply(new traceMiddlewares.Body().body)
234
- .forRoutes({ path: '/**', method: RequestMethod.ALL });
235
- ```
236
-
237
- 4. We should initialize our application with `otel` as a requirement for node startup command:
238
-
239
- ```bash
240
- node --require ./node_modules/@edirect/trace/dist/otel.js dist/main
241
- ```
242
-
243
- (dist/main or your application entrypoint)
244
-
245
- 5. Remove the old client initialization as we moved it to the node require
246
-
247
- If the service was using old trace version
248
-
249
- ```js
250
- const config = require('config');
251
- const {
252
- services: { APM },
253
- middlewares: traceMiddlewares,
254
- } = require('@edirect/trace');
255
- const apmConfig = config.get('apm');
256
-
257
- if (apmConfig.enabled) {
258
- const apm = new APM(
259
- apmConfig.service,
260
- apmConfig.url,
261
- apmConfig.traceServer
262
- );
263
- apm.startTrace();
264
- }
265
- ```
266
-
267
- 6. Clean the middleware usage
268
-
269
- If the service was using old trace version
270
-
271
- Replace:
272
-
273
- ```js
274
- if (apmConfig.enabled) {
275
- app.use(new traceMiddlewares.Body().body);
276
- }
277
- ```
278
-
279
- with:
280
-
281
- ```js
282
- app.use(new traceMiddlewares.Body().body);
283
- ```
284
-
285
- ## Configuration & Environment Variables
286
-
287
- `@edirect/trace` relies on several environment variables for correct operation. These are typically set in your deployment environment or `.env` files:
288
-
289
- - `TRACE_TAG_OWNER` (string): Owner of the service
290
- - `TRACE_TAG_SCOPE` (string): Tech center or scope
291
- - `TRACE_TAG_SERVICENAME` (string): Service name
292
- - `TRACE_TAG_TENANT` (string): Tenant or namespace
293
- - `TRACE_SERVER_URL` (string): OpenTelemetry collector URL
294
- - `TRACE_TAG_SERVICE` (string): Service identifier
295
- - `TRACE_TAG_VERSION` (string): Service version
296
- - `TRACE_TAG_CLUSTER` (string): Cluster name
297
- - `TRACE_TAG_ENV` (string): Environment (e.g., development, staging, production)
298
-
299
- **Example .env:**
300
-
301
- ```env
302
- TRACE_TAG_OWNER=OWNER
303
- TRACE_TAG_SCOPE=pgw
304
- TRACE_TAG_SERVICENAME=payment-gateway
305
- TRACE_TAG_TENANT=local-paythbroker
306
- TRACE_SERVER_URL=opentelemetry-collector.stag.bolttechpay.net
307
- TRACE_TAG_SERVICE=payment-gateway-local-paythbroker
308
- TRACE_TAG_VERSION=1.0.0
309
- TRACE_TAG_CLUSTER=localhost
310
- TRACE_TAG_ENV=development
311
- ```
312
-
313
- **Note:** Never commit sensitive credentials to version control. Use environment variables or secure secrets management.
314
-
315
- ---
316
-
317
- We created a standard way to deploy our application configurations and simplify its configurations:
318
-
319
- - 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
320
- - `bolttech-broker-asia\staging\config-map.yaml` (or your environment config-map)
321
-
322
- ```yaml
323
- auth: #or your service
324
- trace:
325
- tags:
326
- scope: ie #your tech center
327
- env: ie-stag-broker #current k8s cluster environment
328
- cluster: stag-ie #current k8s cluster
329
- tenant: ${namespace}
330
- service: ${name}-${namespace}
331
- servicename: ${name}
332
- version: '1.0.0'
333
- owner: OWNER
334
- server: opentelemetry-collector.stag.bolttechbroker.net #cluster opentelemetry server
335
- ```
336
-
337
- Then you should generate and apply your brand new configurations:
338
-
339
- 1. Generate
340
-
341
- This command will generate the new configuration files for the services.
342
-
343
- ```bash
344
- # Staging Clusters
345
- edi infra bolttech-broker-asia k8s generate <ENVIRONMENT> <SERVICE>
346
- edi infra bolttech-broker-asia k8s generate stage1-vnbroker rules-engine # VN Example
347
-
348
- # Production Clusters
349
- edi infra <PRODUCTION_BROKER> k8s generate <ENVIRONMENT> <SERVICE>
350
- edi infra bolttech-broker-asia-hk k8s generate live-hkbroker-a policy-issuing-service --prod # HK Example
351
- ```
352
-
353
- 2. Apply
354
-
355
- This command will apply the new configurations and **redeploy** the service on the cluster.
356
-
357
- ```bash
358
- # Staging Clusters
359
- edi infra bolttech-broker-asia k8s apply staging <STAGE/RC> <SERVICE> --redeploy
360
- edi infra bolttech-broker-asia k8s apply staging rc-vnbroker frontend-service --redeploy # VN Example
361
-
362
- # Production Clusters
363
- edi infra <PRODUCTION_BROKER> k8s apply <CLUSTER> <ENVIRONMENT> <SERVICE>
364
- edi infra bolttech-broker-asia-hk k8s apply cluster-a live-hkbroker-a plan-service --prod --redeploy # HK Example
365
- ```
366
-
367
- - Key notes when using the infrastructure repositories:
368
- - 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.
369
- - Make sure to have the most recent version of the `master` branch before running any commands.
370
- - 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**.
371
- - To make things easier, make sure to check the helper script on `edi-cli` project. Located at the `edi-cli-cli` folder.
372
- - Consider hiding the folders of the brokers you will not need to work with. This will greatly improve your navigation inside the project.
373
-
374
- ## Debugging
375
-
376
- - How to debug it on vscode:
377
-
378
- As we don't debug using node command directly, we suggest you to use this in your `.vscode/launch.json`
379
-
380
- ```json
381
- {
382
- "version": "0.2.0",
383
- "configurations": [
384
- {
385
- "type": "node",
386
- "request": "launch",
387
- "name": "Debug with OTEL",
388
- "args": ["${workspaceFolder}/src/main.ts"],
389
- "runtimeArgs": [
390
- "--inspect",
391
- "-r",
392
- "./node_modules/@edirect/trace/dist/otel.js",
393
- "-r",
394
- "tsconfig-paths/register",
395
- "-r",
396
- "ts-node/register"
397
- ],
398
- "console": "integratedTerminal",
399
- "envFile": "${workspaceFolder}/.development.env"
400
- }
401
- ]
402
- }
403
- ```
404
-
405
- and append the OTEL environment variables to your local environments file:
406
-
407
- ```conf
408
- TRACE_TAG_OWNER=OWNER
409
- TRACE_TAG_SCOPE=pgw
410
- TRACE_TAG_SERVICENAME=payment-gateway
411
- TRACE_TAG_TENANT=local-paythbroker
412
- TRACE_SERVER_URL=opentelemetry-collector.stag.bolttechpay.net
413
- TRACE_TAG_SERVICE=payment-gateway-local-paythbroker
414
- TRACE_TAG_VERSION=1.0.0
415
- TRACE_TAG_CLUSTER=localhost
416
- TRACE_TAG_ENV=development
417
- ```
package/dist/package.json DELETED
@@ -1,44 +0,0 @@
1
- {
2
- "name": "@edirect/trace",
3
- "version": "11.0.43",
4
- "description": "Edirect trace",
5
- "main": "./dist/src/index.js",
6
- "types": "./dist/src/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/src/index.js",
10
- "default": "./dist/src/index.js",
11
- "require": "./dist/src/index.js",
12
- "types": "./dist/src/index.d.ts"
13
- },
14
- "./package.json": "./package.json"
15
- },
16
- "files": [
17
- "dist"
18
- ],
19
- "author": "EDirectInsure",
20
- "license": "ISC",
21
- "dependencies": {
22
- "@opentelemetry/api": "^1.9.0",
23
- "@opentelemetry/auto-instrumentations-node": "^0.69.0",
24
- "@opentelemetry/exporter-trace-otlp-http": "^0.211.0",
25
- "@opentelemetry/instrumentation": "^0.211.0",
26
- "@opentelemetry/instrumentation-express": "^0.59.0",
27
- "@opentelemetry/instrumentation-http": "^0.211.0",
28
- "@opentelemetry/resources": "^2.5.0",
29
- "@opentelemetry/sdk-node": "^0.211.0",
30
- "@opentelemetry/sdk-trace-base": "^2.5.0",
31
- "@opentelemetry/sdk-trace-node": "^2.5.0",
32
- "@opentelemetry/semantic-conventions": "^1.39.0",
33
- "cls-hooked": "^4.2.2",
34
- "express-mung": "^0.5.1",
35
- "reflect-metadata": "^0.2.2",
36
- "uuid": "^13.0.0"
37
- },
38
- "devDependencies": {
39
- "@types/express": "^5.0.6",
40
- "@types/node": "^25.0.10",
41
- "typescript": "^5.9.3"
42
- },
43
- "type": "commonjs"
44
- }