Skip to content

Commit e082d5a

Browse files
committed
2.2.10 remove metrics
metrics: disable top 2, sample other top metrics
1 parent 9809af8 commit e082d5a

File tree

8 files changed

+54
-49
lines changed

8 files changed

+54
-49
lines changed

packages/shell-chrome-v3/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Alpine.js devtools - Early Access",
33
"description": "DevTools extension for debugging Alpine.js applications.",
4-
"version": "2.2.8",
4+
"version": "2.2.10",
55
"manifest_version": 3,
66
"icons": {
77
"16": "icons/16.png",

packages/shell-chrome-v3/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/shell-chrome-v3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "shell-chrome-v3",
33
"private": true,
4-
"version": "2.2.8",
4+
"version": "2.2.10",
55
"description": "Alpine.js devtools with Chrome manifest v3 compatibility",
66
"type": "module",
77
"scripts": {

packages/shell-chrome-v3/src/devtools/components/footer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createSignal } from 'solid-js';
22
import { componentsValue, errors, state, storesValue } from '../state';
33
import { effect } from 'solid-js/web';
4-
import { bucketCount, metric } from '../metrics';
4+
import { bucketCount, metric, sampledMetric } from '../metrics';
55
import { isEarlyAccess } from '../../lib/isEarlyAccess';
66

77
interface FooterProps {
@@ -13,7 +13,7 @@ export function Footer({ setActiveTab }: FooterProps) {
1313

1414
effect(() => {
1515
if (state.pageLoadCompleted) {
16-
metric('watching_els', {
16+
sampledMetric('watching_els', {
1717
components: bucketCount(componentsValue().length),
1818
stores: bucketCount(storesValue().length),
1919
errors: bucketCount(errors().length),

packages/shell-chrome-v3/src/devtools/messaging.ts

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BACKEND_TO_PANEL_MESSAGES } from '../lib/constants';
2-
import { metric, runWithMeasure } from './metrics';
2+
import { metric, toolDetector } from './metrics';
33
import {
44
setAlpineVersionFromBackend,
55
setComponentsList,
@@ -37,40 +37,24 @@ export function handleBackendToPanelMessage(
3737
switch (message.type) {
3838
case BACKEND_TO_PANEL_MESSAGES.SET_VERSION: {
3939
setAlpineVersionFromBackend(message.version);
40-
if (message.hasHtmxTarget || message.hasAlpineAjaxTarget) {
41-
let tools = [];
42-
if (message.hasHtmxTarget) {
43-
tools.push('htmx');
44-
}
45-
if (message.hasAlpineAjaxTarget) {
46-
tools.push('alpine-ajax');
47-
}
48-
metric('detected_tools', {
49-
tools: tools.join(','),
50-
});
51-
}
40+
metric('detected_tools', {
41+
tools: toolDetector(message),
42+
version: message.version,
43+
});
5244
setPort(port);
5345
break;
5446
}
5547
case BACKEND_TO_PANEL_MESSAGES.SET_COMPONENTS_AND_STORES: {
56-
runWithMeasure('panel_set_components_and_stores', () => {
57-
setComponentsList(message.components, message.url);
58-
setStoresFromList(message.stores);
59-
setPageLoaded();
60-
setPort(port);
61-
});
48+
setComponentsList(message.components, message.url);
49+
setStoresFromList(message.stores);
50+
setPageLoaded();
51+
setPort(port);
6252
break;
6353
}
6454
case BACKEND_TO_PANEL_MESSAGES.SET_DATA: {
65-
runWithMeasure(
66-
'panel_set_data',
67-
() => {
68-
const comps = JSON.parse(message.data);
69-
setComponentData(message.componentId, comps);
70-
setPort(port);
71-
},
72-
{ sampled: true, minValueMs: 5 },
73-
);
55+
const comps = JSON.parse(message.data);
56+
setComponentData(message.componentId, comps);
57+
setPort(port);
7458
break;
7559
}
7660
case BACKEND_TO_PANEL_MESSAGES.SET_STORE_DATA: {

packages/shell-chrome-v3/src/devtools/metrics.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,14 @@ export function bucketTime(ms: number) {
4747
return `>5000ms`;
4848
}
4949

50-
const sampler = new Sampler(0.1);
50+
const tenPercentSampler = new Sampler(0.1);
5151

52-
export function runWithMeasure(
53-
label: string,
54-
fn: Function,
55-
options: { sampled: boolean; minValueMs: number } = { sampled: false, minValueMs: 0 },
52+
export function sampledMetric(
53+
name: string,
54+
metadata: Record<string, string | number | boolean> = {},
5655
) {
57-
const start = performance.now();
58-
fn();
59-
const time = performance.now() - start;
60-
if ((!options.sampled || sampler.shouldSample()) && time >= options.minValueMs) {
61-
metric(`${label}_exec_time`, { time: bucketTime(time) });
56+
if (tenPercentSampler.shouldSample()) {
57+
metric(name, metadata);
6258
}
6359
}
6460

@@ -93,3 +89,27 @@ export function metric(
9389
});
9490
}
9591
}
92+
93+
export function toolDetector(message: any): string {
94+
if (!message) {
95+
return 'error';
96+
}
97+
const tools = [];
98+
if (message.hasHtmxTarget) {
99+
tools.push('htmx');
100+
}
101+
if (message.hasAlpineAjaxTarget) {
102+
tools.push('alpine-ajax');
103+
}
104+
if (message.hasLivewire) {
105+
tools.push('livewire');
106+
}
107+
if (message.hasLiveView) {
108+
tools.push('liveview');
109+
}
110+
if (message.hasTurbo) {
111+
tools.push('turbo');
112+
}
113+
114+
return tools.length === 0 ? 'none' : tools.join(',');
115+
}

packages/shell-chrome-v3/src/devtools/panel.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import { inspectorPortName } from './ports';
44
import { handleBackendToPanelMessage, unsetPort } from './messaging';
55
import { state } from './state';
66
import { DEVTOOLS_INITIAL_STATE_GLOBAL } from '../lib/constants';
7-
import { metric } from './metrics';
7+
import { sampledMetric } from './metrics';
88

99
let dispose: () => void;
1010
/* Entrypoint for Extension panel, integrates with Devtools/extension APIs, initialises the solidJS app, see also index.html */
1111
function connect() {
1212
if (dispose) {
13-
metric('panel_reinjection');
14-
console.log('unmounting solid app');
13+
console.log('[alpine-devtools] unmounting solid app');
1514
dispose();
1615
}
1716
dispose = renderApp(document.getElementById('root')!);
@@ -71,7 +70,6 @@ let injectionAttempts = 0;
7170
* user app.
7271
*/
7372
function injectScript(scriptSrc: string, globals: any, cb: Function) {
74-
metric('inject_script_start', { scriptSrc });
7573
const src = `
7674
(function() {
7775
var script = document.constructor.prototype.createElement.call(document, 'script');
@@ -90,7 +88,7 @@ function injectScript(scriptSrc: string, globals: any, cb: Function) {
9088
injectScript(scriptSrc, globals, cb);
9189
}, 300);
9290
} else {
93-
metric('inject_script_retry_stop');
91+
sampledMetric('inject_script_retry_stop');
9492
console.error('[alpine-devtools] error injecting script, stopping retries', err);
9593
}
9694
}

packages/shell-chrome-v3/src/scripts/backend.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ export function init(forceStart = false) {
399399
.join(','),
400400
),
401401
hasAlpineAjaxTarget: !!document.querySelector('[x-target]'),
402+
hasLivewire: !!window.Livewire,
403+
hasLiveView: !!window.liveSocket,
404+
hasTurbo: !!window.Turbo,
402405
type: BACKEND_TO_PANEL_MESSAGES.SET_VERSION,
403406
});
404407
}

0 commit comments

Comments
 (0)