Skip to content

Commit

Permalink
Dev/cls report (#205)
Browse files Browse the repository at this point in the history
* dev: 支持 cls 上报
  • Loading branch information
livehigh authored Apr 16, 2024
1 parent d40a609 commit d2cfabf
Show file tree
Hide file tree
Showing 12 changed files with 708 additions and 495 deletions.
2 changes: 1 addition & 1 deletion demo/CIDemos/asr.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const getAsrQueue = {
export const updateAsrQueue = {
name: '更新语音识别队列',
fn: function updateAsrQueue() {
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/46946)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/79394)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
const queueId = 'pcc77499e85c311edb9865254008618d9';
const host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/asrqueue/' + queueId;
const url = 'https://' + host;
Expand Down
2 changes: 1 addition & 1 deletion demo/CIDemos/fileProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export const describeFileProcessQueues = {
export const updateFileProcessQueue = {
name: '更新文件处理队列',
fn: function updateFileProcessQueue() {
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/46946)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/86421)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
const queueId = 'p6160ada105a7408e95aac015f4bf8xxx';
const host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/file_queue/' + queueId;
const url = 'https://' + host;
Expand Down
2 changes: 1 addition & 1 deletion demo/CIDemos/picProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export const describePicProcessQueues = {
export const updatePicProcessQueue = {
name: '更新图片处理队列',
fn: function updatePicProcessQueue() {
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/46946)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/79395)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
const queueId = 'p882d181160d84feca27d9376e17c4xxx';
const host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/picqueue/' + queueId;
const url = 'https://' + host;
Expand Down
645 changes: 380 additions & 265 deletions dist/cos-js-sdk-v5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,14 @@ declare namespace COS {
UseAccelerate?: boolean;
/** 默认为true,将host加入签名计算,关闭后可能导致越权风险,建议保持为true */
ForceSignHost?: boolean;
AutoSwitchHost?: boolean;
/** 链路上报 */
EnableTracker?: boolean;
DeepTracker?: boolean;
TrackerDelay?: number;
CustomId?: string;
BeaconReporter?: any;
ClsReporter?: any;
/** 链路上报 */
AutoSwitchHost?: boolean;
CopySourceParser?: null | CopySourceParserFunction;
/** 获取签名的回调方法,如果没有 SecretId、SecretKey 时,必选 */
getAuthorization?: (
Expand Down Expand Up @@ -339,6 +340,7 @@ declare namespace COS {
Region?: Region;
/** 发请求时带上的 Header 字段 */
Headers?: Headers;
tracker?: any;
}
/** getService 接口返回值 */
interface GetServiceResult extends GeneralResult {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "1.7.0",
"version": "1.7.1",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "dist/cos-js-sdk-v5.js",
"types": "index.d.ts",
Expand Down
35 changes: 26 additions & 9 deletions src/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,15 +911,18 @@ function uploadFile(params, callback) {
var fileInfo = { TaskId: '' };

// 上传链路
if (self.options.EnableTracker) {
if (self.options.EnableReporter) {
const accelerate =
self.options.UseAccelerate ||
(typeof self.options.Domain === 'string' && self.options.Domain.includes('accelerate.'));
const realApi = FileSize > SliceSize ? 'sliceUploadFile' : 'putObject';
params.tracker = new Tracker({
Beacon: self.options.Beacon,
Beacon: self.options.BeaconReporter,
clsReporter: self.options.ClsReporter,
bucket: params.Bucket,
region: params.Region,
apiName: 'uploadFile',
realApi,
fileKey: params.Key,
fileSize: FileSize,
accelerate,
Expand Down Expand Up @@ -951,7 +954,7 @@ function uploadFile(params, callback) {
var _onFileFinish = params.onFileFinish;
var onFileFinish = function (err, data) {
// 格式化上报参数并上报
params.tracker && params.tracker.formatResult(err, data);
params.tracker && params.tracker.report(err, data);
_onFileFinish && _onFileFinish(err, data, fileInfo);
callback && callback(err, data);
};
Expand Down Expand Up @@ -998,8 +1001,6 @@ function uploadFiles(params, callback) {
var taskList = [];
util.each(params.files, function (fileParams, index) {
(function () {
// 对齐 nodejs 缩进

var Body = fileParams.Body;
var FileSize = Body.size || Body.length || 0;
var fileInfo = { Index: index, TaskId: '' };
Expand All @@ -1013,15 +1014,18 @@ function uploadFiles(params, callback) {
TotalSize += FileSize;

// 单个文件上传链路
if (self.options.EnableTracker) {
if (self.options.EnableReporter) {
const accelerate =
self.options.UseAccelerate ||
(typeof self.options.Domain === 'string' && self.options.Domain.includes('accelerate.'));
const realApi = FileSize > SliceSize ? 'sliceUploadFile' : 'putObject';
fileParams.tracker = new Tracker({
Beacon: self.options.Beacon,
Beacon: self.options.BeaconReporter,
clsReporter: self.options.ClsReporter,
bucket: fileParams.Bucket,
region: fileParams.Region,
apiName: 'uploadFiles',
realApi,
fileKey: fileParams.Key,
fileSize: FileSize,
accelerate,
Expand Down Expand Up @@ -1064,7 +1068,7 @@ function uploadFiles(params, callback) {
var _onFileFinish = fileParams.onFileFinish;
var onFileFinish = function (err, data) {
// 格式化上报参数并上报
fileParams.tracker && fileParams.tracker.formatResult(err, data);
fileParams.tracker && fileParams.tracker.report(err, data);
_onFileFinish && _onFileFinish(err, data);
onTotalFileFinish && onTotalFileFinish(err, data, fileInfo);
};
Expand Down Expand Up @@ -1135,6 +1139,7 @@ function sliceCopyFile(params, callback) {
Key: Key,
UploadId: UploadData.UploadId,
Parts: Parts,
tracker: params.tracker,
calledBySdk: 'sliceCopyFile',
},
tryCallback
Expand Down Expand Up @@ -1185,6 +1190,8 @@ function sliceCopyFile(params, callback) {
UploadId: UploadData.UploadId,
PartNumber: PartNumber,
CopySourceRange: CopySourceRange,
tracker: params.tracker,
calledBySdk: 'sliceCopyFile',
},
tryCallback
);
Expand Down Expand Up @@ -1217,6 +1224,8 @@ function sliceCopyFile(params, callback) {
Region: Region,
Key: Key,
Headers: TargetHeader,
tracker: params.tracker,
calledBySdk: 'sliceCopyFile',
},
function (err, data) {
if (err) return callback(err);
Expand Down Expand Up @@ -1245,6 +1254,8 @@ function sliceCopyFile(params, callback) {
Region: Region,
Key: Key,
UploadId: UploadId,
tracker: params.tracker,
calledBySdk: 'sliceCopyFile',
},
function (err, PartListData) {
if (err) {
Expand Down Expand Up @@ -1341,6 +1352,8 @@ function sliceCopyFile(params, callback) {
Bucket: SourceBucket,
Region: SourceRegion,
Key: SourceKey,
tracker: params.tracker,
calledBySdk: 'sliceCopyFile',
},
function (err, data) {
if (err) {
Expand All @@ -1364,14 +1377,16 @@ function sliceCopyFile(params, callback) {
return;
}

params.tracker && params.tracker.setParams({ httpSize: FileSize });

onProgress = util.throttleOnProgress.call(self, FileSize, params.onProgress);

// 开始上传
if (FileSize <= CopySliceSize) {
if (!params.Headers['x-cos-metadata-directive']) {
params.Headers['x-cos-metadata-directive'] = 'Copy';
}
self.putObjectCopy(params, function (err, data) {
self.putObjectCopy(Object.assign(params, { calledBySdk: 'sliceCopyFile' }), function (err, data) {
if (err) {
onProgress(null, true);
return callback(err);
Expand Down Expand Up @@ -1429,6 +1444,8 @@ function copySliceItem(params, callback) {
UploadId: UploadId,
PartNumber: PartNumber,
CopySourceRange: CopySourceRange,
tracker: params.tracker,
calledBySdk: params.calledBySdk,
},
function (err, data) {
tryCallback(err || null, data);
Expand Down
Loading

0 comments on commit d2cfabf

Please sign in to comment.