@lark-apaas/observable 1.0.3 → 1.0.4-alpha.1

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.3-alpha.4"};
8845
+ version: "1.0.4-alpha.1"};
8846
8846
 
8847
8847
  // src/const.ts
8848
8848
  var AppEnv = /* @__PURE__ */ (function(AppEnv2) {
@@ -8874,6 +8874,61 @@ function convertAttributesToString(attributes) {
8874
8874
  }
8875
8875
  __name(convertAttributesToString, "convertAttributesToString");
8876
8876
 
8877
+ // src/core/sniping-config.ts
8878
+ var SnipingConfigManager = class _SnipingConfigManager {
8879
+ static {
8880
+ __name(this, "SnipingConfigManager");
8881
+ }
8882
+ static CONFIG_HEADER_NAME = "x-force-observability-pointkill";
8883
+ static config = {
8884
+ logs: {
8885
+ module: []
8886
+ },
8887
+ traces: {
8888
+ module: []
8889
+ },
8890
+ metrics: {
8891
+ module: []
8892
+ }
8893
+ };
8894
+ static getConfig() {
8895
+ return this.config;
8896
+ }
8897
+ static getLogConfig() {
8898
+ return this.config.logs.module;
8899
+ }
8900
+ static getTraceConfig() {
8901
+ return this.config.traces.module;
8902
+ }
8903
+ static getMetricConfig() {
8904
+ return this.config.metrics.module;
8905
+ }
8906
+ static setConfig(configStr) {
8907
+ if (!configStr) return;
8908
+ try {
8909
+ const res = JSON.parse(configStr);
8910
+ const { logs: logs2, traces, metrics } = res ?? {};
8911
+ if (Array.isArray(logs2?.module)) {
8912
+ this.config.logs.module = logs2.module;
8913
+ }
8914
+ if (Array.isArray(traces?.module)) {
8915
+ this.config.traces.module = traces.module;
8916
+ }
8917
+ if (Array.isArray(metrics?.module)) {
8918
+ this.config.metrics.module = metrics.module;
8919
+ }
8920
+ } catch (error) {
8921
+ console.error("Failed to parse sniping config:", error);
8922
+ }
8923
+ }
8924
+ static updateFromHeaders(headers) {
8925
+ const snipingConfig = headers[_SnipingConfigManager.CONFIG_HEADER_NAME];
8926
+ if (snipingConfig) {
8927
+ this.setConfig(snipingConfig);
8928
+ }
8929
+ }
8930
+ };
8931
+
8877
8932
  // src/core/log-exporter.ts
8878
8933
  var CustomExporter = class {
8879
8934
  static {
@@ -8884,6 +8939,26 @@ var CustomExporter = class {
8884
8939
  constructor() {
8885
8940
  }
8886
8941
  export(logs2, resultCallback) {
8942
+ const snipingConfig = SnipingConfigManager.getLogConfig();
8943
+ if (snipingConfig.includes("*")) {
8944
+ resultCallback({
8945
+ code: ExportResultCode.SUCCESS
8946
+ });
8947
+ return;
8948
+ }
8949
+ const filteredLogs = logs2.filter((log) => {
8950
+ const module = log.attributes?.module;
8951
+ if (module && snipingConfig.includes(module)) {
8952
+ return false;
8953
+ }
8954
+ return true;
8955
+ });
8956
+ if (filteredLogs.length === 0) {
8957
+ resultCallback({
8958
+ code: ExportResultCode.SUCCESS
8959
+ });
8960
+ return;
8961
+ }
8887
8962
  const isDev = process.env.NODE_ENV === "development";
8888
8963
  const defaultAttributes = {
8889
8964
  uuid: idGenerator.generateTraceId(),
@@ -8895,7 +8970,7 @@ var CustomExporter = class {
8895
8970
  ...defaultResourceAttr
8896
8971
  }
8897
8972
  },
8898
- logRecords: logs2.map((log) => ({
8973
+ logRecords: filteredLogs.map((log) => ({
8899
8974
  timeUnixNano: hrTimeToNanosNumber(log.hrTime),
8900
8975
  observedTimeUnixNano: hrTimeToNanosNumber(log.hrTimeObserved),
8901
8976
  severityNumber: log.severityNumber,
@@ -8954,12 +9029,25 @@ var CustomTraceExporter = class {
8954
9029
  tracePrefix = "force-trace-prefix";
8955
9030
  traceSuffix = "force-trace-suffix";
8956
9031
  export(spans, resultCallback) {
9032
+ const snipingConfig = SnipingConfigManager.getTraceConfig();
9033
+ if (snipingConfig.includes("*")) {
9034
+ resultCallback({
9035
+ code: ExportResultCode.SUCCESS
9036
+ });
9037
+ return;
9038
+ }
8957
9039
  const isDev = process.env.NODE_ENV === "development";
8958
9040
  const defaultAttributes = {
8959
9041
  uuid: idGenerator.generateTraceId(),
8960
9042
  app_env: isDev ? AppEnv.Dev : AppEnv.Prod
8961
9043
  };
8962
- const finalSpans = spans.filter((span) => !(span.attributes ?? {})[TraceDropToken]);
9044
+ 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;
9049
+ return true;
9050
+ });
8963
9051
  if (!finalSpans.length) {
8964
9052
  resultCallback({
8965
9053
  code: ExportResultCode.SUCCESS
@@ -9047,6 +9135,7 @@ var AppOTelSDK = class _AppOTelSDK {
9047
9135
  * wrapper 形式
9048
9136
  */
9049
9137
  startContext(headers, name, fn) {
9138
+ SnipingConfigManager.updateFromHeaders(headers);
9050
9139
  const carrier = {};
9051
9140
  const customTraceId = headers["rpc-persist-apaas-observability-trace"];
9052
9141
  if (customTraceId && _AppOTelSDK.CUSTOM_FORMAT_REGEX.test(customTraceId)) {