@lark-apaas/client-toolkit 1.2.1-alpha.8 → 1.2.2-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.
@@ -6,7 +6,6 @@ const initObservable = ()=>{
6
6
  env: 'development' === process.env.NODE_ENV ? AppEnv.Dev : AppEnv.Prod,
7
7
  collectorUrl: {
8
8
  log: `/spark/app/${window.appId}/runtime/api/v1/observability/logs/collect`,
9
- trace: `/spark/app/${window.appId}/runtime/api/v1/observability/traces/collect`,
10
9
  metric: `/spark/app/${window.appId}/runtime/api/v1/observability/metrics/collect`
11
10
  }
12
11
  });
package/lib/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createClient } from "@lark-apaas/client-capability";
2
2
  import { normalizeBasePath } from "./utils/utils.js";
3
+ import { logger } from "./logger/index.js";
3
4
  import { version } from "../package.json";
4
5
  const capabilityClient = createClient({
5
6
  baseURL: normalizeBasePath(process.env.CLIENT_BASE_PATH),
@@ -7,7 +8,8 @@ const capabilityClient = createClient({
7
8
  headers: {
8
9
  'X-Suda-Csrf-Token': window.csrfToken ?? ''
9
10
  }
10
- }
11
+ },
12
+ logger: logger
11
13
  });
12
14
  const src = {
13
15
  version: version
@@ -1,14 +1,4 @@
1
1
  import { AxiosInstance } from 'axios';
2
- declare module 'axios' {
3
- interface AxiosRequestConfig {
4
- /** @internal 存储 Span 实例 */
5
- __span?: any;
6
- /** @internal 请求开始时间 */
7
- _startTime?: number;
8
- /** @internal 请求唯一标识 */
9
- _requestUUID?: string;
10
- }
11
- }
12
2
  /**
13
3
  * axios配置内容:拦截器、日志等
14
4
  */
@@ -1,8 +1,6 @@
1
1
  import axios from "axios";
2
- import { observable } from "@lark-apaas/observable-web";
3
2
  import { logger } from "../apis/logger.js";
4
3
  import { getStacktrace } from "../logger/selected-logs.js";
5
- import { safeStringify } from "./safeStringify.js";
6
4
  const isValidResponse = (resp)=>null != resp && 'object' == typeof resp && 'config' in resp && null !== resp.config && void 0 !== resp.config && 'object' == typeof resp.config && 'status' in resp && 'number' == typeof resp.status && 'data' in resp;
7
5
  async function logResponse(ok, responseOrError) {
8
6
  if (isValidResponse(responseOrError)) {
@@ -54,7 +52,7 @@ async function logResponse(ok, responseOrError) {
54
52
  logTraceID
55
53
  };
56
54
  if (stacktrace) logMeta.stacktrace = stacktrace;
57
- logger.debug({
55
+ if ('development' === process.env.NODE_ENV) logger.log({
58
56
  level: ok,
59
57
  args: [
60
58
  parts.join(''),
@@ -110,7 +108,7 @@ async function logResponse(ok, responseOrError) {
110
108
  const stacktrace = await requestStacktraceMap.get(requestUUID);
111
109
  const logMeta = {};
112
110
  if (stacktrace) logMeta.stacktrace = stacktrace;
113
- logger.debug({
111
+ logger.log({
114
112
  level: 'error',
115
113
  args: [
116
114
  parts.join(''),
@@ -120,7 +118,7 @@ async function logResponse(ok, responseOrError) {
120
118
  });
121
119
  return;
122
120
  }
123
- logger.debug({
121
+ logger.log({
124
122
  level: 'error',
125
123
  args: [
126
124
  '请求失败:无响应对象或配置信息'
@@ -131,61 +129,6 @@ async function logResponse(ok, responseOrError) {
131
129
  const requestStacktraceMap = new Map();
132
130
  function initAxiosConfig(axiosInstance) {
133
131
  if (!axiosInstance) axiosInstance = axios;
134
- axiosInstance.interceptors.request.use((config)=>{
135
- const method = (config.method || 'GET').toUpperCase();
136
- const url = config.url || '';
137
- const cleanedPath = url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, '') || '/';
138
- try {
139
- const span = observable.startSpan(`${method} ${cleanedPath}`);
140
- if (span) {
141
- const traceInfo = `${span.spanContext().traceId}-${span.spanContext().spanId}`;
142
- config.headers["X-Tt-TraceInfo"] = traceInfo;
143
- config.__span = span;
144
- }
145
- } catch (error) {
146
- console.error('Trace 配置失败:', error);
147
- }
148
- return config;
149
- });
150
- axiosInstance.interceptors.response.use((response)=>{
151
- const { __span: span, _startTime: startTime, url = "" } = response.config || {};
152
- const method = (response.config.method || 'GET').toUpperCase();
153
- const cleanedPath = url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, '') || '/';
154
- if (span) {
155
- observable.log('INFO', safeStringify({
156
- method,
157
- path: cleanedPath,
158
- url,
159
- user_agent: response.config.headers["user-agent"],
160
- duration_ms: startTime ? Date.now() - startTime : void 0,
161
- status: response.status,
162
- request_body: response.config.data,
163
- response: response.data
164
- }), {}, span);
165
- 'function' == typeof span.end && span.end();
166
- }
167
- return response;
168
- }, (error)=>{
169
- const { config: errorConfig = {}, response: errorResponse = {}, message: errorMessage = '未知错误' } = error;
170
- const { __span: span, _startTime: startTime, url = "" } = errorConfig || {};
171
- const method = (errorConfig.method || 'GET').toUpperCase();
172
- const cleanedPath = url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, '') || '/';
173
- if (span) {
174
- observable.log('ERROR', safeStringify({
175
- method,
176
- path: cleanedPath,
177
- url,
178
- user_agent: errorConfig.headers?.["user-agent"],
179
- duration_ms: startTime ? Date.now() - startTime : void 0,
180
- status: errorResponse.status || 200,
181
- request_body: errorConfig.data,
182
- response: errorResponse.data || {},
183
- error_message: errorMessage
184
- }), {}, span);
185
- 'function' == typeof span.end && span.end();
186
- }
187
- return Promise.reject(error);
188
- });
189
132
  axiosInstance.interceptors.request.use((config)=>{
190
133
  const requestUUID = crypto.randomUUID();
191
134
  if ('production' !== process.env.NODE_ENV) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.1-alpha.8",
3
+ "version": "1.2.2-alpha.0",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -31,11 +31,6 @@
31
31
  "require": "./lib/apis/logger.js",
32
32
  "types": "./lib/apis/logger.d.ts"
33
33
  },
34
- "./trace": {
35
- "import": "./lib/apis/trace.js",
36
- "require": "./lib/apis/trace.js",
37
- "types": "./lib/apis/trace.d.ts"
38
- },
39
34
  "./udt-types": {
40
35
  "import": "./lib/apis/udt-types.js",
41
36
  "require": "./lib/apis/udt-types.js",
@@ -86,9 +81,9 @@
86
81
  "@ant-design/colors": "^7.2.1",
87
82
  "@ant-design/cssinjs": "^1.24.0",
88
83
  "@data-loom/js": "^0.4.3",
89
- "@lark-apaas/client-capability": "^0.1.1",
84
+ "@lark-apaas/client-capability": "0.1.2-alpha.0",
90
85
  "@lark-apaas/miaoda-inspector": "^1.0.8",
91
- "@lark-apaas/observable-web": "^1.0.1-alpha.0",
86
+ "@lark-apaas/observable-web": "^1.0.0",
92
87
  "@radix-ui/react-avatar": "^1.1.10",
93
88
  "@radix-ui/react-popover": "^1.1.15",
94
89
  "@radix-ui/react-slot": "^1.2.3",
@@ -162,4 +157,4 @@
162
157
  "react-router-dom": ">=6.26.2",
163
158
  "styled-jsx": ">=5.0.0"
164
159
  }
165
- }
160
+ }
@@ -1 +0,0 @@
1
- export * from '../trace';
package/lib/apis/trace.js DELETED
@@ -1 +0,0 @@
1
- export * from "../trace/index.js";
@@ -1,2 +0,0 @@
1
- declare const trace: <T>(name: string, fn: (span: import("@opentelemetry/api").Span) => Promise<T>, options?: import("@opentelemetry/api").SpanOptions) => Promise<T>;
2
- export { trace };
@@ -1,3 +0,0 @@
1
- import { observable } from "@lark-apaas/observable-web";
2
- const trace = observable.trace;
3
- export { trace };