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