@rayondigital/nest-dapr 0.9.60 → 0.9.62

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.
@@ -123,7 +123,7 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
123
123
  }
124
124
  const traceId = context[dapr_context_service_1.DAPR_TRACE_ID_KEY];
125
125
  if (traceId) {
126
- contextService.setTraceId(correlationId);
126
+ contextService.setTraceId(traceId);
127
127
  }
128
128
  }
129
129
  if (invokeWrapperFn) {
@@ -106,6 +106,9 @@ let DaprContextService = class DaprContextService {
106
106
  if (!contextObject[exports.DAPR_CORRELATION_ID_KEY]) {
107
107
  contextObject[exports.DAPR_CORRELATION_ID_KEY] = this.getByKey(exports.DAPR_CORRELATION_ID_KEY);
108
108
  }
109
+ if (!contextObject[exports.DAPR_TRACE_ID_KEY]) {
110
+ contextObject[exports.DAPR_TRACE_ID_KEY] = this.getByKey(exports.DAPR_TRACE_ID_KEY);
111
+ }
109
112
  return contextObject;
110
113
  }
111
114
  catch (error) {
@@ -0,0 +1,4 @@
1
+ import { Attributes, SpanKind } from '@opentelemetry/api';
2
+ import { ClsService } from 'nestjs-cls';
3
+ import { DaprContextService } from '../dapr-context-service';
4
+ export declare function withTracedContext<T>(contextService: ClsService | DaprContextService | undefined, operationName: string, operation: () => Promise<T>, spanKind?: SpanKind, spanAttributes?: Attributes, tracerName?: string): Promise<T>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.withTracedContext = void 0;
13
+ const api_1 = require("@opentelemetry/api");
14
+ const nestjs_cls_1 = require("nestjs-cls");
15
+ const dapr_context_service_1 = require("../dapr-context-service");
16
+ function withTracedContext(contextService, operationName, operation, spanKind = api_1.SpanKind.INTERNAL, spanAttributes = undefined, tracerName = 'nest-dapr') {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ if (!api_1.trace || !api_1.context) {
19
+ return yield operation();
20
+ }
21
+ const tracer = api_1.trace.getTracer(tracerName);
22
+ const activeContext = api_1.context.active();
23
+ if (!activeContext) {
24
+ return yield operation();
25
+ }
26
+ const currentSpan = api_1.trace.getSpan(api_1.context.active());
27
+ const span = currentSpan !== null && currentSpan !== void 0 ? currentSpan : tracer.startSpan(operationName, { attributes: spanAttributes, kind: spanKind !== null && spanKind !== void 0 ? spanKind : api_1.SpanKind.SERVER });
28
+ const isNewSpan = !currentSpan;
29
+ if (contextService === undefined) {
30
+ contextService = nestjs_cls_1.ClsServiceManager.getClsService();
31
+ }
32
+ const spanContext = span.spanContext();
33
+ const traceId = `00-${spanContext.traceId}-${spanContext.spanId}-0${spanContext.traceFlags.toString(16)}`;
34
+ if (contextService instanceof nestjs_cls_1.ClsService) {
35
+ contextService.set(dapr_context_service_1.DAPR_TRACE_ID_KEY, traceId);
36
+ }
37
+ else {
38
+ contextService.setTraceId(traceId);
39
+ }
40
+ return api_1.context.with(api_1.trace.setSpan(activeContext, span), () => __awaiter(this, void 0, void 0, function* () {
41
+ try {
42
+ const result = yield operation();
43
+ if (isNewSpan) {
44
+ span.end();
45
+ }
46
+ return result;
47
+ }
48
+ catch (error) {
49
+ span.recordException(error);
50
+ if (isNewSpan) {
51
+ span.end();
52
+ }
53
+ throw error;
54
+ }
55
+ }));
56
+ });
57
+ }
58
+ exports.withTracedContext = withTracedContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.60",
3
+ "version": "0.9.62",
4
4
  "description": "Develop NestJs microservices using Dapr pubsub, actors and other bindings",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -24,9 +24,12 @@
24
24
  "peerDependencies": {
25
25
  "@nestjs/common": "^10.0.0",
26
26
  "@nestjs/core": "^10.0.0",
27
+ "@opentelemetry/api": "^1.0.0",
28
+ "@opentelemetry/core": "^1.0.0",
29
+ "@opentelemetry/sdk-trace-base": "^1.0.0",
30
+ "eventemitter2": "^6.0.0",
27
31
  "nestjs-cls": "^3.4.0",
28
- "rxjs": "^7.1.0",
29
- "eventemitter2": "^6.0.0"
32
+ "rxjs": "^7.1.0"
30
33
  },
31
34
  "dependencies": {
32
35
  "@dapr/dapr": "^3.3.1",
@@ -35,6 +38,9 @@
35
38
  "devDependencies": {
36
39
  "@nestjs/platform-express": "^10.0.0",
37
40
  "@nestjs/testing": "^10.0.0",
41
+ "@opentelemetry/auto-instrumentations-node": "^0.44.0",
42
+ "@opentelemetry/exporter-trace-otlp-http": "^0.50.0",
43
+ "@opentelemetry/sdk-trace-node": "^1.23.0",
38
44
  "@types/jest": "^29.5.12",
39
45
  "@typescript-eslint/eslint-plugin": "^5.29.0",
40
46
  "eslint": "^8.4.1",