@lark-apaas/observable 1.0.4-alpha.2 → 1.0.4-alpha.4

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
@@ -8842,7 +8842,7 @@ __name(hrTimeToNanosNumber, "hrTimeToNanosNumber");
8842
8842
 
8843
8843
  // package.json
8844
8844
  var package_default = {
8845
- version: "1.0.4-alpha.2"};
8845
+ version: "1.0.4-alpha.3"};
8846
8846
 
8847
8847
  // src/const.ts
8848
8848
  var AppEnv = /* @__PURE__ */ (function(AppEnv2) {
@@ -8874,13 +8874,14 @@ function convertAttributesToString(attributes) {
8874
8874
  }
8875
8875
  __name(convertAttributesToString, "convertAttributesToString");
8876
8876
 
8877
- // src/core/sniping-config.ts
8878
- var SnipingConfigManager = class _SnipingConfigManager {
8877
+ // src/core/point-kill/index.ts
8878
+ var PointKillManager = class _PointKillManager {
8879
8879
  static {
8880
- __name(this, "SnipingConfigManager");
8880
+ __name(this, "PointKillManager");
8881
8881
  }
8882
+ static instance;
8882
8883
  static CONFIG_HEADER_NAME = "x-force-observability-pointkill";
8883
- static config = {
8884
+ config = {
8884
8885
  logs: {
8885
8886
  modules: []
8886
8887
  },
@@ -8891,43 +8892,64 @@ var SnipingConfigManager = class _SnipingConfigManager {
8891
8892
  modules: []
8892
8893
  }
8893
8894
  };
8894
- static getConfig() {
8895
- return this.config;
8895
+ constructor() {
8896
8896
  }
8897
- static getLogConfig() {
8898
- return this.config.logs.modules;
8897
+ static getInstance() {
8898
+ if (!_PointKillManager.instance) {
8899
+ _PointKillManager.instance = new _PointKillManager();
8900
+ }
8901
+ return _PointKillManager.instance;
8899
8902
  }
8900
- static getTraceConfig() {
8901
- return this.config.traces.modules;
8903
+ getConfig() {
8904
+ return this.config;
8902
8905
  }
8903
- static getMetricConfig() {
8904
- return this.config.metrics.modules;
8906
+ updateConfig(newConfig) {
8907
+ this.config = {
8908
+ logs: {
8909
+ modules: [
8910
+ ...newConfig.logs.modules
8911
+ ]
8912
+ },
8913
+ traces: {
8914
+ modules: [
8915
+ ...newConfig.traces.modules
8916
+ ]
8917
+ },
8918
+ metrics: {
8919
+ modules: [
8920
+ ...newConfig.metrics.modules
8921
+ ]
8922
+ }
8923
+ };
8905
8924
  }
8906
- static setConfig(configStr) {
8925
+ setConfig(configStr) {
8907
8926
  if (!configStr) return;
8908
8927
  try {
8909
8928
  const res = JSON.parse(configStr);
8910
8929
  const { logs: logs2, traces, metrics } = res ?? {};
8911
- if (Array.isArray(logs2?.modules)) {
8912
- this.config.logs.modules = logs2.modules;
8913
- }
8914
- if (Array.isArray(traces?.modules)) {
8915
- this.config.traces.modules = traces.modules;
8916
- }
8917
- if (Array.isArray(metrics?.modules)) {
8918
- this.config.metrics.modules = metrics.modules;
8919
- }
8930
+ this.updateConfig({
8931
+ logs: {
8932
+ modules: Array.isArray(logs2?.modules) ? logs2.modules : []
8933
+ },
8934
+ traces: {
8935
+ modules: Array.isArray(traces?.modules) ? traces.modules : []
8936
+ },
8937
+ metrics: {
8938
+ modules: Array.isArray(metrics?.modules) ? metrics.modules : []
8939
+ }
8940
+ });
8920
8941
  } catch (error) {
8921
8942
  console.error("Failed to parse sniping config:", error);
8922
8943
  }
8923
8944
  }
8924
- static updateFromHeaders(headers) {
8925
- const snipingConfig = headers[_SnipingConfigManager.CONFIG_HEADER_NAME];
8945
+ updateFromHeaders(headers) {
8946
+ const snipingConfig = headers[_PointKillManager.CONFIG_HEADER_NAME] || headers[_PointKillManager.CONFIG_HEADER_NAME.toLowerCase()];
8926
8947
  if (snipingConfig) {
8927
8948
  this.setConfig(snipingConfig);
8928
8949
  }
8929
8950
  }
8930
8951
  };
8952
+ var pointKillManager = PointKillManager.getInstance();
8931
8953
 
8932
8954
  // src/core/log-exporter.ts
8933
8955
  var CustomExporter = class {
@@ -8939,8 +8961,9 @@ var CustomExporter = class {
8939
8961
  constructor() {
8940
8962
  }
8941
8963
  export(logs2, resultCallback) {
8942
- const snipingConfig = SnipingConfigManager.getLogConfig();
8943
- if (snipingConfig.includes("*")) {
8964
+ const snipingConfig = pointKillManager.getConfig();
8965
+ console.log("snipingConfig", snipingConfig);
8966
+ if (snipingConfig.logs.modules.includes("*")) {
8944
8967
  resultCallback({
8945
8968
  code: ExportResultCode.SUCCESS
8946
8969
  });
@@ -8948,7 +8971,7 @@ var CustomExporter = class {
8948
8971
  }
8949
8972
  const filteredLogs = logs2.filter((log) => {
8950
8973
  const module = log.attributes?.module;
8951
- if (module && snipingConfig.includes(module)) {
8974
+ if (module && snipingConfig.logs.modules.includes(module)) {
8952
8975
  return false;
8953
8976
  }
8954
8977
  return true;
@@ -9029,8 +9052,9 @@ var CustomTraceExporter = class {
9029
9052
  tracePrefix = "force-trace-prefix";
9030
9053
  traceSuffix = "force-trace-suffix";
9031
9054
  export(spans, resultCallback) {
9032
- const snipingConfig = SnipingConfigManager.getTraceConfig();
9033
- if (snipingConfig.includes("*")) {
9055
+ const snipingConfig = pointKillManager.getConfig();
9056
+ console.log("snipingConfig", snipingConfig);
9057
+ if (snipingConfig.traces.modules.includes("*")) {
9034
9058
  resultCallback({
9035
9059
  code: ExportResultCode.SUCCESS
9036
9060
  });
@@ -9042,10 +9066,11 @@ var CustomTraceExporter = class {
9042
9066
  app_env: isDev ? AppEnv.Dev : AppEnv.Prod
9043
9067
  };
9044
9068
  const finalSpans = spans.filter((span) => {
9045
- const attrs = span.attributes ?? {};
9046
- if (attrs[TraceDropToken]) return false;
9047
- const module = attrs.module;
9048
- if (module && snipingConfig.includes(module)) return false;
9069
+ if ((span.attributes ?? {})[TraceDropToken]) return false;
9070
+ const module = span.attributes?.module;
9071
+ if (module && snipingConfig.traces.modules.includes(module)) {
9072
+ return false;
9073
+ }
9049
9074
  return true;
9050
9075
  });
9051
9076
  if (!finalSpans.length) {
@@ -9135,7 +9160,7 @@ var AppOTelSDK = class _AppOTelSDK {
9135
9160
  * wrapper 形式
9136
9161
  */
9137
9162
  startContext(headers, name, fn) {
9138
- SnipingConfigManager.updateFromHeaders(headers);
9163
+ pointKillManager.updateFromHeaders(headers);
9139
9164
  const carrier = {};
9140
9165
  const customTraceId = headers["rpc-persist-apaas-observability-trace"];
9141
9166
  if (customTraceId && _AppOTelSDK.CUSTOM_FORMAT_REGEX.test(customTraceId)) {