@lark-apaas/nestjs-logger 1.0.2-alpha.22 → 1.0.2-alpha.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.
package/dist/index.cjs CHANGED
@@ -65725,35 +65725,27 @@ var CustomExporter = class {
65725
65725
  uuid: idGenerator.generateTraceId(),
65726
65726
  app_env: isDev ? AppEnv.Dev : AppEnv.Prod
65727
65727
  };
65728
- const otlpLikeStructures = logs2.map((log) => {
65729
- const rawAttributes = {
65730
- ...defaultAttributes,
65731
- ...log.attributes ?? {}
65732
- };
65733
- const attributes = convertAttributesToString(rawAttributes);
65734
- return {
65735
- resource: {
65736
- attributes: {
65737
- ...defaultResourceAttr
65738
- }
65739
- },
65740
- logRecords: [
65741
- {
65742
- timeUnixNano: hrTimeToNanosNumber(log.hrTime),
65743
- observedTimeUnixNano: hrTimeToNanosNumber(log.hrTimeObserved),
65744
- severityNumber: log.severityNumber,
65745
- severityText: log.severityText,
65746
- body: log.body,
65747
- attributes,
65748
- traceId: log.spanContext?.traceId,
65749
- spanId: log.spanContext?.spanId
65750
- }
65751
- ]
65752
- };
65753
- });
65754
- otlpLikeStructures.forEach((structure) => {
65755
- console.log(this.logPrefix + JSON.stringify(structure) + this.logSuffix);
65756
- });
65728
+ const otlpLikeStructure = {
65729
+ resource: {
65730
+ attributes: {
65731
+ ...defaultResourceAttr
65732
+ }
65733
+ },
65734
+ logRecords: logs2.map((log) => ({
65735
+ timeUnixNano: hrTimeToNanosNumber(log.hrTime),
65736
+ observedTimeUnixNano: hrTimeToNanosNumber(log.hrTimeObserved),
65737
+ severityNumber: log.severityNumber,
65738
+ severityText: log.severityText,
65739
+ body: log.body,
65740
+ attributes: convertAttributesToString({
65741
+ ...defaultAttributes,
65742
+ ...log.attributes ?? {}
65743
+ }),
65744
+ traceID: log.spanContext?.traceId,
65745
+ spanID: log.spanContext?.spanId
65746
+ }))
65747
+ };
65748
+ console.log(this.logPrefix + JSON.stringify(otlpLikeStructure) + this.logSuffix);
65757
65749
  resultCallback({
65758
65750
  code: ExportResultCode.SUCCESS
65759
65751
  });
@@ -65833,11 +65825,11 @@ var CustomTraceExporter = class {
65833
65825
  endTimeUnixNano: hrTimeToNanosNumber(span.endTime),
65834
65826
  name: span.name,
65835
65827
  attributes,
65836
- traceId: span.spanContext().traceId,
65837
- spanId: span.spanContext().spanId,
65828
+ traceID: span.spanContext().traceId,
65829
+ spanID: span.spanContext().spanId,
65838
65830
  parentSpanID: span.parentSpanContext?.spanId,
65839
65831
  status: span.status,
65840
- spanKind: SpanKind.SERVER
65832
+ kind: SpanKind.SERVER
65841
65833
  };
65842
65834
  })
65843
65835
  };
@@ -65890,15 +65882,12 @@ var AppOTelSDK = class _AppOTelSDK {
65890
65882
  startContext(headers, name, fn) {
65891
65883
  const carrier = {};
65892
65884
  const customTraceId = headers["rpc-persist-apaas-observability-trace"];
65893
- const upperClass = headers["Rpc-Persist-Apaas-Observability-Trace"];
65894
65885
  if (customTraceId && _AppOTelSDK.CUSTOM_FORMAT_REGEX.test(customTraceId)) {
65895
65886
  carrier["traceparent"] = `00-${customTraceId}-01`;
65896
65887
  }
65897
65888
  const activeContext = propagation.extract(context.active(), carrier);
65898
65889
  const tracer = trace.getTracer("app-core");
65899
65890
  tracer.startActiveSpan(name, {}, activeContext, (span) => {
65900
- span.setAttribute("upperClass", upperClass);
65901
- span.setAttribute("lowerClass", customTraceId);
65902
65891
  fn(span);
65903
65892
  });
65904
65893
  }
@@ -65982,16 +65971,27 @@ function _ts_metadata(k, v) {
65982
65971
  }
65983
65972
  __name(_ts_metadata, "_ts_metadata");
65984
65973
  __name3(_ts_metadata, "_ts_metadata");
65985
- var ObservableService = class {
65974
+ var ObservableService = class _ObservableService {
65986
65975
  static {
65987
- __name(this, "ObservableService");
65976
+ __name(this, "_ObservableService");
65988
65977
  }
65989
65978
  static {
65990
65979
  __name3(this, "ObservableService");
65991
65980
  }
65992
65981
  reqCtx;
65982
+ static _instance = null;
65993
65983
  constructor(reqCtx) {
65994
65984
  this.reqCtx = reqCtx;
65985
+ if (!_ObservableService._instance) {
65986
+ _ObservableService._instance = this;
65987
+ }
65988
+ }
65989
+ /** 获取全局单例(需确保模块已初始化) */
65990
+ static getInstance() {
65991
+ if (!_ObservableService._instance) {
65992
+ throw new Error("[nestjs-observable] ObservableService \u5C1A\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u786E\u4FDD\u5728\u6839\u6A21\u5757\u5F15\u5165 NestjsObservableModule.forRoot()");
65993
+ }
65994
+ return _ObservableService._instance;
65995
65995
  }
65996
65996
  /** 记录日志(自动合并上下文) */
65997
65997
  log(level, message, attributes = {}) {
@@ -66040,6 +66040,15 @@ function _ts_metadata2(k, v) {
66040
66040
  }
66041
66041
  __name(_ts_metadata2, "_ts_metadata2");
66042
66042
  __name3(_ts_metadata2, "_ts_metadata");
66043
+ var OBSERVABLE_SINGLETON = null;
66044
+ function getObservableService() {
66045
+ if (!OBSERVABLE_SINGLETON) {
66046
+ throw new Error("[nestjs-observable] ObservableService \u5C1A\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u786E\u4FDD\u5728\u6839\u6A21\u5757\u5F15\u5165 NestjsObservableModule.forRoot()");
66047
+ }
66048
+ return OBSERVABLE_SINGLETON;
66049
+ }
66050
+ __name(getObservableService, "getObservableService");
66051
+ __name3(getObservableService, "getObservableService");
66043
66052
  var NestjsObservableModule = class _NestjsObservableModule {
66044
66053
  static {
66045
66054
  __name(this, "_NestjsObservableModule");
@@ -66047,7 +66056,9 @@ var NestjsObservableModule = class _NestjsObservableModule {
66047
66056
  static {
66048
66057
  __name3(this, "NestjsObservableModule");
66049
66058
  }
66050
- constructor() {
66059
+ observableService;
66060
+ constructor(observableService) {
66061
+ this.observableService = observableService;
66051
66062
  }
66052
66063
  static forRoot() {
66053
66064
  return {
@@ -66057,6 +66068,7 @@ var NestjsObservableModule = class _NestjsObservableModule {
66057
66068
  }
66058
66069
  onModuleInit() {
66059
66070
  appSdk.start();
66071
+ OBSERVABLE_SINGLETON = this.observableService;
66060
66072
  }
66061
66073
  };
66062
66074
  NestjsObservableModule = _ts_decorate2([
@@ -66073,7 +66085,9 @@ NestjsObservableModule = _ts_decorate2([
66073
66085
  ]
66074
66086
  }),
66075
66087
  _ts_metadata2("design:type", Function),
66076
- _ts_metadata2("design:paramtypes", [])
66088
+ _ts_metadata2("design:paramtypes", [
66089
+ typeof ObservableService === "undefined" ? Object : ObservableService
66090
+ ])
66077
66091
  ], NestjsObservableModule);
66078
66092
  var SpanStatusCode2;
66079
66093
  (function(SpanStatusCode22) {
@@ -66136,7 +66150,12 @@ function Trace(name) {
66136
66150
  }
66137
66151
  descriptor.value = async function(...args) {
66138
66152
  const spanName = name || `${target?.constructor?.name}.${String(propertyKey)}`;
66139
- const contextAttributes = this.reqCtx?.getContext?.() || {};
66153
+ const context2 = this.reqCtx?.getContext?.() || {};
66154
+ const contextAttributes = {
66155
+ user_id: context2.userId || "",
66156
+ app_id: context2.appId || "",
66157
+ tenant_id: context2.tenantId || ""
66158
+ };
66140
66159
  return await appSdk.trace(spanName, async (span) => {
66141
66160
  if (contextAttributes && typeof contextAttributes === "object") {
66142
66161
  span.setAttributes({
@@ -66630,7 +66649,6 @@ var LoggingInterceptor = class {
66630
66649
  }
66631
66650
  this.appLogger.log(`HTTP request started
66632
66651
  url=${req.url}`, "HTTPTraceInterceptor");
66633
- this.appLogger.log(`header: ${JSON.stringify(req.headers)}`, "HTTPHeaderInfo");
66634
66652
  this.traceLogger.logStructured("verbose", "HTTP request started", requestMeta, "HTTPTraceInterceptor");
66635
66653
  let logged = false;
66636
66654
  res.on("finish", () => {