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