您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
onclick to view logs of a trace id
当前为
// ==UserScript== // @name datadog-traceId // @namespace http://tampermonkey.net/ // @version 0.1.3 // @description onclick to view logs of a trace id // @author You // @match https://app.datadoghq.com/logs* // @grant unsafeWindow // @run-at document-end // ==/UserScript== const baseURL = 'https://app.datadoghq.com'; function buildURL(baseURL, params) { const paramArr = []; Object.keys(params).forEach((key) => { paramArr.push(`${key}=${encodeURIComponent(params[key])}`); }); return `${baseURL}?${paramArr.join('&')}`; } function buildAttrbutes() { const rows = document.querySelectorAll('.log_raw-json tr'); const attrs = {}; for (let i = 0; i < rows.length; i += 1) { const row = rows[i]; const cells = row.innerText.split(/\s+/ig); if (cells.length === 2) { attrs[cells[0]] = { row: row, value: cells[1] }; } } return attrs; } function clearExistButton() { const btn = document.querySelector('#btnOpenTraceIdView'); if (btn) btn.remove(); } function findTraceId() { const attributes = buildAttrbutes(); const traceIdObj = attributes['traceId']; const timestampObj = attributes['@timestamp']; if (!traceIdObj || !traceIdObj.row || !timestampObj) { return; } const timestamp = timestampObj.value; const traceId = traceIdObj.value; const traceIdRow = traceIdObj.row; if (traceIdRow.lastTraceId != traceId) { clearExistButton(); const button = document.createElement('button'); const divBox = document.querySelector('.ui_layout_expandable-block__content'); const boxPreClass = divBox.childNodes[0]; button.innerText = 'Open Logs of traceId'; button.id = 'btnOpenTraceIdView'; button.onclick = () => { const startMilliSec = new Date(timestamp).getTime() - 10 * 60 * 1000; const destMilliSec = new Date(timestamp).getTime() + 10 * 60 * 1000; const url = buildURL(`${baseURL}/logs`, { cols: 'core_host,core_service', from_ts: startMilliSec, index: 'main', live: 'false', messageDisplay: 'inline', query: `@traceId:${traceId}`, stream_sort: 'desc', to_ts: destMilliSec }); // eslint-disable-next-line no-undef unsafeWindow.open(url, '_blank'); }; button.style.padding = '5px'; button.style.marginBottom = '3px'; button.style.borderColor = '#ccc'; button.style.cursor = 'pointer'; divBox.insertBefore(button, boxPreClass); traceIdRow.lastTraceId = traceId; } } (function () { 'use strict'; setInterval(() => { findTraceId(); }, 1000); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址