Skip to content

Commit a3c5ece

Browse files
committed
fix: rename app_name to app
1 parent 209e41f commit a3c5ece

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/mcp/server.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Model Context Protocol (MCP) server for Apify Actors
33
*/
44

5+
import * as crypto from 'node:crypto';
6+
57
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
68
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
79
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
@@ -764,7 +766,7 @@ Please verify the tool name and ensure the tool is properly registered.`;
764766
*/
765767
private finalizeAndTrackTelemetry(
766768
telemetryData: ToolCallTelemetryProperties | null,
767-
userId: string | null,
769+
userId: string,
768770
startTime: number,
769771
toolStatus: 'succeeded' | 'failed' | 'aborted',
770772
): void {
@@ -786,9 +788,9 @@ Please verify the tool name and ensure the tool is properly registered.`;
786788
*/
787789
private async prepareTelemetryData(
788790
tool: HelperTool | ActorTool | ActorMcpTool, mcpSessionId: string | undefined, apifyToken: string,
789-
): Promise<{ telemetryData: ToolCallTelemetryProperties | null; userId: string | null }> {
791+
): Promise<{ telemetryData: ToolCallTelemetryProperties | null; userId: string }> {
790792
if (this.options.telemetry?.enabled !== true) {
791-
return { telemetryData: null, userId: null };
793+
return { telemetryData: null, userId: crypto.randomUUID() };
792794
}
793795

794796
const toolFullName = tool.type === 'actor' ? tool.actorFullName : tool.name;
@@ -810,11 +812,15 @@ Please verify the tool name and ensure the tool is properly registered.`;
810812
userId = await getUserIdFromTokenCached(apifyToken, apifyClient);
811813
log.debug('Telemetry: fetched userId', { userId });
812814
}
815+
if (!userId) {
816+
userId = crypto.randomUUID();
817+
log.debug('Telemetry: using random userId', { userId });
818+
}
813819

814820
const capabilities = this.options.initializeRequestData?.params?.capabilities;
815821
const params = this.options.initializeRequestData?.params as InitializeRequest['params'];
816822
const telemetryData: ToolCallTelemetryProperties = {
817-
app_name: 'apify-mcp-server',
823+
app: 'mcp',
818824
app_version: getPackageVersion() || '',
819825
mcp_client_name: params?.clientInfo?.name || '',
820826
mcp_client_version: params?.clientInfo?.version || '',

src/telemetry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function getOrInitAnalyticsClient(): Analytics | null {
6262
* @param properties - Event properties for the tool call
6363
*/
6464
export function trackToolCall(
65-
userId: string | null,
65+
userId: string,
6666
properties: ToolCallTelemetryProperties,
6767
): void {
6868
const client = getOrInitAnalyticsClient();
@@ -73,7 +73,7 @@ export function trackToolCall(
7373

7474
try {
7575
client.track({
76-
userId: userId || '',
76+
userId,
7777
event: SEGMENT_EVENTS.TOOL_CALL,
7878
properties,
7979
});

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export type ApifyToken = string | null | undefined;
298298
* Properties for tool call telemetry events sent to Segment.
299299
*/
300300
export interface ToolCallTelemetryProperties {
301-
app_name: string;
301+
app: 'mcp';
302302
app_version: string;
303303
mcp_client_name: string;
304304
mcp_client_version: string;

tests/unit/telemetry.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('telemetry', () => {
1818
it('should send correct payload structure to Segment', () => {
1919
const userId = 'test-user-123';
2020
const properties = {
21-
app_name: 'apify-mcp-server',
21+
app: 'mcp' as const,
2222
app_version: '0.5.6',
2323
mcp_client_name: 'test-client',
2424
mcp_client_version: '1.0.0',
@@ -38,7 +38,7 @@ describe('telemetry', () => {
3838
userId: 'test-user-123',
3939
event: 'MCP Tool Call',
4040
properties: {
41-
app_name: 'apify-mcp-server',
41+
app: 'mcp',
4242
app_version: '0.5.6',
4343
mcp_client_name: 'test-client',
4444
mcp_client_version: '1.0.0',

0 commit comments

Comments
 (0)