Skip to content

Commit

Permalink
[devtools] log more events + metadata (#24951)
Browse files Browse the repository at this point in the history
* [devtools] log more events + metadata

* better typing

* consistent string type
  • Loading branch information
mondaychen committed Jul 19, 2022
1 parent cfb6cfa commit 3ddbedd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/react-devtools-shared/src/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export type LogEvent =
+event_name: 'profiling-start',
|};

export type LogFunction = LogEvent => void | Promise<void>;
export type LogFunction = (LogEvent, ?Object) => void | Promise<void>;

let logFunctions: Array<LogFunction> = [];
export const logEvent: LogFunction =
enableLogger === true
? function logEvent(event: LogEvent): void {
? function logEvent(event: LogEvent, metadata: ?Object): void {
logFunctions.forEach(log => {
log(event);
log(event, metadata);
});
}
: function logEvent() {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function Element({data, index, style}: Props) {

const handleClick = ({metaKey}) => {
if (id !== null) {
logEvent({event_name: 'select-element'});
logEvent({event_name: 'select-element'}, {source: 'click-element'});
dispatch({
type: 'SELECT_ELEMENT_BY_ID',
payload: metaKey ? null : id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function OwnerView({
} = useHighlightNativeElement();

const handleClick = useCallback(() => {
logEvent({event_name: 'select-element'});
logEvent({event_name: 'select-element'}, {source: 'owner-view'});
dispatch({
type: 'SELECT_ELEMENT_BY_ID',
payload: id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function Tree(props: Props) {
function handleStopInspectingNative(didSelectNode) {
if (didSelectNode && focusTargetRef.current !== null) {
focusTargetRef.current.focus();
logEvent({event_name: 'select-element'});
logEvent({event_name: 'select-element'}, {source: 'inspector'});
}
}
bridge.addListener('stopInspectingNative', handleStopInspectingNative);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,6 @@ function ProfilerContextController({children}: Props) {
});
}

const startProfiling = useCallback(() => {
logEvent({event_name: 'profiling-start'});
store.profilerStore.startProfiling();
}, [store]);
const stopProfiling = useCallback(() => store.profilerStore.stopProfiling(), [
store,
]);

const [
isCommitFilterEnabled,
setIsCommitFilterEnabled,
Expand All @@ -217,6 +209,14 @@ function ProfilerContextController({children}: Props) {
'flame-chart',
);

const startProfiling = useCallback(() => {
logEvent({event_name: 'profiling-start'}, {current_tab: selectedTabID});
store.profilerStore.startProfiling();
}, [store, selectedTabID]);
const stopProfiling = useCallback(() => store.profilerStore.stopProfiling(), [
store,
]);

if (isProfiling) {
batchedUpdates(() => {
if (selectedCommitIndex !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function registerDevToolsEventLogger(
| LoggerContext
| ?(() => Promise<LoggerContext>),
): void {
async function logEvent(event: LogEvent) {
async function logEvent(event: LogEvent, metadata: ?Object) {
if (enableLogger) {
if (loggingIFrame != null) {
loggingIFrame.contentWindow.postMessage(
Expand All @@ -35,6 +35,7 @@ export function registerDevToolsEventLogger(
context: {
surface,
version: process.env.DEVTOOLS_VERSION,
metadata: metadata != null ? JSON.stringify(metadata) : '',
...(fetchAdditionalContext != null
? await fetchAdditionalContext()
: {}),
Expand Down

0 comments on commit 3ddbedd

Please sign in to comment.