Skip to content

Commit ff7d1af

Browse files
committed
get custom transport names
1 parent a4f7b8c commit ff7d1af

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

packages/core/src/integrations/mcp-server/attributeExtraction.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,16 @@ import type {
4545
* @returns Transport type mapping for span attributes
4646
*/
4747
export function getTransportTypes(transport: MCPTransport): { mcpTransport: string; networkTransport: string } {
48-
// Handle undefined transport gracefully while preserving type detection
4948
if (!transport?.constructor) {
5049
return { mcpTransport: 'unknown', networkTransport: 'unknown' };
5150
}
52-
const transportName = transport.constructor.name?.toLowerCase() || '';
51+
const transportName = transport.constructor.name?.toLowerCase() || 'unknown';
52+
const networkTransport = transportName === 'stdio' ? 'pipe' : 'tcp';
5353

54-
if (transportName.includes('stdio')) {
55-
return { mcpTransport: 'stdio', networkTransport: 'pipe' };
56-
}
57-
58-
if (transportName.includes('streamablehttp') || transportName.includes('streamable')) {
59-
return { mcpTransport: 'http', networkTransport: 'tcp' };
60-
}
61-
62-
if (transportName.includes('sse')) {
63-
return { mcpTransport: 'sse', networkTransport: 'tcp' };
64-
}
65-
66-
return { mcpTransport: 'unknown', networkTransport: 'unknown' };
54+
return {
55+
mcpTransport: transportName,
56+
networkTransport,
57+
};
6758
}
6859

6960
/**
@@ -264,17 +255,13 @@ export function extractClientInfo(extra: ExtraHandlerData): {
264255
* @param transport - MCP transport instance
265256
* @param extra - Optional extra handler data
266257
* @returns Transport attributes for span instrumentation
258+
* @note sessionId may be undefined during initial setup - session should be established by client during initialize flow
267259
*/
268260
export function buildTransportAttributes(
269261
transport: MCPTransport,
270262
extra?: ExtraHandlerData,
271263
): Record<string, string | number> {
272-
// Gracefully handle undefined sessionId during MCP initialization
273-
// Respects client-provided sessions and waits for proper session establishment
274264
const sessionId = transport && 'sessionId' in transport ? transport.sessionId : undefined;
275-
276-
// Note: sessionId may be undefined during initial setup - this is expected behavior
277-
// The actual session should be established by the client during the initialize flow
278265
const clientInfo = extra ? extractClientInfo(extra) : {};
279266
const { mcpTransport, networkTransport } = getTransportTypes(transport);
280267
const clientAttributes = getClientAttributes(transport);

0 commit comments

Comments
 (0)