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

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.0"};
8846
8846
 
8847
8847
  // src/const.ts
8848
8848
  var AppEnv = /* @__PURE__ */ (function(AppEnv2) {
@@ -8874,6 +8874,55 @@ 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) && Array.isArray(traces?.module) && Array.isArray(metrics?.module)) {
8912
+ this.config = res;
8913
+ }
8914
+ } catch (error) {
8915
+ console.error("Failed to parse sniping config:", error);
8916
+ }
8917
+ }
8918
+ static updateFromHeaders(headers) {
8919
+ const snipingConfig = headers[_SnipingConfigManager.CONFIG_HEADER_NAME];
8920
+ if (snipingConfig) {
8921
+ this.setConfig(snipingConfig);
8922
+ }
8923
+ }
8924
+ };
8925
+
8877
8926
  // src/core/log-exporter.ts
8878
8927
  var CustomExporter = class {
8879
8928
  static {
@@ -8884,6 +8933,26 @@ var CustomExporter = class {
8884
8933
  constructor() {
8885
8934
  }
8886
8935
  export(logs2, resultCallback) {
8936
+ const snipingConfig = SnipingConfigManager.getLogConfig();
8937
+ if (snipingConfig.includes("*")) {
8938
+ resultCallback({
8939
+ code: ExportResultCode.SUCCESS
8940
+ });
8941
+ return;
8942
+ }
8943
+ const filteredLogs = logs2.filter((log) => {
8944
+ const module = log.attributes?.module;
8945
+ if (module && snipingConfig.includes(module)) {
8946
+ return false;
8947
+ }
8948
+ return true;
8949
+ });
8950
+ if (filteredLogs.length === 0) {
8951
+ resultCallback({
8952
+ code: ExportResultCode.SUCCESS
8953
+ });
8954
+ return;
8955
+ }
8887
8956
  const isDev = process.env.NODE_ENV === "development";
8888
8957
  const defaultAttributes = {
8889
8958
  uuid: idGenerator.generateTraceId(),
@@ -8895,7 +8964,7 @@ var CustomExporter = class {
8895
8964
  ...defaultResourceAttr
8896
8965
  }
8897
8966
  },
8898
- logRecords: logs2.map((log) => ({
8967
+ logRecords: filteredLogs.map((log) => ({
8899
8968
  timeUnixNano: hrTimeToNanosNumber(log.hrTime),
8900
8969
  observedTimeUnixNano: hrTimeToNanosNumber(log.hrTimeObserved),
8901
8970
  severityNumber: log.severityNumber,
@@ -8954,12 +9023,25 @@ var CustomTraceExporter = class {
8954
9023
  tracePrefix = "force-trace-prefix";
8955
9024
  traceSuffix = "force-trace-suffix";
8956
9025
  export(spans, resultCallback) {
9026
+ const snipingConfig = SnipingConfigManager.getTraceConfig();
9027
+ if (snipingConfig.includes("*")) {
9028
+ resultCallback({
9029
+ code: ExportResultCode.SUCCESS
9030
+ });
9031
+ return;
9032
+ }
8957
9033
  const isDev = process.env.NODE_ENV === "development";
8958
9034
  const defaultAttributes = {
8959
9035
  uuid: idGenerator.generateTraceId(),
8960
9036
  app_env: isDev ? AppEnv.Dev : AppEnv.Prod
8961
9037
  };
8962
- const finalSpans = spans.filter((span) => !(span.attributes ?? {})[TraceDropToken]);
9038
+ const finalSpans = spans.filter((span) => {
9039
+ const attrs = span.attributes ?? {};
9040
+ if (attrs[TraceDropToken]) return false;
9041
+ const module = attrs.module;
9042
+ if (module && snipingConfig.includes(module)) return false;
9043
+ return true;
9044
+ });
8963
9045
  if (!finalSpans.length) {
8964
9046
  resultCallback({
8965
9047
  code: ExportResultCode.SUCCESS
@@ -9047,6 +9129,7 @@ var AppOTelSDK = class _AppOTelSDK {
9047
9129
  * wrapper 形式
9048
9130
  */
9049
9131
  startContext(headers, name, fn) {
9132
+ SnipingConfigManager.updateFromHeaders(headers);
9050
9133
  const carrier = {};
9051
9134
  const customTraceId = headers["rpc-persist-apaas-observability-trace"];
9052
9135
  if (customTraceId && _AppOTelSDK.CUSTOM_FORMAT_REGEX.test(customTraceId)) {