()
| 63 | `; |
| 64 | |
| 65 | async function main() { |
| 66 | console.log('✨ Starting Local Telemetry Exporter for Google Cloud ✨'); |
| 67 | |
| 68 | let collectorProcess; |
| 69 | let collectorLogFd; |
| 70 | |
| 71 | const originalSandboxSetting = manageTelemetrySettings( |
| 72 | true, |
| 73 | 'http://localhost:4317', |
| 74 | 'gcp', |
| 75 | ); |
| 76 | registerCleanup( |
| 77 | () => [collectorProcess].filter((p) => p), // Function to get processes |
| 78 | () => [collectorLogFd].filter((fd) => fd), // Function to get FDs |
| 79 | originalSandboxSetting, |
| 80 | ); |
| 81 | |
| 82 | const projectId = process.env.OTLP_GOOGLE_CLOUD_PROJECT; |
| 83 | if (!projectId) { |
| 84 | console.error( |
| 85 | '🛑 Error: OTLP_GOOGLE_CLOUD_PROJECT environment variable is not exported.', |
| 86 | ); |
| 87 | console.log( |
| 88 | ' Please set it to your Google Cloud Project ID and try again.', |
| 89 | ); |
| 90 | console.log(' `export OTLP_GOOGLE_CLOUD_PROJECT=your-project-id`'); |
| 91 | process.exit(1); |
| 92 | } |
| 93 | console.log(`✅ Using OTLP Google Cloud Project ID: ${projectId}`); |
| 94 | |
| 95 | console.log('\n🔑 Please ensure you are authenticated with Google Cloud:'); |
| 96 | console.log( |
| 97 | ' - Run `gcloud auth application-default login` OR ensure `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a valid service account key.', |
| 98 | ); |
| 99 | console.log( |
| 100 | ' - The account needs "Cloud Trace Agent", "Monitoring Metric Writer", and "Logs Writer" roles.', |
| 101 | ); |
| 102 | |
| 103 | if (!fileExists(BIN_DIR)) fs.mkdirSync(BIN_DIR, { recursive: true }); |
| 104 | |
| 105 | const otelcolPath = await ensureBinary( |
| 106 | 'otelcol-contrib', |
| 107 | 'open-telemetry/opentelemetry-collector-releases', |
| 108 | (version, platform, arch, ext) => |
| 109 | `otelcol-contrib_${version}_${platform}_${arch}.${ext}`, |
| 110 | 'otelcol-contrib', |
| 111 | false, // isJaeger = false |
| 112 | ).catch((e) => { |
| 113 | console.error(`🛑 Error getting otelcol-contrib: ${e.message}`); |
| 114 | return null; |
| 115 | }); |
| 116 | if (!otelcolPath) process.exit(1); |
| 117 | |
| 118 | console.log('🧹 Cleaning up old processes and logs...'); |
| 119 | try { |
| 120 | execSync('pkill -f "otelcol-contrib"'); |
| 121 | console.log('✅ Stopped existing otelcol-contrib process.'); |
| 122 | } catch (_e) { |
no test coverage detected