@pristine-ts/networking 2.0.6 → 2.0.8

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.
@@ -18,4 +18,5 @@ __exportStar(require("./body-mapping.request-interceptor"), exports);
18
18
  __exportStar(require("./default-content-type-response-header.interceptor"), exports);
19
19
  __exportStar(require("./request-body-converter.interceptor"), exports);
20
20
  __exportStar(require("./response-headers.interceptor"), exports);
21
+ __exportStar(require("./trace-enrichment.interceptor"), exports);
21
22
  //# sourceMappingURL=interceptors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../../../../src/interceptors/interceptors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qEAAmD;AACnD,qFAAmE;AACnE,uEAAqD;AACrD,iEAA+C"}
1
+ {"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../../../../src/interceptors/interceptors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qEAAmD;AACnD,qFAAmE;AACnE,uEAAqD;AACrD,iEAA+C;AAC/C,iEAA+C"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.TraceEnrichmentInterceptor = void 0;
25
+ const common_1 = require("@pristine-ts/common");
26
+ const tsyringe_1 = require("tsyringe");
27
+ const telemetry_1 = require("@pristine-ts/telemetry");
28
+ const networking_module_keyname_1 = require("../networking.module.keyname");
29
+ /**
30
+ * Stamps the active trace's `context` with the request's HTTP metadata
31
+ * (`http.method`, `http.path`, `http.statusCode`) once the response is known.
32
+ *
33
+ * This makes the trace self-describing: any tracer that persists the trace — the
34
+ * observability store in particular — can render a meaningful request listing
35
+ * (method · path · status) without a separate request log.
36
+ *
37
+ * Mutation goes through `TracingManager.addToTraceContext` rather than touching the
38
+ * trace object directly; path extraction lives on `Request.getPath()` rather than in
39
+ * the interceptor. The interceptor itself becomes pure glue between two collaborators.
40
+ *
41
+ * Best-effort: enrichment never alters or fails the response. No-op when there is no
42
+ * active trace (e.g. tracing disabled).
43
+ */
44
+ let TraceEnrichmentInterceptor = class TraceEnrichmentInterceptor {
45
+ constructor(tracingManager) {
46
+ this.tracingManager = tracingManager;
47
+ }
48
+ interceptResponse(response, request, methodNode) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ try {
51
+ this.tracingManager.addToTraceContext({
52
+ "http.method": String(request.httpMethod),
53
+ "http.path": request.getPath(),
54
+ "http.statusCode": String(response.status),
55
+ });
56
+ }
57
+ catch (_a) {
58
+ // Enrichment is purely observational — never let it affect the response.
59
+ }
60
+ return response;
61
+ });
62
+ }
63
+ };
64
+ exports.TraceEnrichmentInterceptor = TraceEnrichmentInterceptor;
65
+ exports.TraceEnrichmentInterceptor = TraceEnrichmentInterceptor = __decorate([
66
+ (0, common_1.tag)(common_1.ServiceDefinitionTagEnum.RequestInterceptor),
67
+ (0, common_1.moduleScoped)(networking_module_keyname_1.NetworkingModuleKeyname),
68
+ (0, tsyringe_1.injectable)(),
69
+ __param(0, (0, tsyringe_1.inject)("TracingManagerInterface")),
70
+ __metadata("design:paramtypes", [telemetry_1.TracingManager])
71
+ ], TraceEnrichmentInterceptor);
72
+ //# sourceMappingURL=trace-enrichment.interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-enrichment.interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/trace-enrichment.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAmG;AACnG,uCAA4C;AAC5C,sDAAsD;AACtD,4EAAqE;AAIrE;;;;;;;;;;;;;;GAcG;AAII,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAErC,YACsD,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAEpF,CAAC;IAEK,iBAAiB,CAAC,QAAkB,EAAE,OAAgB,EAAE,UAA6B;;YACzF,IAAI,CAAC;gBACH,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC;oBACpC,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;oBACzC,WAAW,EAAE,OAAO,CAAC,OAAO,EAAE;oBAC9B,iBAAiB,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;iBAC3C,CAAC,CAAC;YACL,CAAC;YAAC,WAAM,CAAC;gBACP,yEAAyE;YAC3E,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;KAAA;CACF,CAAA;AApBY,gEAA0B;qCAA1B,0BAA0B;IAHtC,IAAA,YAAG,EAAC,iCAAwB,CAAC,kBAAkB,CAAC;IAChD,IAAA,qBAAY,EAAC,mDAAuB,CAAC;IACrC,IAAA,qBAAU,GAAE;IAIR,WAAA,IAAA,iBAAM,EAAC,yBAAyB,CAAC,CAAA;qCAAkC,0BAAc;GAHzE,0BAA0B,CAoBtC"}