@lark-apaas/observable 1.0.4-alpha.5 → 1.0.4-alpha.7
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 +92 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +93 -72
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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");
|
|
@@ -8802,7 +8802,7 @@ var PlatformDetector = class {
|
|
|
8802
8802
|
* @param config 探测配置 (可选)
|
|
8803
8803
|
*/
|
|
8804
8804
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8805
|
-
detect(
|
|
8805
|
+
detect(_config) {
|
|
8806
8806
|
const attributes = {};
|
|
8807
8807
|
const cleanAttributes = Object.entries(attributes).reduce((acc, [key, value]) => {
|
|
8808
8808
|
if (value !== void 0 && value !== null && value !== "") {
|
|
@@ -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.7"};
|
|
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,36 +9079,7 @@ function isObservable(input) {
|
|
|
9033
9079
|
}
|
|
9034
9080
|
__name(isObservable, "isObservable");
|
|
9035
9081
|
|
|
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
|
-
|
|
9064
9082
|
// src/core/sdk.ts
|
|
9065
|
-
var POINT_KILL_TAG = /* @__PURE__ */ Symbol("__point_kill");
|
|
9066
9083
|
var AppOTelSDK = class _AppOTelSDK {
|
|
9067
9084
|
static {
|
|
9068
9085
|
__name(this, "AppOTelSDK");
|
|
@@ -9070,9 +9087,13 @@ var AppOTelSDK = class _AppOTelSDK {
|
|
|
9070
9087
|
sdk = null;
|
|
9071
9088
|
logProcessor = null;
|
|
9072
9089
|
spanProcessor = null;
|
|
9090
|
+
logger = null;
|
|
9091
|
+
isStarted = false;
|
|
9073
9092
|
static CUSTOM_FORMAT_REGEX = /^[0-9a-fA-F]{32}-[0-9a-fA-F]{16}$/;
|
|
9074
9093
|
static emptySpan = api.trace.wrapSpanContext(api.INVALID_SPAN_CONTEXT);
|
|
9075
9094
|
start() {
|
|
9095
|
+
if (this.isStarted) return;
|
|
9096
|
+
this.isStarted = true;
|
|
9076
9097
|
const resource = resources.detectResources({
|
|
9077
9098
|
detectors: [
|
|
9078
9099
|
new PlatformDetector()
|
|
@@ -9096,6 +9117,7 @@ var AppOTelSDK = class _AppOTelSDK {
|
|
|
9096
9117
|
spanProcessor: this.spanProcessor
|
|
9097
9118
|
});
|
|
9098
9119
|
this.sdk.start();
|
|
9120
|
+
this.logger = apiLogs.logs.getLogger("app-logger");
|
|
9099
9121
|
}
|
|
9100
9122
|
/**
|
|
9101
9123
|
* [框架专用 API] 开启一个根 Span (Root Span)
|
|
@@ -9109,7 +9131,6 @@ var AppOTelSDK = class _AppOTelSDK {
|
|
|
9109
9131
|
carrier["traceparent"] = `00-${customTraceId}-01`;
|
|
9110
9132
|
}
|
|
9111
9133
|
const activeContext = api.propagation.extract(api.context.active(), carrier);
|
|
9112
|
-
activeContext.setValue(POINT_KILL_TAG, processSnipConfig(headers["x-force-observability-pointkill"]));
|
|
9113
9134
|
const tracer = api.trace.getTracer("app-core");
|
|
9114
9135
|
tracer.startActiveSpan(name, {}, activeContext, (span) => {
|
|
9115
9136
|
fn(span);
|
|
@@ -9168,7 +9189,7 @@ var AppOTelSDK = class _AppOTelSDK {
|
|
|
9168
9189
|
*/
|
|
9169
9190
|
log(level, message, extra = {}, spanAttr) {
|
|
9170
9191
|
try {
|
|
9171
|
-
|
|
9192
|
+
if (!this.logger) return;
|
|
9172
9193
|
const severityNumber = mapSeverity(level);
|
|
9173
9194
|
const severityText = mapSeverityText(level);
|
|
9174
9195
|
const attributes = {
|
|
@@ -9189,7 +9210,7 @@ var AppOTelSDK = class _AppOTelSDK {
|
|
|
9189
9210
|
} catch {
|
|
9190
9211
|
logContext = api.context.active();
|
|
9191
9212
|
}
|
|
9192
|
-
logger.emit({
|
|
9213
|
+
this.logger.emit({
|
|
9193
9214
|
body: message,
|
|
9194
9215
|
severityNumber,
|
|
9195
9216
|
severityText,
|