Skip to content

Commit 8b8c58a

Browse files
committed
Improve how environmental variables are adding to Sentry
1 parent 116877f commit 8b8c58a

1 file changed

Lines changed: 22 additions & 26 deletions

File tree

src/utils/sentry.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ function getXcodeInfo(): { version: string; path: string; selectedXcode: string;
3030

3131
function getEnvironmentVariables(): Record<string, string> {
3232
const relevantVars = [
33-
'XCODEBUILDMCP_DEBUG',
3433
'INCREMENTAL_BUILDS_ENABLED',
35-
'XCODEBUILDMCP_DYNAMIC_TOOLS',
3634
'PATH',
3735
'DEVELOPER_DIR',
3836
'HOME',
@@ -47,6 +45,12 @@ function getEnvironmentVariables(): Record<string, string> {
4745
envVars[varName] = process.env[varName] ?? '';
4846
});
4947

48+
Object.keys(process.env).forEach((key) => {
49+
if (key.startsWith('XCODEBUILDMCP_')) {
50+
envVars[key] = process.env[key] ?? '';
51+
}
52+
});
53+
5054
return envVars;
5155
}
5256

@@ -78,7 +82,9 @@ function checkBinaryAvailability(binary: string): { available: boolean; version?
7882
}
7983

8084
Sentry.init({
81-
dsn: 'https://798607831167c7b9fe2f2912f5d3c665@o4509258288332800.ingest.de.sentry.io/4509258293837904',
85+
dsn:
86+
process.env.SENTRY_DSN ??
87+
'https://798607831167c7b9fe2f2912f5d3c665@o4509258288332800.ingest.de.sentry.io/4509258293837904',
8288

8389
// Setting this option to true will send default PII data to Sentry
8490
// For example, automatic IP address collection on events
@@ -88,40 +94,30 @@ Sentry.init({
8894
release: `xcodebuildmcp@${version}`,
8995

9096
// Set environment based on NODE_ENV
91-
environment: process.env.NODE_ENV ?? 'development',
97+
environment: process.env.NODE_ENV ?? 'production',
9298

9399
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring
94100
// We recommend adjusting this value in production
95101
tracesSampleRate: 1.0,
96102
});
97103

104+
const axeAvailable = checkBinaryAvailability('axe');
105+
const miseAvailable = checkBinaryAvailability('mise');
106+
const envVars = getEnvironmentVariables();
107+
const xcodeInfo = getXcodeInfo();
108+
98109
// Add additional context that might be helpful for debugging
99110
const tags: Record<string, string> = {
100111
nodeVersion: process.version,
101112
platform: process.platform,
102113
arch: process.arch,
114+
axeAvailable: axeAvailable.available ? 'true' : 'false',
115+
axeVersion: axeAvailable.version ?? 'Unknown',
116+
miseAvailable: miseAvailable.available ? 'true' : 'false',
117+
miseVersion: miseAvailable.version ?? 'Unknown',
118+
...Object.fromEntries(Object.entries(envVars).map(([k, v]) => [`env_${k}`, v ?? ''])),
119+
xcodeVersion: xcodeInfo.version ?? 'Unknown',
120+
xcodePath: xcodeInfo.path ?? 'Unknown',
103121
};
104122

105-
// Only add Xcode Info if it's available
106-
const xcodeInfo = getXcodeInfo();
107-
if (!xcodeInfo.error) {
108-
tags.xcodeVersion = xcodeInfo.version;
109-
tags.xcodePath = xcodeInfo.path;
110-
} else {
111-
tags.xcodeVersion = 'Unknown';
112-
tags.xcodePath = 'Unknown';
113-
}
114-
115-
const envVars = getEnvironmentVariables();
116-
tags.env_XCODEBUILDMCP_DEBUG = envVars['XCODEBUILDMCP_DEBUG'] ?? 'false';
117-
tags.env_XCODEMAKE_ENABLED = envVars['INCREMENTAL_BUILDS_ENABLED'] ?? 'false';
118-
119-
const miseAvailable = checkBinaryAvailability('mise');
120-
tags.miseAvailable = miseAvailable.available ? 'true' : 'false';
121-
tags.miseVersion = miseAvailable.version ?? 'Unknown';
122-
123-
const axeAvailable = checkBinaryAvailability('axe');
124-
tags.axeAvailable = axeAvailable.available ? 'true' : 'false';
125-
tags.axeVersion = axeAvailable.version ?? 'Unknown';
126-
127123
Sentry.setTags(tags);

0 commit comments

Comments
 (0)