telemetry-dev-litellm 0.2.6__tar.gz → 0.2.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: telemetry-dev-litellm
3
- Version: 0.2.6
3
+ Version: 0.2.8
4
4
  Summary: LiteLLM integration for telemetry.dev Python SDK
5
5
  Keywords: telemetry,opentelemetry,llm,genai,litellm,tracing
6
6
  Author: telemetry.dev
@@ -152,7 +152,7 @@ Aggregate usage keys are `input_tokens`, `output_tokens`, `total_tokens`, `cache
152
152
 
153
153
  ## Metadata
154
154
 
155
- On a LiteLLM or Router call made outside the LiteLLM proxy, each key of the call's `litellm_metadata` argument, or of `metadata` when `litellm_metadata` is absent or empty, is exported as `td.metadata.<key>`, except the keys listed below. That includes keys LiteLLM's Router adds to the argument, such as `model_group`, `deployment`, `model_info` and `api_base`. Rerank spans also add `result_count` and `search_units`.
155
+ On a LiteLLM or Router call made outside the LiteLLM proxy, each key of the call's `litellm_metadata` argument, or of `metadata` when `litellm_metadata` is absent or empty, is exported as `td.metadata.<key>`, except the keys listed below. That includes keys LiteLLM's Router adds to the argument, such as `model_group` and `deployment`, and the Router's additions to `tags`: the picked deployment's own tags and, for a deployment that uses a stored credential, `Credential: <name>`. Rerank spans also add `result_count` and `search_units`.
156
156
 
157
157
  Strings, numbers, booleans and non-empty sequences of only strings, only booleans or only numbers are exported as they are; other values, including empty sequences, are JSON-encoded. When `max_attribute_length` is set, each string, including each string in a sequence, and each JSON value is truncated to it; by default they are exported whole, or cut at 65,536 characters with `telemetry-dev` 0.3.2 or earlier. Metadata values are not passed to the `mask` callback, and metadata is exported whatever `capture_input` and `capture_output` are set to.
158
158
 
@@ -160,6 +160,7 @@ These top-level keys are always dropped:
160
160
 
161
161
  - `headers`, `requester_metadata`, `requester_ip_address`, `user_agent`, `endpoint`, `user_api_end_user_max_budget`, and every key that starts with `user_api_key`. LiteLLM's proxy stores the incoming request's headers, client IP address, user agent and URL under these names, along with the authenticated key, user, team and end user, including the user's email and JWT claims.
162
162
  - `previous_models`, where the Router keeps copies of the arguments and metadata of earlier failed calls on a retry or fallback.
163
+ - `model_info`, `api_base` and `kubernetes_pod_routing`, where the Router writes the deployment it picked: `model_info` holds any fields an admin configured for the deployment, an `api_base` URL can contain credentials, and `kubernetes_pod_routing` holds the internal service host and pod IP of a deployment found through Kubernetes pod discovery.
163
164
  - `userId`, `sessionId`, `user_id` and `session_id`, which the core SDK reserves. Use `propagate_attributes(user_id=..., session_id=...)` instead.
164
165
 
165
166
  Don't use these names for your own metadata. Other keys, including nested values, are exported as they are, so don't put credentials or personal data in metadata.
@@ -169,7 +170,7 @@ Don't use these names for your own metadata. Other keys, including nested values
169
170
  When LiteLLM's proxy server handles a request, the call it makes through its Router carries a `proxy_server_request` argument. For every call with that argument, the integration reads metadata differently. The proxy and its guardrails and hooks write their own data into both metadata arguments, such as the request's headers, the authenticated key and user, or Presidio's `pii_tokens`. So only part of one argument is read: `litellm_metadata` for Responses calls, and `metadata` for chat, embedding and rerank calls. These are the arguments the proxy and Router write into for those calls. Two parts of it are exported:
170
171
 
171
172
  - `requester_metadata`, the proxy's copy of the request body's `metadata` object. The proxy takes this copy before its guardrails and hooks run, but after authentication and request preparation have added data to the body's metadata, such as the `x-litellm-tags` header and the key's tags. So these keys of the copy are not exported, even when the client sent them in the body: `tags`, `spend_logs_metadata`, `agent_id`, `trace_id`, `session_id`, `used_client_oauth_token` and `litellm_session_id_omitted`, plus the keys dropped for every call listed above. If the body has no `metadata` object, nothing from `requester_metadata` is exported.
172
- - The Router's `model_group`, `model_group_alias`, `model_group_size`, `deployment`, `deployment_model_name`, `attempted_retries` and `max_retries`, when that argument holds a string, number or boolean under them. Objects, lists and `null` under these names are not exported. The Router's `model_info` and `api_base` are not exported, because `model_info` holds any fields an admin configured for the deployment and an `api_base` URL can contain credentials.
173
+ - The Router's `model_group`, `model_group_alias`, `model_group_size`, `deployment`, `deployment_model_name`, `attempted_retries` and `max_retries`, when that argument holds a string, number or boolean under them. Objects, lists and `null` under these names are not exported.
173
174
 
174
175
  Anything else is not exported, including keys the client sends in the body's `litellm_metadata`. Some limits remain:
175
176
 
@@ -128,7 +128,7 @@ Aggregate usage keys are `input_tokens`, `output_tokens`, `total_tokens`, `cache
128
128
 
129
129
  ## Metadata
130
130
 
131
- On a LiteLLM or Router call made outside the LiteLLM proxy, each key of the call's `litellm_metadata` argument, or of `metadata` when `litellm_metadata` is absent or empty, is exported as `td.metadata.<key>`, except the keys listed below. That includes keys LiteLLM's Router adds to the argument, such as `model_group`, `deployment`, `model_info` and `api_base`. Rerank spans also add `result_count` and `search_units`.
131
+ On a LiteLLM or Router call made outside the LiteLLM proxy, each key of the call's `litellm_metadata` argument, or of `metadata` when `litellm_metadata` is absent or empty, is exported as `td.metadata.<key>`, except the keys listed below. That includes keys LiteLLM's Router adds to the argument, such as `model_group` and `deployment`, and the Router's additions to `tags`: the picked deployment's own tags and, for a deployment that uses a stored credential, `Credential: <name>`. Rerank spans also add `result_count` and `search_units`.
132
132
 
133
133
  Strings, numbers, booleans and non-empty sequences of only strings, only booleans or only numbers are exported as they are; other values, including empty sequences, are JSON-encoded. When `max_attribute_length` is set, each string, including each string in a sequence, and each JSON value is truncated to it; by default they are exported whole, or cut at 65,536 characters with `telemetry-dev` 0.3.2 or earlier. Metadata values are not passed to the `mask` callback, and metadata is exported whatever `capture_input` and `capture_output` are set to.
134
134
 
@@ -136,6 +136,7 @@ These top-level keys are always dropped:
136
136
 
137
137
  - `headers`, `requester_metadata`, `requester_ip_address`, `user_agent`, `endpoint`, `user_api_end_user_max_budget`, and every key that starts with `user_api_key`. LiteLLM's proxy stores the incoming request's headers, client IP address, user agent and URL under these names, along with the authenticated key, user, team and end user, including the user's email and JWT claims.
138
138
  - `previous_models`, where the Router keeps copies of the arguments and metadata of earlier failed calls on a retry or fallback.
139
+ - `model_info`, `api_base` and `kubernetes_pod_routing`, where the Router writes the deployment it picked: `model_info` holds any fields an admin configured for the deployment, an `api_base` URL can contain credentials, and `kubernetes_pod_routing` holds the internal service host and pod IP of a deployment found through Kubernetes pod discovery.
139
140
  - `userId`, `sessionId`, `user_id` and `session_id`, which the core SDK reserves. Use `propagate_attributes(user_id=..., session_id=...)` instead.
140
141
 
141
142
  Don't use these names for your own metadata. Other keys, including nested values, are exported as they are, so don't put credentials or personal data in metadata.
@@ -145,7 +146,7 @@ Don't use these names for your own metadata. Other keys, including nested values
145
146
  When LiteLLM's proxy server handles a request, the call it makes through its Router carries a `proxy_server_request` argument. For every call with that argument, the integration reads metadata differently. The proxy and its guardrails and hooks write their own data into both metadata arguments, such as the request's headers, the authenticated key and user, or Presidio's `pii_tokens`. So only part of one argument is read: `litellm_metadata` for Responses calls, and `metadata` for chat, embedding and rerank calls. These are the arguments the proxy and Router write into for those calls. Two parts of it are exported:
146
147
 
147
148
  - `requester_metadata`, the proxy's copy of the request body's `metadata` object. The proxy takes this copy before its guardrails and hooks run, but after authentication and request preparation have added data to the body's metadata, such as the `x-litellm-tags` header and the key's tags. So these keys of the copy are not exported, even when the client sent them in the body: `tags`, `spend_logs_metadata`, `agent_id`, `trace_id`, `session_id`, `used_client_oauth_token` and `litellm_session_id_omitted`, plus the keys dropped for every call listed above. If the body has no `metadata` object, nothing from `requester_metadata` is exported.
148
- - The Router's `model_group`, `model_group_alias`, `model_group_size`, `deployment`, `deployment_model_name`, `attempted_retries` and `max_retries`, when that argument holds a string, number or boolean under them. Objects, lists and `null` under these names are not exported. The Router's `model_info` and `api_base` are not exported, because `model_info` holds any fields an admin configured for the deployment and an `api_base` URL can contain credentials.
149
+ - The Router's `model_group`, `model_group_alias`, `model_group_size`, `deployment`, `deployment_model_name`, `attempted_retries` and `max_retries`, when that argument holds a string, number or boolean under them. Objects, lists and `null` under these names are not exported.
149
150
 
150
151
  Anything else is not exported, including keys the client sends in the body's `litellm_metadata`. Some limits remain:
151
152
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telemetry-dev-litellm"
3
- version = "0.2.6"
3
+ version = "0.2.8"
4
4
  description = "LiteLLM integration for telemetry.dev Python SDK"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telemetry-dev-litellm"
3
- version = "0.2.6"
3
+ version = "0.2.8"
4
4
  description = "LiteLLM integration for telemetry.dev Python SDK"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -16,8 +16,9 @@ from typing import Any, TypeVar, cast
16
16
  import litellm
17
17
  import telemetry_dev
18
18
  from opentelemetry import trace
19
+ from telemetry_dev._serialize import json_dumps
19
20
 
20
- __version__ = "0.2.6"
21
+ __version__ = "0.2.8"
21
22
 
22
23
  RequestMapper = Callable[[tuple[Any, ...], Mapping[str, Any]], tuple[str, dict[str, Any]]]
23
24
  ResponseMapper = Callable[[Any], dict[str, Any]]
@@ -403,11 +404,14 @@ _PROXY_REQUEST_METADATA_KEYS = frozenset(
403
404
  }
404
405
  )
405
406
  _PROXY_AUTH_METADATA_PREFIX = "user_api_key"
407
+ # Keys the Router writes into the caller's metadata argument for the deployment it picked,
408
+ # dropped on every call: model_info holds whatever fields an admin configured for the
409
+ # deployment, an api_base URL can carry credentials, and kubernetes_pod_routing (LiteLLM 1.110
410
+ # and later) holds the internal service host and pod IP of a pod-discovered deployment.
411
+ _ROUTER_DEPLOYMENT_METADATA_KEYS = frozenset({"model_info", "api_base", "kubernetes_pod_routing"})
406
412
 
407
413
  # Keys the Router writes into the metadata argument when it picks a deployment and retries,
408
414
  # exported on the proxy only with a scalar value, since a hook can write anything under them.
409
- # model_info and api_base are left out: model_info holds whatever fields an admin configured
410
- # for the deployment, and an api_base URL can carry credentials.
411
415
  _PROXY_ROUTER_METADATA_KEYS = (
412
416
  "model_group",
413
417
  "model_group_alias",
@@ -452,6 +456,7 @@ def _request_metadata(
452
456
  key: value
453
457
  for key, value in metadata.items()
454
458
  if str(key) not in _PROXY_REQUEST_METADATA_KEYS
459
+ and str(key) not in _ROUTER_DEPLOYMENT_METADATA_KEYS
455
460
  and not str(key).startswith(_PROXY_AUTH_METADATA_PREFIX)
456
461
  }
457
462
 
@@ -501,6 +506,39 @@ def _prompt_attributes(messages: object) -> dict[str, Any]:
501
506
  return cast("dict[str, Any]", read(messages)) if callable(read) else {}
502
507
 
503
508
 
509
+ def _tool_definitions(tools: Any) -> dict[str, str] | None:
510
+ """The request tools, in the OpenAI format, as ``gen_ai.tool.definitions``: each tool's type
511
+ and name, and with input capture on a function or custom tool's description and its
512
+ parameters (custom tools: their input format). Chat Completions nests a tool under
513
+ ``function`` or ``custom``; Responses puts it at the top. A built-in tool without a name is
514
+ listed by its type. The core SDK also strips descriptions and schemas with capture off; this
515
+ check keeps them out with a core older than that rule."""
516
+ client = telemetry_dev.get_client()
517
+ content = client is not None and client.capture_input
518
+ definitions: list[dict[str, Any]] = []
519
+ for tool in _sequence_items(tools):
520
+ kind = _string(_field(tool, "type"))
521
+ if kind is None:
522
+ continue
523
+ spec = _field(tool, "custom" if kind == "custom" else "function") or tool
524
+ name = _string(_field(spec, "name"))
525
+ if kind not in ("function", "custom"):
526
+ definitions.append({"type": kind} if name is None else {"type": kind, "name": name})
527
+ continue
528
+ if name is None:
529
+ continue
530
+ definition: dict[str, Any] = {"type": kind, "name": name}
531
+ if content:
532
+ description = _string(_field(spec, "description"))
533
+ if description is not None:
534
+ definition["description"] = description
535
+ parameters = _field(spec, "format" if kind == "custom" else "parameters")
536
+ if parameters is not None:
537
+ definition["parameters"] = parameters
538
+ definitions.append(definition)
539
+ return {"gen_ai.tool.definitions": _tools_json(definitions)} if definitions else None
540
+
541
+
504
542
  def _completion_request(
505
543
  args: tuple[Any, ...], kwargs: Mapping[str, Any]
506
544
  ) -> tuple[str, dict[str, Any]]:
@@ -524,7 +562,11 @@ def _completion_request(
524
562
  "presence_penalty": _number(kwargs.get("presence_penalty")),
525
563
  "output_type": _output_type(kwargs.get("response_format")),
526
564
  "metadata": _request_metadata(kwargs),
527
- "attributes": _prompt_attributes(_arg(args, kwargs, "messages", 1)) or None,
565
+ "attributes": {
566
+ **(_tool_definitions(kwargs.get("tools")) or {}),
567
+ **_prompt_attributes(_arg(args, kwargs, "messages", 1)),
568
+ }
569
+ or None,
528
570
  },
529
571
  )
530
572
 
@@ -594,6 +636,7 @@ def _responses_request(
594
636
  input_value, input_budget = _bounded_responses_native(_arg(args, kwargs, "input", 0))
595
637
  attributes: dict[str, Any] = {
596
638
  "gen_ai.operation.name": "chat",
639
+ **(_tool_definitions(kwargs.get("tools")) or {}),
597
640
  **_prompt_attributes(_arg(args, kwargs, "input", 0)),
598
641
  }
599
642
  if input_budget is not None and input_budget.truncated:
@@ -2352,3 +2395,14 @@ __all__ = [
2352
2395
  "uninstrument_litellm",
2353
2396
  "wrap_router",
2354
2397
  ]
2398
+
2399
+
2400
+ def _tools_json(definitions: list[dict[str, Any]]) -> str:
2401
+ """The definitions as JSON, or only their types and names when a schema cannot be
2402
+ serialized, such as one holding a cycle: the wrapper maps the request outside any catch."""
2403
+ try:
2404
+ return json_dumps(definitions)
2405
+ except (TypeError, ValueError):
2406
+ return json_dumps(
2407
+ [{key: tool[key] for key in ("type", "name") if key in tool} for tool in definitions]
2408
+ )