Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: opentelemetry依赖移除及引用处兼容 #4781

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 0 additions & 230 deletions bklog/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions bklog/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@
"@codemirror/language": "6.10.2",
"@codemirror/state": "6.4.1",
"@codemirror/view": "6.33.0",
"@opentelemetry/api": "1.8.0",
"@opentelemetry/context-zone": "1.23.0",
"@opentelemetry/instrumentation": "0.50.0",
"@opentelemetry/instrumentation-http": "0.50.0",
"@opentelemetry/instrumentation-xml-http-request": "0.50.0",
"@opentelemetry/sdk-trace-base": "1.23.0",
"@opentelemetry/sdk-trace-web": "1.23.0",

"@vue/babel-helper-vue-jsx-merge-props": "1.4.0",
"@vue/babel-preset-jsx": "1.4.0",
"axios": "1.6.0",
Expand Down
31 changes: 13 additions & 18 deletions bklog/web/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { makeMessage } from '@/common/util';
import i18n from '@/language/i18n';
import serviceList from '@/services/index.js';
import { showLoginModal } from '@blueking/login-modal';
import { context, trace } from '@opentelemetry/api';
import axios from 'axios';

import { random } from '../common/util';
Expand Down Expand Up @@ -70,11 +69,11 @@ axiosInstance.interceptors.request.use(
if (window.IS_EXTERNAL && JSON.parse(window.IS_EXTERNAL) && store.state.spaceUid) {
config.headers['X-Bk-Space-Uid'] = store.state.spaceUid;
}
if (window.__IS_MONITOR_COMPONENT__) {
// if (window.__IS_MONITOR_COMPONENT__) {
// 监控上层并没有使用 OT 这里直接自己生成traceparent id
const traceparent = `00-${random(32, 'abcdef0123456789')}-${random(16, 'abcdef0123456789')}-01`;
config.headers.Traceparent = traceparent;
}
// }
return config;
},
error => Promise.reject(error),
Expand Down Expand Up @@ -150,17 +149,15 @@ async function getPromise(method, url, data, userConfig = {}) {
}

promise = new Promise(async (resolve, reject) => {
context.with(trace.setSpan(context.active(), config.span), async () => {
try {
const axiosRequest = http.$request.request(url, data, config);
const response = await axiosRequest;
Object.assign(config, response.config || {});
handleResponse({ config, response, resolve, reject });
} catch (error) {
Object.assign(config, error.config);
reject(error);
try {
const axiosRequest = http.$request.request(url, data, config);
const response = await axiosRequest;
Object.assign(config, response.config || {});
handleResponse({ config, response, resolve, reject });
} catch (error) {
Object.assign(config, error.config);
reject(error);
}
});
}).catch(error => handleReject(error, config));

// 添加请求队列
Expand Down Expand Up @@ -210,8 +207,8 @@ function handleReject(error, config) {
// const service = getHttpService(url, serviceList);
// const ajaxUrl = service ? service.url : '';
// console.error('Request error UrlPath:', ajaxUrl);
const traceparent = config.span._spanContext.traceId;

const traceparent = config?.headers?.traceparent;
http.queue.delete(config.requestId);

// 捕获 http status 错误
Expand Down Expand Up @@ -289,12 +286,11 @@ function handleReject(error, config) {
*/
function initConfig(method, url, userConfig) {
// const traceparent = `00-${random(32, 'abcdef0123456789')}-${random(16, 'abcdef0123456789')}-01`;
// const copyUserConfig = Object.assign({}, userConfig ?? {});
const copyUserConfig = Object.assign({}, userConfig ?? {});
// copyUserConfig.headers = {
// ...(userConfig.headers ?? {}),
// traceparent,
// };

const defaultConfig = {
...getCancelToken(),
// http 请求默认 id
Expand All @@ -313,9 +309,8 @@ function initConfig(method, url, userConfig) {
cancelPrevious: true,
// 接口报错是否弹bkMessage弹窗
catchIsShowMessage: true,
span: trace.getTracer('bk-log').startSpan('api'),
};
return Object.assign(defaultConfig, userConfig);
return Object.assign(defaultConfig, copyUserConfig);
}

/**
Expand Down
Loading
Loading