@lark-apaas/observable 1.0.4-alpha.5 → 1.0.4-alpha.6
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 +150 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +151 -57
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
523
|
+
var context2 = null;
|
|
524
524
|
function errorContext(cb) {
|
|
525
525
|
if (config_1.config.useDeprecatedSynchronousErrorHandling) {
|
|
526
|
-
var isRoot = !
|
|
526
|
+
var isRoot = !context2;
|
|
527
527
|
if (isRoot) {
|
|
528
|
-
|
|
528
|
+
context2 = {
|
|
529
529
|
errorThrown: false,
|
|
530
530
|
error: null
|
|
531
531
|
};
|
|
532
532
|
}
|
|
533
533
|
cb();
|
|
534
534
|
if (isRoot) {
|
|
535
|
-
var _a =
|
|
536
|
-
|
|
535
|
+
var _a = context2, errorThrown = _a.errorThrown, error = _a.error;
|
|
536
|
+
context2 = 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 &&
|
|
549
|
-
|
|
550
|
-
|
|
548
|
+
if (config_1.config.useDeprecatedSynchronousErrorHandling && context2) {
|
|
549
|
+
context2.errorThrown = true;
|
|
550
|
+
context2.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.
|
|
8847
|
+
version: "1.0.4-alpha.5"};
|
|
8848
8848
|
|
|
8849
8849
|
// src/const.ts
|
|
8850
8850
|
var AppEnv = /* @__PURE__ */ (function(AppEnv2) {
|
|
@@ -8857,6 +8857,7 @@ var defaultResourceAttr = {
|
|
|
8857
8857
|
"sdk_type": "client-backend",
|
|
8858
8858
|
"sdk_language": "node"
|
|
8859
8859
|
};
|
|
8860
|
+
var pointKillTag = "__point_kill_info";
|
|
8860
8861
|
var TraceDropToken = "TraceDropToken";
|
|
8861
8862
|
|
|
8862
8863
|
// src/utils/convertAllAttrIntoString.ts
|
|
@@ -8876,6 +8877,34 @@ function convertAttributesToString(attributes) {
|
|
|
8876
8877
|
}
|
|
8877
8878
|
__name(convertAttributesToString, "convertAttributesToString");
|
|
8878
8879
|
|
|
8880
|
+
// src/utils/getSnippingConfig.ts
|
|
8881
|
+
function processSnipConfig(configStr) {
|
|
8882
|
+
if (!configStr) return;
|
|
8883
|
+
try {
|
|
8884
|
+
const res = JSON.parse(configStr);
|
|
8885
|
+
const { logs: logs2, traces, metrics } = res ?? {};
|
|
8886
|
+
if (res) {
|
|
8887
|
+
return {
|
|
8888
|
+
logs: {
|
|
8889
|
+
modules: Array.isArray(logs2?.modules) ? logs2.modules : []
|
|
8890
|
+
},
|
|
8891
|
+
traces: {
|
|
8892
|
+
modules: Array.isArray(traces?.modules) ? traces.modules : []
|
|
8893
|
+
},
|
|
8894
|
+
metrics: {
|
|
8895
|
+
modules: Array.isArray(metrics?.modules) ? metrics.modules : []
|
|
8896
|
+
}
|
|
8897
|
+
};
|
|
8898
|
+
} else {
|
|
8899
|
+
return void 0;
|
|
8900
|
+
}
|
|
8901
|
+
} catch (error) {
|
|
8902
|
+
console.error("Failed to parse sniping config:", error);
|
|
8903
|
+
return void 0;
|
|
8904
|
+
}
|
|
8905
|
+
}
|
|
8906
|
+
__name(processSnipConfig, "processSnipConfig");
|
|
8907
|
+
|
|
8879
8908
|
// src/core/log-exporter.ts
|
|
8880
8909
|
var CustomExporter = class {
|
|
8881
8910
|
static {
|
|
@@ -8886,12 +8915,22 @@ var CustomExporter = class {
|
|
|
8886
8915
|
constructor() {
|
|
8887
8916
|
}
|
|
8888
8917
|
export(logs2, resultCallback) {
|
|
8889
|
-
const pointKillConfig = api.context.active().getValue(POINT_KILL_TAG);
|
|
8890
8918
|
const filteredLogs = logs2.filter((log) => {
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8919
|
+
const pkTag = log.attributes?.[pointKillTag];
|
|
8920
|
+
if (pkTag) {
|
|
8921
|
+
try {
|
|
8922
|
+
const snipingConfig = processSnipConfig(pkTag);
|
|
8923
|
+
if (snipingConfig?.logs?.modules?.includes("*")) {
|
|
8924
|
+
return false;
|
|
8925
|
+
}
|
|
8926
|
+
const module = log.attributes?.module;
|
|
8927
|
+
if (module && snipingConfig?.logs?.modules?.includes(module)) {
|
|
8928
|
+
return false;
|
|
8929
|
+
}
|
|
8930
|
+
} catch (e) {
|
|
8931
|
+
console.error(`Failed to parse ${pointKillTag} in log exporter:`, e);
|
|
8932
|
+
}
|
|
8933
|
+
}
|
|
8895
8934
|
return true;
|
|
8896
8935
|
});
|
|
8897
8936
|
if (filteredLogs.length === 0) {
|
|
@@ -8911,23 +8950,19 @@ var CustomExporter = class {
|
|
|
8911
8950
|
...defaultResourceAttr
|
|
8912
8951
|
}
|
|
8913
8952
|
},
|
|
8914
|
-
logRecords: filteredLogs.map((log) => {
|
|
8915
|
-
|
|
8953
|
+
logRecords: filteredLogs.map((log) => ({
|
|
8954
|
+
timeUnixNano: hrTimeToNanosNumber(log.hrTime),
|
|
8955
|
+
observedTimeUnixNano: hrTimeToNanosNumber(log.hrTimeObserved),
|
|
8956
|
+
severityNumber: log.severityNumber,
|
|
8957
|
+
severityText: log.severityText,
|
|
8958
|
+
body: log.body,
|
|
8959
|
+
attributes: convertAttributesToString({
|
|
8916
8960
|
...defaultAttributes,
|
|
8917
8961
|
...log.attributes ?? {}
|
|
8918
|
-
}
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
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
|
-
})
|
|
8962
|
+
}),
|
|
8963
|
+
traceID: log.spanContext?.traceId,
|
|
8964
|
+
spanID: log.spanContext?.spanId
|
|
8965
|
+
}))
|
|
8931
8966
|
};
|
|
8932
8967
|
console.log(this.logPrefix + JSON.stringify(otlpLikeStructure) + this.logSuffix);
|
|
8933
8968
|
resultCallback({
|
|
@@ -8974,17 +9009,23 @@ var CustomTraceExporter = class {
|
|
|
8974
9009
|
tracePrefix = "force-trace-prefix";
|
|
8975
9010
|
traceSuffix = "force-trace-suffix";
|
|
8976
9011
|
export(spans, resultCallback) {
|
|
8977
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
8978
|
-
const defaultAttributes = {
|
|
8979
|
-
uuid: idGenerator.generateTraceId(),
|
|
8980
|
-
app_env: isDev ? AppEnv.Dev : AppEnv.Prod
|
|
8981
|
-
};
|
|
8982
9012
|
const finalSpans = spans.filter((span) => {
|
|
8983
|
-
const pointKillConfig = api.context.active().getValue(POINT_KILL_TAG);
|
|
8984
9013
|
if ((span.attributes ?? {})[TraceDropToken]) return false;
|
|
8985
|
-
|
|
8986
|
-
|
|
8987
|
-
|
|
9014
|
+
const pkTag = span.attributes?.[pointKillTag];
|
|
9015
|
+
if (pkTag) {
|
|
9016
|
+
try {
|
|
9017
|
+
const snipingConfig = processSnipConfig(pkTag);
|
|
9018
|
+
if (snipingConfig?.traces?.modules?.includes("*")) {
|
|
9019
|
+
return false;
|
|
9020
|
+
}
|
|
9021
|
+
const module = span.attributes?.module;
|
|
9022
|
+
if (module && snipingConfig?.traces?.modules?.includes(module)) {
|
|
9023
|
+
return false;
|
|
9024
|
+
}
|
|
9025
|
+
} catch (e) {
|
|
9026
|
+
console.error(`Failed to parse in trace exporter:`, e);
|
|
9027
|
+
}
|
|
9028
|
+
}
|
|
8988
9029
|
return true;
|
|
8989
9030
|
});
|
|
8990
9031
|
if (!finalSpans.length) {
|
|
@@ -8993,6 +9034,11 @@ var CustomTraceExporter = class {
|
|
|
8993
9034
|
});
|
|
8994
9035
|
return;
|
|
8995
9036
|
}
|
|
9037
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
9038
|
+
const defaultAttributes = {
|
|
9039
|
+
uuid: idGenerator.generateTraceId(),
|
|
9040
|
+
app_env: isDev ? AppEnv.Dev : AppEnv.Prod
|
|
9041
|
+
};
|
|
8996
9042
|
const otlpLikeStructure = {
|
|
8997
9043
|
resource: {
|
|
8998
9044
|
attributes: {
|
|
@@ -9033,14 +9079,60 @@ function isObservable(input) {
|
|
|
9033
9079
|
}
|
|
9034
9080
|
__name(isObservable, "isObservable");
|
|
9035
9081
|
|
|
9036
|
-
// src/
|
|
9037
|
-
|
|
9038
|
-
|
|
9039
|
-
|
|
9040
|
-
|
|
9041
|
-
|
|
9042
|
-
|
|
9043
|
-
|
|
9082
|
+
// src/core/point-kill/index.ts
|
|
9083
|
+
var PointKillManager = class _PointKillManager {
|
|
9084
|
+
static {
|
|
9085
|
+
__name(this, "PointKillManager");
|
|
9086
|
+
}
|
|
9087
|
+
static instance;
|
|
9088
|
+
static CONFIG_HEADER_NAME = "x-force-observability-pointkill";
|
|
9089
|
+
config = {
|
|
9090
|
+
logs: {
|
|
9091
|
+
modules: []
|
|
9092
|
+
},
|
|
9093
|
+
traces: {
|
|
9094
|
+
modules: []
|
|
9095
|
+
},
|
|
9096
|
+
metrics: {
|
|
9097
|
+
modules: []
|
|
9098
|
+
}
|
|
9099
|
+
};
|
|
9100
|
+
constructor() {
|
|
9101
|
+
}
|
|
9102
|
+
static getInstance() {
|
|
9103
|
+
if (!_PointKillManager.instance) {
|
|
9104
|
+
_PointKillManager.instance = new _PointKillManager();
|
|
9105
|
+
}
|
|
9106
|
+
return _PointKillManager.instance;
|
|
9107
|
+
}
|
|
9108
|
+
getConfig() {
|
|
9109
|
+
return this.config;
|
|
9110
|
+
}
|
|
9111
|
+
updateConfig(newConfig) {
|
|
9112
|
+
this.config = {
|
|
9113
|
+
logs: {
|
|
9114
|
+
modules: [
|
|
9115
|
+
...newConfig.logs.modules
|
|
9116
|
+
]
|
|
9117
|
+
},
|
|
9118
|
+
traces: {
|
|
9119
|
+
modules: [
|
|
9120
|
+
...newConfig.traces.modules
|
|
9121
|
+
]
|
|
9122
|
+
},
|
|
9123
|
+
metrics: {
|
|
9124
|
+
modules: [
|
|
9125
|
+
...newConfig.metrics.modules
|
|
9126
|
+
]
|
|
9127
|
+
}
|
|
9128
|
+
};
|
|
9129
|
+
}
|
|
9130
|
+
setConfig(configStr) {
|
|
9131
|
+
if (!configStr) return;
|
|
9132
|
+
try {
|
|
9133
|
+
const res = JSON.parse(configStr);
|
|
9134
|
+
const { logs: logs2, traces, metrics } = res ?? {};
|
|
9135
|
+
this.updateConfig({
|
|
9044
9136
|
logs: {
|
|
9045
9137
|
modules: Array.isArray(logs2?.modules) ? logs2.modules : []
|
|
9046
9138
|
},
|
|
@@ -9050,19 +9142,21 @@ function processSnipConfig(configStr) {
|
|
|
9050
9142
|
metrics: {
|
|
9051
9143
|
modules: Array.isArray(metrics?.modules) ? metrics.modules : []
|
|
9052
9144
|
}
|
|
9053
|
-
};
|
|
9054
|
-
}
|
|
9055
|
-
|
|
9145
|
+
});
|
|
9146
|
+
} catch (error) {
|
|
9147
|
+
console.error("Failed to parse sniping config:", error);
|
|
9056
9148
|
}
|
|
9057
|
-
} catch (error) {
|
|
9058
|
-
console.error("Failed to parse sniping config:", error);
|
|
9059
|
-
return void 0;
|
|
9060
9149
|
}
|
|
9061
|
-
|
|
9062
|
-
|
|
9150
|
+
updateFromHeaders(headers) {
|
|
9151
|
+
const snipingConfig = headers[_PointKillManager.CONFIG_HEADER_NAME] || headers[_PointKillManager.CONFIG_HEADER_NAME.toLowerCase()];
|
|
9152
|
+
if (snipingConfig) {
|
|
9153
|
+
this.setConfig(snipingConfig);
|
|
9154
|
+
}
|
|
9155
|
+
}
|
|
9156
|
+
};
|
|
9157
|
+
var pointKillManager = PointKillManager.getInstance();
|
|
9063
9158
|
|
|
9064
9159
|
// src/core/sdk.ts
|
|
9065
|
-
var POINT_KILL_TAG = /* @__PURE__ */ Symbol("__point_kill");
|
|
9066
9160
|
var AppOTelSDK = class _AppOTelSDK {
|
|
9067
9161
|
static {
|
|
9068
9162
|
__name(this, "AppOTelSDK");
|
|
@@ -9103,13 +9197,13 @@ var AppOTelSDK = class _AppOTelSDK {
|
|
|
9103
9197
|
* wrapper 形式
|
|
9104
9198
|
*/
|
|
9105
9199
|
startContext(headers, name, fn) {
|
|
9200
|
+
pointKillManager.updateFromHeaders(headers);
|
|
9106
9201
|
const carrier = {};
|
|
9107
9202
|
const customTraceId = headers["rpc-persist-apaas-observability-trace"];
|
|
9108
9203
|
if (customTraceId && _AppOTelSDK.CUSTOM_FORMAT_REGEX.test(customTraceId)) {
|
|
9109
9204
|
carrier["traceparent"] = `00-${customTraceId}-01`;
|
|
9110
9205
|
}
|
|
9111
9206
|
const activeContext = api.propagation.extract(api.context.active(), carrier);
|
|
9112
|
-
activeContext.setValue(POINT_KILL_TAG, processSnipConfig(headers["x-force-observability-pointkill"]));
|
|
9113
9207
|
const tracer = api.trace.getTracer("app-core");
|
|
9114
9208
|
tracer.startActiveSpan(name, {}, activeContext, (span) => {
|
|
9115
9209
|
fn(span);
|