@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.js CHANGED
@@ -63771,35 +63771,27 @@ var CustomExporter = class {
63771
63771
  uuid: idGenerator.generateTraceId(),
63772
63772
  app_env: isDev ? AppEnv.Dev : AppEnv.Prod
63773
63773
  };
63774
- const otlpLikeStructures = logs2.map((log) => {
63775
- const rawAttributes = {
63776
- ...defaultAttributes,
63777
- ...log.attributes ?? {}
63778
- };
63779
- const attributes = convertAttributesToString(rawAttributes);
63780
- return {
63781
- resource: {
63782
- attributes: {
63783
- ...defaultResourceAttr
63784
- }
63785
- },
63786
- logRecords: [
63787
- {
63788
- timeUnixNano: hrTimeToNanosNumber(log.hrTime),
63789
- observedTimeUnixNano: hrTimeToNanosNumber(log.hrTimeObserved),
63790
- severityNumber: log.severityNumber,
63791
- severityText: log.severityText,
63792
- body: log.body,
63793
- attributes,
63794
- traceId: log.spanContext?.traceId,
63795
- spanId: log.spanContext?.spanId
63796
- }
63797
- ]
63798
- };
63799
- });
63800
- otlpLikeStructures.forEach((structure) => {
63801
- console.log(this.logPrefix + JSON.stringify(structure) + this.logSuffix);
63802
- });
63774
+ const otlpLikeStructure = {
63775
+ resource: {
63776
+ attributes: {
63777
+ ...defaultResourceAttr
63778
+ }
63779
+ },
63780
+ logRecords: logs2.map((log) => ({
63781
+ timeUnixNano: hrTimeToNanosNumber(log.hrTime),
63782
+ observedTimeUnixNano: hrTimeToNanosNumber(log.hrTimeObserved),
63783
+ severityNumber: log.severityNumber,
63784
+ severityText: log.severityText,
63785
+ body: log.body,
63786
+ attributes: convertAttributesToString({
63787
+ ...defaultAttributes,
63788
+ ...log.attributes ?? {}
63789
+ }),
63790
+ traceID: log.spanContext?.traceId,
63791
+ spanID: log.spanContext?.spanId
63792
+ }))
63793
+ };
63794
+ console.log(this.logPrefix + JSON.stringify(otlpLikeStructure) + this.logSuffix);
63803
63795
  resultCallback({
63804
63796
  code: ExportResultCode.SUCCESS
63805
63797
  });
@@ -63879,11 +63871,11 @@ var CustomTraceExporter = class {
63879
63871
  endTimeUnixNano: hrTimeToNanosNumber(span.endTime),
63880
63872
  name: span.name,
63881
63873
  attributes,
63882
- traceId: span.spanContext().traceId,
63883
- spanId: span.spanContext().spanId,
63874
+ traceID: span.spanContext().traceId,
63875
+ spanID: span.spanContext().spanId,
63884
63876
  parentSpanID: span.parentSpanContext?.spanId,
63885
63877
  status: span.status,
63886
- spanKind: SpanKind.SERVER
63878
+ kind: SpanKind.SERVER
63887
63879
  };
63888
63880
  })
63889
63881
  };
@@ -63936,15 +63928,12 @@ var AppOTelSDK = class _AppOTelSDK {
63936
63928
  startContext(headers, name, fn) {
63937
63929
  const carrier = {};
63938
63930
  const customTraceId = headers["rpc-persist-apaas-observability-trace"];
63939
- const upperClass = headers["Rpc-Persist-Apaas-Observability-Trace"];
63940
63931
  if (customTraceId && _AppOTelSDK.CUSTOM_FORMAT_REGEX.test(customTraceId)) {
63941
63932
  carrier["traceparent"] = `00-${customTraceId}-01`;
63942
63933
  }
63943
63934
  const activeContext = propagation.extract(context.active(), carrier);
63944
63935
  const tracer = trace.getTracer("app-core");
63945
63936
  tracer.startActiveSpan(name, {}, activeContext, (span) => {
63946
- span.setAttribute("upperClass", upperClass);
63947
- span.setAttribute("lowerClass", customTraceId);
63948
63937
  fn(span);
63949
63938
  });
63950
63939
  }
@@ -64028,16 +64017,27 @@ function _ts_metadata(k, v) {
64028
64017
  }
64029
64018
  __name(_ts_metadata, "_ts_metadata");
64030
64019
  __name3(_ts_metadata, "_ts_metadata");
64031
- var ObservableService = class {
64020
+ var ObservableService = class _ObservableService {
64032
64021
  static {
64033
- __name(this, "ObservableService");
64022
+ __name(this, "_ObservableService");
64034
64023
  }
64035
64024
  static {
64036
64025
  __name3(this, "ObservableService");
64037
64026
  }
64038
64027
  reqCtx;
64028
+ static _instance = null;
64039
64029
  constructor(reqCtx) {
64040
64030
  this.reqCtx = reqCtx;
64031
+ if (!_ObservableService._instance) {
64032
+ _ObservableService._instance = this;
64033
+ }
64034
+ }
64035
+ /** 获取全局单例(需确保模块已初始化) */
64036
+ static getInstance() {
64037
+ if (!_ObservableService._instance) {
64038
+ throw new Error("[nestjs-observable] ObservableService \u5C1A\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u786E\u4FDD\u5728\u6839\u6A21\u5757\u5F15\u5165 NestjsObservableModule.forRoot()");
64039
+ }
64040
+ return _ObservableService._instance;
64041
64041
  }
64042
64042
  /** 记录日志(自动合并上下文) */
64043
64043
  log(level, message, attributes = {}) {
@@ -64086,6 +64086,15 @@ function _ts_metadata2(k, v) {
64086
64086
  }
64087
64087
  __name(_ts_metadata2, "_ts_metadata2");
64088
64088
  __name3(_ts_metadata2, "_ts_metadata");
64089
+ var OBSERVABLE_SINGLETON = null;
64090
+ function getObservableService() {
64091
+ if (!OBSERVABLE_SINGLETON) {
64092
+ throw new Error("[nestjs-observable] ObservableService \u5C1A\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u786E\u4FDD\u5728\u6839\u6A21\u5757\u5F15\u5165 NestjsObservableModule.forRoot()");
64093
+ }
64094
+ return OBSERVABLE_SINGLETON;
64095
+ }
64096
+ __name(getObservableService, "getObservableService");
64097
+ __name3(getObservableService, "getObservableService");
64089
64098
  var NestjsObservableModule = class _NestjsObservableModule {
64090
64099
  static {
64091
64100
  __name(this, "_NestjsObservableModule");
@@ -64093,7 +64102,9 @@ var NestjsObservableModule = class _NestjsObservableModule {
64093
64102
  static {
64094
64103
  __name3(this, "NestjsObservableModule");
64095
64104
  }
64096
- constructor() {
64105
+ observableService;
64106
+ constructor(observableService) {
64107
+ this.observableService = observableService;
64097
64108
  }
64098
64109
  static forRoot() {
64099
64110
  return {
@@ -64103,6 +64114,7 @@ var NestjsObservableModule = class _NestjsObservableModule {
64103
64114
  }
64104
64115
  onModuleInit() {
64105
64116
  appSdk.start();
64117
+ OBSERVABLE_SINGLETON = this.observableService;
64106
64118
  }
64107
64119
  };
64108
64120
  NestjsObservableModule = _ts_decorate2([
@@ -64119,7 +64131,9 @@ NestjsObservableModule = _ts_decorate2([
64119
64131
  ]
64120
64132
  }),
64121
64133
  _ts_metadata2("design:type", Function),
64122
- _ts_metadata2("design:paramtypes", [])
64134
+ _ts_metadata2("design:paramtypes", [
64135
+ typeof ObservableService === "undefined" ? Object : ObservableService
64136
+ ])
64123
64137
  ], NestjsObservableModule);
64124
64138
  var SpanStatusCode2;
64125
64139
  (function(SpanStatusCode22) {
@@ -64182,7 +64196,12 @@ function Trace(name) {
64182
64196
  }
64183
64197
  descriptor.value = async function(...args) {
64184
64198
  const spanName = name || `${target?.constructor?.name}.${String(propertyKey)}`;
64185
- const contextAttributes = this.reqCtx?.getContext?.() || {};
64199
+ const context2 = this.reqCtx?.getContext?.() || {};
64200
+ const contextAttributes = {
64201
+ user_id: context2.userId || "",
64202
+ app_id: context2.appId || "",
64203
+ tenant_id: context2.tenantId || ""
64204
+ };
64186
64205
  return await appSdk.trace(spanName, async (span) => {
64187
64206
  if (contextAttributes && typeof contextAttributes === "object") {
64188
64207
  span.setAttributes({
@@ -64676,7 +64695,6 @@ var LoggingInterceptor = class {
64676
64695
  }
64677
64696
  this.appLogger.log(`HTTP request started
64678
64697
  url=${req.url}`, "HTTPTraceInterceptor");
64679
- this.appLogger.log(`header: ${JSON.stringify(req.headers)}`, "HTTPHeaderInfo");
64680
64698
  this.traceLogger.logStructured("verbose", "HTTP request started", requestMeta, "HTTPTraceInterceptor");
64681
64699
  let logged = false;
64682
64700
  res.on("finish", () => {