Skip to content

Commit

Permalink
Log commit hash in telemetry events (#2601)
Browse files Browse the repository at this point in the history
* log commit hash

* use git log --format instead
  • Loading branch information
artursapek authored Sep 16, 2024
1 parent 5b39313 commit 7d02a52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions wormhole-connect/src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export const AVAILABLE_MARKETS_URL =
export const CONNECT_VERSION =
import.meta.env.REACT_APP_CONNECT_VERSION || 'unknown';

export const CONNECT_GIT_HASH =
import.meta.env.REACT_APP_CONNECT_GIT_HASH || 'unknown';

export const CHAIN_ORDER: Chain[] = [
'Ethereum',
'Solana',
Expand Down
3 changes: 2 additions & 1 deletion wormhole-connect/src/config/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONNECT_VERSION } from './constants';
import { CONNECT_VERSION, CONNECT_GIT_HASH } from './constants';
import {
WormholeConnectEvent,
WormholeConnectEventHandler,
Expand All @@ -12,6 +12,7 @@ export function wrapEventHandler(
const eventWithMeta: WormholeConnectEventWithMeta = {
meta: {
version: CONNECT_VERSION,
hash: CONNECT_GIT_HASH,
host: window?.location?.host,
},
...event,
Expand Down
1 change: 1 addition & 0 deletions wormhole-connect/src/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export type WormholeConnectEvent =
export interface WormholeConnectEventMeta {
meta: {
version: string;
hash: string;
host: string;
};
}
Expand Down
14 changes: 14 additions & 0 deletions wormhole-connect/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import { execSync } from 'child_process';
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react-swc';
import checker from '@artursapek/vite-plugin-checker';
Expand All @@ -13,6 +14,18 @@ const packagePath = __dirname.endsWith('wormhole-connect')
: './wormhole-connect/package.json';
const { version } = require(packagePath);

let gitHash = 'unknown';
try {
gitHash = execSync('git log -1 --format=%H').toString().replace('\n', '');
} catch (e) {
console.error(`Failed to determine git hash! Will be missing from telemetry`);
console.error(e);
}

console.info(
`\nBuilding Wormhole Connect version=${version} hash=${gitHash}\n`,
);

// There are three configs this file can return.
// 1. local dev server
// 2. production build, for direct import
Expand All @@ -24,6 +37,7 @@ const envPrefix = 'REACT_APP_';
const define = {
'import.meta.env.REACT_APP_CONNECT_VERSION':
process.env.CONNECT_VERSION ?? JSON.stringify(version),
'import.meta.env.REACT_APP_CONNECT_GIT_HASH': JSON.stringify(gitHash),
};

const resolve = {
Expand Down

0 comments on commit 7d02a52

Please sign in to comment.