|
130 | 130 |
|
131 | 131 | import {Flags} from '@oclif/core'; |
132 | 132 | import {BaseCommand, MrtCommand, InstanceCommand} from '@salesforce/b2c-tooling-sdk/cli'; |
| 133 | +import {createTelemetry, type Telemetry} from '@salesforce/b2c-tooling-sdk/telemetry'; |
133 | 134 | import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; |
134 | 135 | import {B2CDxMcpServer} from '../server.js'; |
135 | 136 | import {Services} from '../services.js'; |
136 | 137 | import {registerToolsets} from '../registry.js'; |
137 | | -import {TOOLSETS, type StartupFlags} from '../utils/index.js'; |
138 | | -import {Telemetry} from '../utils/telemetry.js'; |
| 138 | +import {TOOLSETS, type StartupFlags, loadAppInsightsKey} from '../utils/index.js'; |
139 | 139 |
|
140 | 140 | /** |
141 | 141 | * oclif Command that starts the B2C DX MCP server. |
@@ -250,28 +250,18 @@ export default class McpServerCommand extends BaseCommand<typeof McpServerComman |
250 | 250 | // Initialize telemetry unless disabled |
251 | 251 | let telemetry: Telemetry | undefined; |
252 | 252 | if (!this.flags['no-telemetry']) { |
253 | | - telemetry = new Telemetry({ |
254 | | - toolsets: (startupFlags.toolsets ?? []).join(','), |
| 253 | + telemetry = createTelemetry({ |
| 254 | + project: 'b2c-dx-mcp', |
| 255 | + appInsightsKey: loadAppInsightsKey(), |
255 | 256 | version: this.config.version, |
| 257 | + initialAttributes: { |
| 258 | + toolsets: (startupFlags.toolsets ?? []).join(', '), |
| 259 | + }, |
256 | 260 | }); |
257 | 261 | await telemetry.start(); |
258 | | - |
259 | | - // Set up process exit handlers to send SERVER_STATUS stopped events |
260 | | - const sendStop = (signal: string): void => { |
261 | | - telemetry?.sendEvent('SERVER_STATUS', {status: 'stopped', signal}); |
| 262 | + process.stdin.on('close', (err) => { |
| 263 | + telemetry?.sendEvent(err ? 'SERVER_STOPPED_ERROR' : 'SERVER_STOPPED_SUCCESS'); |
262 | 264 | telemetry?.stop(); |
263 | | - }; |
264 | | - |
265 | | - process.on('exit', () => sendStop('exit')); |
266 | | - process.on('SIGINT', () => { |
267 | | - sendStop('SIGINT'); |
268 | | - // eslint-disable-next-line n/no-process-exit |
269 | | - process.exit(0); |
270 | | - }); |
271 | | - process.on('SIGTERM', () => { |
272 | | - sendStop('SIGTERM'); |
273 | | - // eslint-disable-next-line n/no-process-exit |
274 | | - process.exit(0); |
275 | 265 | }); |
276 | 266 | } |
277 | 267 |
|
|
0 commit comments