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

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
@@ -520,20 +520,20 @@ var require_errorContext = __commonJS({
520
520
  });
521
521
  exports$1.captureError = exports$1.errorContext = void 0;
522
522
  var config_1 = require_config();
523
- var context2 = null;
523
+ var context4 = null;
524
524
  function errorContext(cb) {
525
525
  if (config_1.config.useDeprecatedSynchronousErrorHandling) {
526
- var isRoot = !context2;
526
+ var isRoot = !context4;
527
527
  if (isRoot) {
528
- context2 = {
528
+ context4 = {
529
529
  errorThrown: false,
530
530
  error: null
531
531
  };
532
532
  }
533
533
  cb();
534
534
  if (isRoot) {
535
- var _a = context2, errorThrown = _a.errorThrown, error = _a.error;
536
- context2 = null;
535
+ var _a = context4, errorThrown = _a.errorThrown, error = _a.error;
536
+ context4 = null;
537
537
  if (errorThrown) {
538
538
  throw error;
539
539
  }
@@ -545,9 +545,9 @@ var require_errorContext = __commonJS({
545
545
  __name(errorContext, "errorContext");
546
546
  exports$1.errorContext = errorContext;
547
547
  function captureError(err) {
548
- if (config_1.config.useDeprecatedSynchronousErrorHandling && context2) {
549
- context2.errorThrown = true;
550
- context2.error = err;
548
+ if (config_1.config.useDeprecatedSynchronousErrorHandling && context4) {
549
+ context4.errorThrown = true;
550
+ context4.error = err;
551
551
  }
552
552
  }
553
553
  __name(captureError, "captureError");
@@ -8844,7 +8844,7 @@ __name(hrTimeToNanosNumber, "hrTimeToNanosNumber");
8844
8844
 
8845
8845
  // package.json
8846
8846
  var package_default = {
8847
- version: "1.0.4-alpha.3"};
8847
+ version: "1.0.4-alpha.4"};
8848
8848
 
8849
8849
  // src/const.ts
8850
8850
  var AppEnv = /* @__PURE__ */ (function(AppEnv2) {
@@ -8876,83 +8876,6 @@ function convertAttributesToString(attributes) {
8876
8876
  }
8877
8877
  __name(convertAttributesToString, "convertAttributesToString");
8878
8878
 
8879
- // src/core/point-kill/index.ts
8880
- var PointKillManager = class _PointKillManager {
8881
- static {
8882
- __name(this, "PointKillManager");
8883
- }
8884
- static instance;
8885
- static CONFIG_HEADER_NAME = "x-force-observability-pointkill";
8886
- config = {
8887
- logs: {
8888
- modules: []
8889
- },
8890
- traces: {
8891
- modules: []
8892
- },
8893
- metrics: {
8894
- modules: []
8895
- }
8896
- };
8897
- constructor() {
8898
- }
8899
- static getInstance() {
8900
- if (!_PointKillManager.instance) {
8901
- _PointKillManager.instance = new _PointKillManager();
8902
- }
8903
- return _PointKillManager.instance;
8904
- }
8905
- getConfig() {
8906
- return this.config;
8907
- }
8908
- updateConfig(newConfig) {
8909
- this.config = {
8910
- logs: {
8911
- modules: [
8912
- ...newConfig.logs.modules
8913
- ]
8914
- },
8915
- traces: {
8916
- modules: [
8917
- ...newConfig.traces.modules
8918
- ]
8919
- },
8920
- metrics: {
8921
- modules: [
8922
- ...newConfig.metrics.modules
8923
- ]
8924
- }
8925
- };
8926
- }
8927
- setConfig(configStr) {
8928
- if (!configStr) return;
8929
- try {
8930
- const res = JSON.parse(configStr);
8931
- const { logs: logs2, traces, metrics } = res ?? {};
8932
- this.updateConfig({
8933
- logs: {
8934
- modules: Array.isArray(logs2?.modules) ? logs2.modules : []
8935
- },
8936
- traces: {
8937
- modules: Array.isArray(traces?.modules) ? traces.modules : []
8938
- },
8939
- metrics: {
8940
- modules: Array.isArray(metrics?.modules) ? metrics.modules : []
8941
- }
8942
- });
8943
- } catch (error) {
8944
- console.error("Failed to parse sniping config:", error);
8945
- }
8946
- }
8947
- updateFromHeaders(headers) {
8948
- const snipingConfig = headers[_PointKillManager.CONFIG_HEADER_NAME] || headers[_PointKillManager.CONFIG_HEADER_NAME.toLowerCase()];
8949
- if (snipingConfig) {
8950
- this.setConfig(snipingConfig);
8951
- }
8952
- }
8953
- };
8954
- var pointKillManager = PointKillManager.getInstance();
8955
-
8956
8879
  // src/core/log-exporter.ts
8957
8880
  var CustomExporter = class {
8958
8881
  static {
@@ -8963,19 +8886,12 @@ var CustomExporter = class {
8963
8886
  constructor() {
8964
8887
  }
8965
8888
  export(logs2, resultCallback) {
8966
- const snipingConfig = pointKillManager.getConfig();
8967
- console.log("snipingConfig", snipingConfig);
8968
- if (snipingConfig.logs.modules.includes("*")) {
8969
- resultCallback({
8970
- code: core.ExportResultCode.SUCCESS
8971
- });
8972
- return;
8973
- }
8889
+ const pointKillConfig = api.context.active().getValue(POINT_KILL_TAG);
8974
8890
  const filteredLogs = logs2.filter((log) => {
8975
- const module = log.attributes?.module;
8976
- if (module && snipingConfig.logs.modules.includes(module)) {
8977
- return false;
8978
- }
8891
+ if (!pointKillConfig) return true;
8892
+ const moduleName = log.attributes?.module;
8893
+ if (pointKillConfig.logs?.modules?.includes("*")) return false;
8894
+ if (moduleName && pointKillConfig.logs?.modules?.includes(moduleName)) return false;
8979
8895
  return true;
8980
8896
  });
8981
8897
  if (filteredLogs.length === 0) {
@@ -8995,19 +8911,23 @@ var CustomExporter = class {
8995
8911
  ...defaultResourceAttr
8996
8912
  }
8997
8913
  },
8998
- logRecords: filteredLogs.map((log) => ({
8999
- timeUnixNano: hrTimeToNanosNumber(log.hrTime),
9000
- observedTimeUnixNano: hrTimeToNanosNumber(log.hrTimeObserved),
9001
- severityNumber: log.severityNumber,
9002
- severityText: log.severityText,
9003
- body: log.body,
9004
- attributes: convertAttributesToString({
8914
+ logRecords: filteredLogs.map((log) => {
8915
+ const rawAttributes = {
9005
8916
  ...defaultAttributes,
9006
8917
  ...log.attributes ?? {}
9007
- }),
9008
- traceID: log.spanContext?.traceId,
9009
- spanID: log.spanContext?.spanId
9010
- }))
8918
+ };
8919
+ delete rawAttributes["__point_kill_logs"];
8920
+ return {
8921
+ timeUnixNano: hrTimeToNanosNumber(log.hrTime),
8922
+ observedTimeUnixNano: hrTimeToNanosNumber(log.hrTimeObserved),
8923
+ severityNumber: log.severityNumber,
8924
+ severityText: log.severityText,
8925
+ body: log.body,
8926
+ attributes: convertAttributesToString(rawAttributes),
8927
+ traceID: log.spanContext?.traceId,
8928
+ spanID: log.spanContext?.spanId
8929
+ };
8930
+ })
9011
8931
  };
9012
8932
  console.log(this.logPrefix + JSON.stringify(otlpLikeStructure) + this.logSuffix);
9013
8933
  resultCallback({
@@ -9054,25 +8974,17 @@ var CustomTraceExporter = class {
9054
8974
  tracePrefix = "force-trace-prefix";
9055
8975
  traceSuffix = "force-trace-suffix";
9056
8976
  export(spans, resultCallback) {
9057
- const snipingConfig = pointKillManager.getConfig();
9058
- console.log("snipingConfig", snipingConfig);
9059
- if (snipingConfig.traces.modules.includes("*")) {
9060
- resultCallback({
9061
- code: core.ExportResultCode.SUCCESS
9062
- });
9063
- return;
9064
- }
9065
8977
  const isDev = process.env.NODE_ENV === "development";
9066
8978
  const defaultAttributes = {
9067
8979
  uuid: idGenerator.generateTraceId(),
9068
8980
  app_env: isDev ? AppEnv.Dev : AppEnv.Prod
9069
8981
  };
9070
8982
  const finalSpans = spans.filter((span) => {
8983
+ const pointKillConfig = api.context.active().getValue(POINT_KILL_TAG);
9071
8984
  if ((span.attributes ?? {})[TraceDropToken]) return false;
9072
- const module = span.attributes?.module;
9073
- if (module && snipingConfig.traces.modules.includes(module)) {
9074
- return false;
9075
- }
8985
+ if (pointKillConfig?.traces?.modules?.includes("*")) return false;
8986
+ const moduleName = span.attributes?.module;
8987
+ if (moduleName && pointKillConfig?.traces?.modules?.includes(moduleName)) return false;
9076
8988
  return true;
9077
8989
  });
9078
8990
  if (!finalSpans.length) {
@@ -9121,7 +9033,36 @@ function isObservable(input) {
9121
9033
  }
9122
9034
  __name(isObservable, "isObservable");
9123
9035
 
9036
+ // src/utils/getSnippingConfig.ts
9037
+ function processSnipConfig(configStr) {
9038
+ if (!configStr) return;
9039
+ try {
9040
+ const res = JSON.parse(configStr);
9041
+ const { logs: logs2, traces, metrics } = res ?? {};
9042
+ if (res) {
9043
+ return {
9044
+ logs: {
9045
+ modules: Array.isArray(logs2?.modules) ? logs2.modules : []
9046
+ },
9047
+ traces: {
9048
+ modules: Array.isArray(traces?.modules) ? traces.modules : []
9049
+ },
9050
+ metrics: {
9051
+ modules: Array.isArray(metrics?.modules) ? metrics.modules : []
9052
+ }
9053
+ };
9054
+ } else {
9055
+ return void 0;
9056
+ }
9057
+ } catch (error) {
9058
+ console.error("Failed to parse sniping config:", error);
9059
+ return void 0;
9060
+ }
9061
+ }
9062
+ __name(processSnipConfig, "processSnipConfig");
9063
+
9124
9064
  // src/core/sdk.ts
9065
+ var POINT_KILL_TAG = /* @__PURE__ */ Symbol("__point_kill");
9125
9066
  var AppOTelSDK = class _AppOTelSDK {
9126
9067
  static {
9127
9068
  __name(this, "AppOTelSDK");
@@ -9162,13 +9103,13 @@ var AppOTelSDK = class _AppOTelSDK {
9162
9103
  * wrapper 形式
9163
9104
  */
9164
9105
  startContext(headers, name, fn) {
9165
- pointKillManager.updateFromHeaders(headers);
9166
9106
  const carrier = {};
9167
9107
  const customTraceId = headers["rpc-persist-apaas-observability-trace"];
9168
9108
  if (customTraceId && _AppOTelSDK.CUSTOM_FORMAT_REGEX.test(customTraceId)) {
9169
9109
  carrier["traceparent"] = `00-${customTraceId}-01`;
9170
9110
  }
9171
9111
  const activeContext = api.propagation.extract(api.context.active(), carrier);
9112
+ activeContext.setValue(POINT_KILL_TAG, processSnipConfig(headers["x-force-observability-pointkill"]));
9172
9113
  const tracer = api.trace.getTracer("app-core");
9173
9114
  tracer.startActiveSpan(name, {}, activeContext, (span) => {
9174
9115
  fn(span);