telemetry-dev 0.3.5__tar.gz → 0.3.7__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.
Files changed (26) hide show
  1. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/PKG-INFO +12 -10
  2. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/README.md +11 -9
  3. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/pyproject.toml +1 -1
  4. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/pyproject.toml.orig +1 -1
  5. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/__init__.py +1 -1
  6. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_api.py +30 -21
  7. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/LICENSE +0 -0
  8. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_capture.py +0 -0
  9. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_ci.py +0 -0
  10. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_client.py +0 -0
  11. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_config.py +0 -0
  12. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_context.py +0 -0
  13. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_experiments.py +0 -0
  14. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_export.py +0 -0
  15. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_logs.py +0 -0
  16. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_metrics.py +0 -0
  17. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_observe.py +0 -0
  18. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_process_lock.py +0 -0
  19. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_processor.py +0 -0
  20. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_prompts.py +0 -0
  21. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_scores.py +0 -0
  22. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_semconv.py +0 -0
  23. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_serialize.py +0 -0
  24. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/_spans.py +0 -0
  25. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/otel.py +0 -0
  26. {telemetry_dev-0.3.5 → telemetry_dev-0.3.7}/src/telemetry_dev/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: telemetry-dev
3
- Version: 0.3.5
3
+ Version: 0.3.7
4
4
  Summary: telemetry.dev SDK for Python — OpenTelemetry-native GenAI tracing, logs, and metrics
5
5
  Keywords: telemetry,opentelemetry,llm,genai,tracing,observability
6
6
  Author: telemetry.dev
@@ -57,9 +57,9 @@ def lookup_weather(city: str) -> dict:
57
57
 
58
58
  with propagate_attributes(user_id="user_123", session_id="session_456"):
59
59
  with start_span(
60
- "chat gpt-4o",
60
+ "chat gpt-6-luna",
61
61
  type="generation",
62
- model="gpt-4o",
62
+ model="gpt-6-luna",
63
63
  provider="openai",
64
64
  input=[{"role": "user", "content": "Plan a day trip"}],
65
65
  ):
@@ -243,7 +243,7 @@ messages = prompt.compile(customer_message=customer_message, tone=tone)
243
243
 
244
244
  with telemetry_dev.with_prompt(prompt):
245
245
  response = client.chat.completions.create(
246
- model=prompt.model["name"] if prompt.model else "gpt-4o", messages=messages
246
+ model=prompt.model["name"] if prompt.model else "gpt-6-luna", messages=messages
247
247
  )
248
248
 
249
249
  # Pin one version, as in a test:
@@ -362,7 +362,7 @@ import telemetry_dev
362
362
  telemetry_dev.init(environment="experiment")
363
363
 
364
364
  result = telemetry_dev.run_experiment(
365
- name="reply-v13-gpt-4o",
365
+ name="reply-v13-gpt-6-luna",
366
366
  dataset="support-golden",
367
367
  task=lambda item: reply_to_customer(item.input),
368
368
  evaluators=["correctness", "helpfulness"],
@@ -414,10 +414,12 @@ result = telemetry_dev.run_experiment(
414
414
  `missing_api_key`, or `timeout`. A read of the dataset or the result, a post of outputs, and the
415
415
  completion go again up to 2 times after a timeout, a network error, a 429, or a 5xx. The server
416
416
  skips an item run that it has. The request that makes the experiment goes again only after a
417
- 429, thus a lost response or a 503 cannot make a second experiment. When the run stops after it
418
- made the experiment, also after Ctrl-C or a cancellation, `run_experiment` sends the completion
419
- before it raises: telemetry.dev then ends the experiment with the item runs that it got, or fails
420
- it when it got none.
417
+ 429, thus a lost response or a 503 cannot make a second experiment. No request goes again after
418
+ a 429 `quota_exceeded`, which a cap of the plan gives, or after a 429 whose `Retry-After` is
419
+ more than 60 seconds: `run_experiment` raises at once with the message of the server. When the
420
+ run stops after it made the experiment, also after Ctrl-C or a cancellation, `run_experiment`
421
+ sends the completion before it raises: telemetry.dev then ends the experiment with the item runs
422
+ that it got, or fails it when it got none.
421
423
  - The key needs Run experiments in its Access on the API keys page (the `datasets:read` and
422
424
  `experiments:write` scopes). `run_experiment` uses the same
423
425
  API key and base URL as `get_prompt`, or its own `api_key` and `base_url`.
@@ -614,7 +616,7 @@ trace.set_tracer_provider(provider)
614
616
 
615
617
  client = Anthropic()
616
618
  client.messages.create(
617
- model="claude-sonnet-4-6",
619
+ model="claude-haiku-5-5",
618
620
  max_tokens=256,
619
621
  messages=[{"role": "user", "content": "Say hello."}],
620
622
  )
@@ -30,9 +30,9 @@ def lookup_weather(city: str) -> dict:
30
30
 
31
31
  with propagate_attributes(user_id="user_123", session_id="session_456"):
32
32
  with start_span(
33
- "chat gpt-4o",
33
+ "chat gpt-6-luna",
34
34
  type="generation",
35
- model="gpt-4o",
35
+ model="gpt-6-luna",
36
36
  provider="openai",
37
37
  input=[{"role": "user", "content": "Plan a day trip"}],
38
38
  ):
@@ -216,7 +216,7 @@ messages = prompt.compile(customer_message=customer_message, tone=tone)
216
216
 
217
217
  with telemetry_dev.with_prompt(prompt):
218
218
  response = client.chat.completions.create(
219
- model=prompt.model["name"] if prompt.model else "gpt-4o", messages=messages
219
+ model=prompt.model["name"] if prompt.model else "gpt-6-luna", messages=messages
220
220
  )
221
221
 
222
222
  # Pin one version, as in a test:
@@ -335,7 +335,7 @@ import telemetry_dev
335
335
  telemetry_dev.init(environment="experiment")
336
336
 
337
337
  result = telemetry_dev.run_experiment(
338
- name="reply-v13-gpt-4o",
338
+ name="reply-v13-gpt-6-luna",
339
339
  dataset="support-golden",
340
340
  task=lambda item: reply_to_customer(item.input),
341
341
  evaluators=["correctness", "helpfulness"],
@@ -387,10 +387,12 @@ result = telemetry_dev.run_experiment(
387
387
  `missing_api_key`, or `timeout`. A read of the dataset or the result, a post of outputs, and the
388
388
  completion go again up to 2 times after a timeout, a network error, a 429, or a 5xx. The server
389
389
  skips an item run that it has. The request that makes the experiment goes again only after a
390
- 429, thus a lost response or a 503 cannot make a second experiment. When the run stops after it
391
- made the experiment, also after Ctrl-C or a cancellation, `run_experiment` sends the completion
392
- before it raises: telemetry.dev then ends the experiment with the item runs that it got, or fails
393
- it when it got none.
390
+ 429, thus a lost response or a 503 cannot make a second experiment. No request goes again after
391
+ a 429 `quota_exceeded`, which a cap of the plan gives, or after a 429 whose `Retry-After` is
392
+ more than 60 seconds: `run_experiment` raises at once with the message of the server. When the
393
+ run stops after it made the experiment, also after Ctrl-C or a cancellation, `run_experiment`
394
+ sends the completion before it raises: telemetry.dev then ends the experiment with the item runs
395
+ that it got, or fails it when it got none.
394
396
  - The key needs Run experiments in its Access on the API keys page (the `datasets:read` and
395
397
  `experiments:write` scopes). `run_experiment` uses the same
396
398
  API key and base URL as `get_prompt`, or its own `api_key` and `base_url`.
@@ -587,7 +589,7 @@ trace.set_tracer_provider(provider)
587
589
 
588
590
  client = Anthropic()
589
591
  client.messages.create(
590
- model="claude-sonnet-4-6",
592
+ model="claude-haiku-5-5",
591
593
  max_tokens=256,
592
594
  messages=[{"role": "user", "content": "Say hello."}],
593
595
  )
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telemetry-dev"
3
- version = "0.3.5"
3
+ version = "0.3.7"
4
4
  description = "telemetry.dev SDK for Python — OpenTelemetry-native GenAI tracing, logs, and metrics"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telemetry-dev"
3
- version = "0.3.5"
3
+ version = "0.3.7"
4
4
  description = "telemetry.dev SDK for Python — OpenTelemetry-native GenAI tracing, logs, and metrics"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -6,7 +6,7 @@ Quickstart::
6
6
 
7
7
  telemetry_dev.init() # reads TELEMETRY_DEV_API_KEY
8
8
 
9
- with telemetry_dev.start_span("chat gpt-4o", type="generation", model="gpt-4o",
9
+ with telemetry_dev.start_span("chat gpt-6-luna", type="generation", model="gpt-6-luna",
10
10
  provider="openai", input=messages) as span:
11
11
  ...
12
12
  span.update(output=completion, usage={"input_tokens": 11, "output_tokens": 7})
@@ -20,7 +20,8 @@ from ._client import get_client
20
20
  from ._config import SDK_VERSION, resolve_config
21
21
  from ._serialize import json_dumps
22
22
 
23
- # A longer Retry-After waits only this long: the API counts requests by the minute.
23
+ # The longest wait before a retry: the API counts requests by the minute. A 429 with a longer
24
+ # Retry-After fails at once, and a 503 with a longer one waits only this long.
24
25
  _MAX_RETRY_AFTER_S = 60.0
25
26
  # IMF-fixdate, the HTTP date that servers send: Sun, 06 Nov 1994 08:49:37 GMT.
26
27
  _HTTP_DATE = re.compile(r"[A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} \d{2}:\d{2}:\d{2} GMT", re.ASCII)
@@ -52,6 +53,7 @@ def resolve_api(api_key: str | None, base_url: str | None) -> Api:
52
53
  @dataclass(frozen=True)
53
54
  class _Failure:
54
55
  error: Exception
56
+ code: str | None
55
57
  status: int | None
56
58
  retry_after: float | None
57
59
 
@@ -74,7 +76,8 @@ def request(
74
76
  ``http_<status>``. With ``idempotent``, the server takes a repeat at most once, so a timeout, a
75
77
  network error, or a 5xx tries again. Other requests try again only after a 429, which the rate
76
78
  limit answers before the server does any work: a 503 can come after the work committed. A
77
- retry waits for the Retry-After of the response, or for 1 and then 2 seconds. The timeout
79
+ retry waits for the Retry-After of the response, or for 1 and then 2 seconds. A 429
80
+ ``quota_exceeded``, or a 429 with a Retry-After past 60 seconds, raises at once. The timeout
78
81
  applies to each socket operation of urllib.
79
82
  """
80
83
  url = f"{api.base_url}{path}"
@@ -92,7 +95,7 @@ def request(
92
95
  result = _send(error_type, method, url, path, data, headers, timeout_s)
93
96
  if not isinstance(result, _Failure):
94
97
  return result
95
- if attempt >= attempts or not _retryable(result.status, idempotent):
98
+ if attempt >= attempts or not _retryable(result, idempotent):
96
99
  raise result.error
97
100
  time.sleep(min(result.retry_after or float(attempt), _MAX_RETRY_AFTER_S))
98
101
  attempt += 1
@@ -128,18 +131,7 @@ opener = urllib.request.build_opener(NoRedirect)
128
131
 
129
132
  def api_error(error_type: Callable[[str, str, int | None], E], status: int, body: bytes) -> E:
130
133
  """The error of a response that is not 2xx: its API code and message, or ``http_<status>``."""
131
- try:
132
- error = json.loads(body).get("error")
133
- except (ValueError, AttributeError):
134
- error = None
135
- fields = cast("dict[str, Any]", error) if isinstance(error, dict) else {}
136
- code = fields.get("code")
137
- message = fields.get("message")
138
- return error_type(
139
- code if isinstance(code, str) else f"http_{status}",
140
- message if isinstance(message, str) else f"telemetry.dev returned {status}",
141
- status,
142
- )
134
+ return error_type(*_code_and_message(status, body), status)
143
135
 
144
136
 
145
137
  def retry_after(status: int, value: str | None) -> float | None:
@@ -175,8 +167,10 @@ def _send(
175
167
  body: bytes = response.read()
176
168
  except urllib.error.HTTPError as exc:
177
169
  with exc:
170
+ code, message = _code_and_message(exc.code, exc.read())
178
171
  return _Failure(
179
- api_error(error_type, exc.code, exc.read()),
172
+ error_type(code, message, exc.code),
173
+ code,
180
174
  exc.code,
181
175
  retry_after(exc.code, exc.headers.get("Retry-After")),
182
176
  )
@@ -190,14 +184,29 @@ def _send(
190
184
  else error_type("network_error", "Could not reach telemetry.dev", None)
191
185
  )
192
186
  error.__cause__ = exc
193
- return _Failure(error, None, None)
187
+ return _Failure(error, None, None, None)
194
188
  try:
195
189
  return json.loads(body)
196
190
  except ValueError:
197
191
  return None
198
192
 
199
193
 
200
- def _retryable(status: int | None, idempotent: bool) -> bool:
201
- if status == 429:
202
- return True
203
- return idempotent and (status is None or status >= 500)
194
+ def _code_and_message(status: int, body: bytes) -> tuple[str, str]:
195
+ try:
196
+ error = json.loads(body).get("error")
197
+ except (ValueError, AttributeError):
198
+ error = None
199
+ fields = cast("dict[str, Any]", error) if isinstance(error, dict) else {}
200
+ code = fields.get("code")
201
+ message = fields.get("message")
202
+ return (
203
+ code if isinstance(code, str) else f"http_{status}",
204
+ message if isinstance(message, str) else f"telemetry.dev returned {status}",
205
+ )
206
+
207
+
208
+ def _retryable(failure: _Failure, idempotent: bool) -> bool:
209
+ if failure.status == 429:
210
+ # A monthly quota resets at the start of next month, and a gift budget never resets.
211
+ return failure.code != "quota_exceeded" and (failure.retry_after or 0) <= _MAX_RETRY_AFTER_S
212
+ return idempotent and (failure.status is None or failure.status >= 500)
File without changes