Skip to content

Commit 1b466c8

Browse files
committed
Replace ddtrace with telemetry
1 parent 624ef30 commit 1b466c8

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

ddtrace/contrib/internal/mcp/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def traced_request_responder_enter(mcp, pin: Pin, func, instance, args: tuple, k
243243
setattr(instance, "_dd_span", span)
244244

245245
if isinstance(request_root, CallToolRequest):
246-
integration.process_ddtrace_argument(span, request_root)
246+
integration.process_telemetry_argument(span, request_root)
247247

248248
return func(*args, **kwargs)
249249

ddtrace/llmobs/_integrations/mcp.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
SERVER_TOOL_CALL_OPERATION_NAME = "server_tool_call"
3939

4040

41-
DD_TRACE_KEY = "ddtrace"
41+
TELEMETRY_KEY = "telemetry"
4242
INTENT_KEY = "intent"
4343
INTENT_PROMPT = """Briefly describe the wider context task, and why this tool was chosen.
4444
Omit argument values, PII/secrets. Use English.
@@ -108,7 +108,7 @@ def inject_tools_list_response(self, response: "ListToolsResult") -> None:
108108
if "required" not in input_schema:
109109
input_schema["required"] = []
110110

111-
input_schema["properties"][DD_TRACE_KEY] = dd_trace_input_schema()
111+
input_schema["properties"][TELEMETRY_KEY] = dd_trace_input_schema()
112112
input_schema["required"].append(INTENT_KEY)
113113

114114
def _parse_mcp_text_content(self, item: Any) -> Dict[str, Any]:
@@ -245,23 +245,23 @@ def _set_call_tool_request_overrides(
245245
_set_or_update_tags(span, override_tags)
246246
span._set_ctx_items({NAME: tool_name, SPAN_KIND: "tool"})
247247

248-
def process_ddtrace_argument(self, span: Span, request: "CallToolRequest") -> None:
249-
"""Process and remove ddtrace argument from requests
248+
def process_telemetry_argument(self, span: Span, request: "CallToolRequest") -> None:
249+
"""Process and remove telemetry argument from requests
250250
This is called before the tool is called or the input is recorded
251251
"""
252252
if not self.llmobs_enabled:
253253
return
254254

255255
params = _get_attr(request, "params", None)
256256
arguments = _get_attr(params, "arguments", None)
257-
ddtrace = _get_attr(arguments, DD_TRACE_KEY, None)
258-
if isinstance(arguments, dict) and ddtrace:
259-
intent = _get_attr(ddtrace, INTENT_KEY, None)
257+
telemetry = _get_attr(arguments, TELEMETRY_KEY, None)
258+
if isinstance(arguments, dict) and telemetry:
259+
intent = _get_attr(telemetry, INTENT_KEY, None)
260260
if intent:
261261
span._set_ctx_item(MCP_TOOL_CALL_INTENT, intent)
262262

263263
# The argument is removed before recording the input and calling the tool
264-
del arguments[DD_TRACE_KEY]
264+
del arguments[TELEMETRY_KEY]
265265

266266
def _llmobs_set_tags_request_responder_respond(
267267
self, span: Span, args: List[Any], kwargs: Dict[str, Any], response: Any
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
other:
3+
- |
4+
When using the intent capture feature of the MCP integration, a tool argument is injected.
5+
The name of the argument is renamed from ``ddtrace`` to ``telemetry``.

tests/contrib/mcp/test_mcp_llmobs.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ async def test():
328328

329329

330330
def test_intent_capture_tool_schema_injection(mcp_setup, mock_tracer, llmobs_events, mcp_server):
331-
"""Test that intent capture adds ddtrace property to tool input schemas."""
331+
"""Test that intent capture adds telemetry property to tool input schemas."""
332332
from mcp.shared.memory import create_connected_server_and_client_session
333333

334334
async def run_test():
@@ -341,14 +341,14 @@ async def run_test():
341341
tool = next(t for t in result.tools if t.name == "calculator")
342342
schema = tool.inputSchema
343343

344-
# Verify ddtrace property is injected
345-
assert "ddtrace" in schema["properties"], f"ddtrace not in properties: {schema}"
346-
ddtrace_schema = schema["properties"]["ddtrace"]
347-
assert ddtrace_schema["type"] == "object"
348-
assert "intent" in ddtrace_schema["properties"]
349-
assert ddtrace_schema["properties"]["intent"]["type"] == "string"
350-
assert "required" in ddtrace_schema
351-
assert "intent" in ddtrace_schema["required"]
344+
# Verify telemetry property is injected
345+
assert "telemetry" in schema["properties"], f"telemetry not in properties: {schema}"
346+
telemetry_schema = schema["properties"]["telemetry"]
347+
assert telemetry_schema["type"] == "object"
348+
assert "intent" in telemetry_schema["properties"]
349+
assert telemetry_schema["properties"]["intent"]["type"] == "string"
350+
assert "required" in telemetry_schema
351+
assert "intent" in telemetry_schema["required"]
352352

353353
# Verify original tool arguments are unchanged
354354
assert "operation" in schema["properties"]
@@ -366,7 +366,7 @@ async def run_test():
366366

367367

368368
def test_intent_capture_records_intent_on_span_meta(mcp_setup, mock_tracer, llmobs_events, mcp_server):
369-
"""Test that intent is recorded on the span meta and ddtrace argument is excluded from input."""
369+
"""Test that intent is recorded on the span meta and telemetry argument is excluded from input."""
370370
from mcp.shared.memory import create_connected_server_and_client_session
371371

372372
async def run_test():
@@ -377,7 +377,7 @@ async def run_test():
377377
"operation": "add",
378378
"a": 1,
379379
"b": 2,
380-
"ddtrace": {"intent": "Testing intent capture for adding numbers"},
380+
"telemetry": {"intent": "Testing intent capture for adding numbers"},
381381
},
382382
)
383383

@@ -395,17 +395,17 @@ async def run_test():
395395
assert "intent" in server_tool_event["meta"], f"intent not in meta: {server_tool_event['meta']}"
396396
assert server_tool_event["meta"]["intent"] == "Testing intent capture for adding numbers"
397397

398-
# Verify ddtrace argument is NOT in the input value
398+
# Verify telemetry argument is NOT in the input value
399399
input_value = json.loads(server_tool_event["meta"]["input"]["value"])
400400
arguments = input_value.get("params", {}).get("arguments", {})
401-
assert "ddtrace" not in arguments, f"ddtrace should not be in arguments: {arguments}"
401+
assert "telemetry" not in arguments, f"telemetry should not be in arguments: {arguments}"
402402
assert "operation" in arguments
403403
assert "a" in arguments
404404
assert "b" in arguments
405405

406406

407407
def test_intent_capture_disabled_by_default(mcp_setup, mock_tracer, llmobs_events, mcp_server):
408-
"""Test that intent capture is disabled by default and ddtrace property is not injected."""
408+
"""Test that intent capture is disabled by default and telemetry property is not injected."""
409409
from mcp.shared.memory import create_connected_server_and_client_session
410410

411411
async def run_test():
@@ -418,5 +418,5 @@ async def run_test():
418418
tool = next(t for t in result.tools if t.name == "calculator")
419419
schema = tool.inputSchema
420420

421-
# Verify ddtrace property is NOT injected when intent capture is disabled
422-
assert "ddtrace" not in schema.get("properties", {}), f"ddtrace should not be in properties: {schema}"
421+
# Verify telemetry property is NOT injected when intent capture is disabled
422+
assert "telemetry" not in schema.get("properties", {}), f"telemetry should not be in properties: {schema}"

0 commit comments

Comments
 (0)