logfire-api 5.5.0__tar.gz → 5.6.0__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 (133) hide show
  1. {logfire_api-5.5.0 → logfire_api-5.6.0}/PKG-INFO +1 -1
  2. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/__init__.py +7 -2
  3. logfire_api-5.6.0/logfire_api/_internal/agent_sandboxes.pyi +13 -0
  4. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/config.pyi +3 -1
  5. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/otlp.pyi +2 -2
  6. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/processor_wrapper.pyi +32 -2
  7. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/formatter.pyi +5 -1
  8. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/json_encoder.pyi +5 -0
  9. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/main.pyi +15 -8
  10. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/scrubbing.pyi +2 -1
  11. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/logging.pyi +0 -1
  12. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/sampling/_tail_sampling.pyi +2 -1
  13. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/types.pyi +3 -0
  14. {logfire_api-5.5.0 → logfire_api-5.6.0}/pyproject.toml +1 -1
  15. logfire_api-5.5.0/logfire_api/_internal/agent_sandboxes.pyi +0 -42
  16. {logfire_api-5.5.0 → logfire_api-5.6.0}/.gitignore +0 -0
  17. {logfire_api-5.5.0 → logfire_api-5.6.0}/README.md +0 -0
  18. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/__init__.pyi +0 -0
  19. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/__init__.pyi +0 -0
  20. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/ast_utils.pyi +0 -0
  21. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/async_.pyi +0 -0
  22. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/auth.pyi +0 -0
  23. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/auto_trace/__init__.pyi +0 -0
  24. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/auto_trace/import_hook.pyi +0 -0
  25. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/auto_trace/rewrite_ast.pyi +0 -0
  26. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/auto_trace/types.pyi +0 -0
  27. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/baggage.pyi +0 -0
  28. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/cli/__init__.pyi +0 -0
  29. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/cli/ai_tools.pyi +0 -0
  30. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/cli/auth.pyi +0 -0
  31. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/cli/gateway.pyi +0 -0
  32. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/cli/gateway_auth.pyi +0 -0
  33. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/cli/prompt.pyi +0 -0
  34. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/cli/run.pyi +0 -0
  35. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/cli.pyi +0 -0
  36. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/client.pyi +0 -0
  37. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/collect_system_info.pyi +0 -0
  38. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/config_params.pyi +0 -0
  39. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/constants.pyi +0 -0
  40. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/db_statement_summary.pyi +0 -0
  41. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/__init__.pyi +0 -0
  42. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/api_key_gate.pyi +0 -0
  43. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/console.pyi +0 -0
  44. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/dynamic_batch.pyi +0 -0
  45. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/logs.pyi +0 -0
  46. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/quiet_metrics.pyi +0 -0
  47. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/remove_pending.pyi +0 -0
  48. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/tail_sampling.pyi +0 -0
  49. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/exporters/wrapper.pyi +0 -0
  50. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/fleet.pyi +0 -0
  51. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/forwarding.pyi +0 -0
  52. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/http_transport.pyi +0 -0
  53. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/instrument.pyi +0 -0
  54. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/__init__.pyi +0 -0
  55. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/aiohttp_client.pyi +0 -0
  56. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/aiohttp_server.pyi +0 -0
  57. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/asgi.pyi +0 -0
  58. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/asyncpg.pyi +0 -0
  59. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/aws_lambda.pyi +0 -0
  60. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/celery.pyi +0 -0
  61. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/claude_agent_sdk.pyi +0 -0
  62. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/django.pyi +0 -0
  63. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/dspy.pyi +0 -0
  64. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/executors.pyi +0 -0
  65. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/fastapi.pyi +0 -0
  66. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/flask.pyi +0 -0
  67. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/google_genai.pyi +0 -0
  68. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/httpx.pyi +0 -0
  69. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/litellm.pyi +0 -0
  70. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/litestar.pyi +0 -0
  71. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/mcp.pyi +0 -0
  72. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/monty.pyi +0 -0
  73. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/mysql.pyi +0 -0
  74. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/openai_agents.pyi +0 -0
  75. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/print.pyi +0 -0
  76. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/psycopg.pyi +0 -0
  77. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/pydantic_ai.pyi +0 -0
  78. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/pymongo.pyi +0 -0
  79. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/pytest.pyi +0 -0
  80. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/redis.pyi +0 -0
  81. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/requests.pyi +0 -0
  82. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/snowflake.pyi +0 -0
  83. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/sqlalchemy.pyi +0 -0
  84. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/sqlite3.pyi +0 -0
  85. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/starlette.pyi +0 -0
  86. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/surrealdb.pyi +0 -0
  87. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/system_metrics.pyi +0 -0
  88. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/integrations/wsgi.pyi +0 -0
  89. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/interactive.pyi +0 -0
  90. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/json_formatter.pyi +0 -0
  91. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/json_schema.pyi +0 -0
  92. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/json_types.pyi +0 -0
  93. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/logs.pyi +0 -0
  94. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/metrics.pyi +0 -0
  95. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/server_response.pyi +0 -0
  96. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/stack_info.pyi +0 -0
  97. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/tracer.pyi +0 -0
  98. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/ulid.pyi +0 -0
  99. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/_internal/utils.pyi +0 -0
  100. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/cli.pyi +0 -0
  101. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/db_api.pyi +0 -0
  102. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/exceptions.pyi +0 -0
  103. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/experimental/__init__.pyi +0 -0
  104. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/experimental/annotations.pyi +0 -0
  105. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/experimental/api_client.pyi +0 -0
  106. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/experimental/datasets/__init__.pyi +0 -0
  107. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/experimental/query_client.pyi +0 -0
  108. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/fleet/__init__.pyi +0 -0
  109. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/__init__.pyi +0 -0
  110. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/aiohttp_client.pyi +0 -0
  111. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/flask.pyi +0 -0
  112. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/httpx.pyi +0 -0
  113. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/loguru.pyi +0 -0
  114. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/psycopg.pyi +0 -0
  115. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/pydantic.pyi +0 -0
  116. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/redis.pyi +0 -0
  117. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/sqlalchemy.pyi +0 -0
  118. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/structlog.pyi +0 -0
  119. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/integrations/wsgi.pyi +0 -0
  120. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/propagate.pyi +0 -0
  121. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/py.typed +0 -0
  122. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/query_client.pyi +0 -0
  123. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/sampling/__init__.pyi +0 -0
  124. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/variables/__init__.pyi +0 -0
  125. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/variables/_handlebars.pyi +0 -0
  126. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/variables/abstract.pyi +0 -0
  127. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/variables/composition.pyi +0 -0
  128. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/variables/config.pyi +0 -0
  129. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/variables/local.pyi +0 -0
  130. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/variables/remote.pyi +0 -0
  131. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/variables/template_validation.pyi +0 -0
  132. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/variables/variable.pyi +0 -0
  133. {logfire_api-5.5.0 → logfire_api-5.6.0}/logfire_api/version.pyi +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: logfire-api
3
- Version: 5.5.0
3
+ Version: 5.6.0
4
4
  Summary: Shim for the Logfire SDK which does nothing unless Logfire is installed
5
5
  Author-email: Pydantic Team <engineering@pydantic.dev>, Samuel Colvin <samuel@pydantic.dev>, Hasan Ramezani <hasan@pydantic.dev>, Adrian Garcia Badaracco <adrian@pydantic.dev>, David Montague <david@pydantic.dev>, Marcelo Trylesinski <marcelo@pydantic.dev>, David Hewitt <david.hewitt@pydantic.dev>, Alex Hall <alex@pydantic.dev>
6
6
  License-Expression: MIT
@@ -167,7 +167,11 @@ except ImportError:
167
167
 
168
168
  def instrument_sqlalchemy(self, *args, **kwargs) -> None: ...
169
169
 
170
- def instrument_sqlite3(self, *args, **kwargs) -> None: ...
170
+ def instrument_sqlite3(self, conn=None, *args, **kwargs):
171
+ return conn
172
+
173
+ def instrument_mysql(self, conn=None, *args, **kwargs):
174
+ return conn
171
175
 
172
176
  def instrument_aws_lambda(self, *args, **kwargs) -> None: ...
173
177
 
@@ -230,7 +234,8 @@ except ImportError:
230
234
  async def forward_export_request_starlette(self, *args, **kwargs) -> MagicMock:
231
235
  return MagicMock()
232
236
 
233
- def shutdown(self, *args, **kwargs) -> None: ...
237
+ def shutdown(self, *args, **kwargs) -> bool:
238
+ return True
234
239
 
235
240
  DEFAULT_LOGFIRE_INSTANCE = Logfire()
236
241
  span = DEFAULT_LOGFIRE_INSTANCE.span
@@ -0,0 +1,13 @@
1
+ from collections.abc import Callable, Mapping as Mapping
2
+ from logfire import Logfire as Logfire
3
+ from logfire.exceptions import LogfireConfigError as LogfireConfigError
4
+ from logfire.propagate import get_context as get_context
5
+ from pydantic_monty import AsyncMontyRemote
6
+ from typing import Any
7
+
8
+ def agent_sandboxes_url(base_url: str) -> str:
9
+ """Validate and normalize a supplied or derived Logfire Agent Sandboxes URL.
10
+
11
+ The client opens its gRPC stream at the root of this URL, so the base URL must not have a path.
12
+ """
13
+ def create_agent_sandboxes(logfire_instance: Logfire, *, api_key: str | None, url: str | None, metadata: Callable[[], Mapping[str, str]] | None = None, connect_headers: Callable[[], Mapping[str, str]] | None = None, **kwargs: Any) -> AsyncMontyRemote: ...
@@ -11,7 +11,7 @@ from .exporters.console import ConsoleColorsValues as ConsoleColorsValues, Conso
11
11
  from .exporters.dynamic_batch import DynamicBatchSpanProcessor as DynamicBatchSpanProcessor
12
12
  from .exporters.logs import CheckSuppressInstrumentationLogProcessorWrapper as CheckSuppressInstrumentationLogProcessorWrapper, MainLogProcessorWrapper as MainLogProcessorWrapper
13
13
  from .exporters.otlp import BodySizeCheckingOTLPSpanExporter as BodySizeCheckingOTLPSpanExporter, OTLPExporterHttpSession as OTLPExporterHttpSession, QuietLogExporter as QuietLogExporter, QuietSpanExporter as QuietSpanExporter, RetryFewerSpansSpanExporter as RetryFewerSpansSpanExporter, cleanup_disk_retryers as cleanup_disk_retryers, zstd_compress as zstd_compress
14
- from .exporters.processor_wrapper import CheckSuppressInstrumentationProcessorWrapper as CheckSuppressInstrumentationProcessorWrapper, MainSpanProcessorWrapper as MainSpanProcessorWrapper
14
+ from .exporters.processor_wrapper import BackgroundScrubbingSpanProcessor as BackgroundScrubbingSpanProcessor, CheckSuppressInstrumentationProcessorWrapper as CheckSuppressInstrumentationProcessorWrapper, MainSpanProcessorWrapper as MainSpanProcessorWrapper, ScrubbingSpanProcessor as ScrubbingSpanProcessor, SpanProcessorGroup as SpanProcessorGroup, make_scrubbing_queue as make_scrubbing_queue, scrub_span as scrub_span
15
15
  from .exporters.quiet_metrics import QuietMetricExporter as QuietMetricExporter
16
16
  from .exporters.remove_pending import RemovePendingSpansExporter as RemovePendingSpansExporter
17
17
  from .exporters.test import TestExporter as TestExporter
@@ -204,6 +204,8 @@ def configure(*, local: bool = False, send_to_logfire: bool | Literal['if-token-
204
204
 
205
205
  data_dir: Directory to store credentials, and logs. If `None` uses the `LOGFIRE_CREDENTIALS_DIR` environment variable, otherwise defaults to `'.logfire'`.
206
206
  additional_span_processors: Span processors to use in addition to the default processor which exports spans to Logfire's API.
207
+ Processors which have a custom `on_end` method (other than `BatchSpanProcessor`) will cause
208
+ span attribute scrubbing to happen on the calling thread, which may slow down your application.
207
209
  metrics: Set to `False` to disable sending all metrics,
208
210
  or provide a `MetricsOptions` object to configure metrics, e.g. additional metric readers.
209
211
  scrubbing: Options for scrubbing sensitive data. Set to `False` to disable.
@@ -9,7 +9,6 @@ from .wrapper import WrapperLogExporter as WrapperLogExporter, WrapperSpanExport
9
9
  from _typeshed import Incomplete
10
10
  from collections import deque
11
11
  from collections.abc import Mapping, Sequence
12
- from functools import cached_property
13
12
  from logfire._internal.utils import handle_internal_errors as handle_internal_errors
14
13
  from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
15
14
  from opentelemetry.sdk._logs import ReadableLogRecord as ReadableLogRecord
@@ -60,7 +59,7 @@ class OTLPExporterHttpSession(Session):
60
59
  def __init__(self, *, _use_zstd: bool = False) -> None: ...
61
60
  def request(self, method: str, url: str, **kwargs: Any): ...
62
61
  def post(self, url: str, data: bytes, **kwargs: Any): ...
63
- @cached_property
62
+ @property
64
63
  def retryer(self) -> DiskRetryer: ...
65
64
  def close(self) -> None: ...
66
65
 
@@ -76,6 +75,7 @@ class DiskRetryer:
76
75
  tasks: deque[tuple[Path, dict[str, Any]]]
77
76
  total_size: int
78
77
  closed: bool
78
+ pid: Incomplete
79
79
  session: Incomplete
80
80
  dir: Incomplete
81
81
  last_log_time: Incomplete
@@ -5,9 +5,11 @@ from ..json_schema import JsonSchemaProperties as JsonSchemaProperties, attribut
5
5
  from ..scrubbing import BaseScrubber as BaseScrubber
6
6
  from ..utils import ReadableSpanDict as ReadableSpanDict, handle_internal_errors as handle_internal_errors, is_asgi_send_receive_span_name as is_asgi_send_receive_span_name, is_instrumentation_suppressed as is_instrumentation_suppressed, span_to_dict as span_to_dict, truncate_string as truncate_string
7
7
  from .wrapper import WrapperSpanProcessor as WrapperSpanProcessor
8
+ from collections.abc import Sequence
8
9
  from dataclasses import dataclass
9
10
  from opentelemetry import context
10
- from opentelemetry.sdk.trace import Event as Event, ReadableSpan, Span
11
+ from opentelemetry.sdk.trace import Event as Event, ReadableSpan, Span, SpanProcessor, SynchronousMultiSpanProcessor
12
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanExportResult, SpanExporter
11
13
 
12
14
  class CheckSuppressInstrumentationProcessorWrapper(WrapperSpanProcessor):
13
15
  """Checks if instrumentation is suppressed, then suppresses instrumentation itself.
@@ -17,14 +19,42 @@ class CheckSuppressInstrumentationProcessorWrapper(WrapperSpanProcessor):
17
19
  def on_start(self, span: Span, parent_context: context.Context | None = None) -> None: ...
18
20
  def on_end(self, span: ReadableSpan) -> None: ...
19
21
 
20
- @dataclass
21
22
  class MainSpanProcessorWrapper(WrapperSpanProcessor):
22
23
  """Wrapper around other processors to intercept starting and ending spans with our own global logic.
23
24
 
24
25
  Suppresses starting/ending if the current context has a `suppress_instrumentation` value.
25
26
  Tweaks the send/receive span names generated by the ASGI middleware.
26
27
  """
28
+ def on_end(self, span: ReadableSpan) -> None: ...
29
+
30
+ def scrub_span(span: ReadableSpan, scrubber: BaseScrubber) -> ReadableSpan: ...
31
+
32
+ @dataclass
33
+ class ScrubbingSpanProcessor(WrapperSpanProcessor):
27
34
  scrubber: BaseScrubber
28
35
  def on_end(self, span: ReadableSpan) -> None: ...
29
36
 
37
+ @dataclass
38
+ class _SpanProcessorExporter(SpanExporter):
39
+ """Forward drained records to a processor's `on_end` hook.
40
+
41
+ The group that owns the destination processor flushes and shuts it down.
42
+ """
43
+ processor: SpanProcessor
44
+ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult: ...
45
+
46
+ def make_scrubbing_queue(processor: SpanProcessor, scrubber: BaseScrubber) -> BatchSpanProcessor:
47
+ """Queue records for scrubbing before delivering them to a processor."""
48
+
49
+ class SpanProcessorGroup(SynchronousMultiSpanProcessor):
50
+ """Flush processors that may inherit a no-op force_flush returning None."""
51
+ def force_flush(self, timeout_millis: int = 30000) -> bool: ...
52
+
53
+ @dataclass
54
+ class BackgroundScrubbingSpanProcessor(WrapperSpanProcessor):
55
+ """Send completed spans to the synchronous processors and the scrubbing queue."""
56
+ synchronous_end_processor: SpanProcessor
57
+ background_end_processor: BatchSpanProcessor
58
+ def on_end(self, span: ReadableSpan) -> None: ...
59
+
30
60
  def guess_system(model: str, default: str = ''): ...
@@ -9,7 +9,7 @@ from _typeshed import Incomplete
9
9
  from collections.abc import Iterator
10
10
  from functools import lru_cache
11
11
  from string import Formatter
12
- from types import CodeType as CodeType
12
+ from types import CodeType
13
13
  from typing import Any, Literal
14
14
  from typing_extensions import NotRequired, TypedDict
15
15
 
@@ -29,6 +29,10 @@ chunks_formatter: Incomplete
29
29
 
30
30
  def logfire_format(format_string: str, kwargs: dict[str, Any], scrubber: BaseScrubber) -> str: ...
31
31
  def logfire_format_with_magic(format_string: Any, kwargs: dict[str, Any], scrubber: BaseScrubber, fstring_frame: types.FrameType | None = None) -> tuple[str, dict[str, Any], str]: ...
32
+
33
+ LOGFIRE_PACKAGE_DIR: Incomplete
34
+
35
+ def is_logfire_code(code: CodeType) -> bool: ...
32
36
  @lru_cache
33
37
  def compile_formatted_value(node: ast.FormattedValue, ex_source: executing.Source) -> tuple[str, CodeType, CodeType]:
34
38
  """Returns three things that can be expensive to compute.
@@ -12,6 +12,11 @@ EncoderFunction: Incomplete
12
12
 
13
13
  @cache
14
14
  def encoder_by_type() -> dict[type[Any], EncoderFunction]: ...
15
+ def numpy_scalar_to_python(o: Any) -> Any:
16
+ """Convert a NumPy bool, integer or floating scalar to the equivalent Python value, and return anything else as is.
17
+
18
+ Without this, a value like `numpy.int64(42)` (e.g. from `df['col'].sum()`) would be recorded as its repr.
19
+ """
15
20
  def to_json_value(o: Any, seen: set[int]) -> JsonValue: ...
16
21
  def logfire_json_dumps(obj: Any) -> str: ...
17
22
  def is_sqlalchemy(obj: Any) -> bool: ...
@@ -16,7 +16,6 @@ from ..integrations.sqlalchemy import CommenterOptions as SQLAlchemyCommenterOpt
16
16
  from ..integrations.wsgi import RequestHook as WSGIRequestHook, ResponseHook as WSGIResponseHook
17
17
  from ..variables import ResolveFunction as ResolveFunction, TemplateVariable as TemplateVariable, ValidationReport as ValidationReport, Variable as Variable, VariablesConfig as VariablesConfig
18
18
  from ..version import VERSION as VERSION
19
- from .agent_sandboxes import AgentSandboxPool as AgentSandboxPool
20
19
  from .auto_trace import AutoTraceModule as AutoTraceModule, install_auto_tracing as install_auto_tracing
21
20
  from .config import GLOBAL_CONFIG as GLOBAL_CONFIG, LogfireConfig as LogfireConfig, TemplateMismatchPolicy as TemplateMismatchPolicy
22
21
  from .config_params import PydanticPluginRecordValues as PydanticPluginRecordValues
@@ -31,7 +30,7 @@ from .integrations.mysql import MySQLConnection as MySQLConnection
31
30
  from .integrations.psycopg import Psycopg2Connection as Psycopg2Connection, PsycopgConnection as PsycopgConnection
32
31
  from .integrations.sqlite3 import SQLite3Connection as SQLite3Connection
33
32
  from .integrations.system_metrics import Base as SystemMetricsBase, Config as SystemMetricsConfig
34
- from .json_encoder import logfire_json_dumps as logfire_json_dumps
33
+ from .json_encoder import logfire_json_dumps as logfire_json_dumps, numpy_scalar_to_python as numpy_scalar_to_python
35
34
  from .json_schema import JsonSchemaProperties as JsonSchemaProperties, attributes_json_schema as attributes_json_schema, attributes_json_schema_properties as attributes_json_schema_properties, create_json_schema as create_json_schema
36
35
  from .metrics import ProxyMeterProvider as ProxyMeterProvider
37
36
  from .stack_info import get_user_stack_info as get_user_stack_info
@@ -52,6 +51,7 @@ from opentelemetry.sdk.trace import ReadableSpan, Span
52
51
  from opentelemetry.trace import SpanContext, SpanKind
53
52
  from opentelemetry.util import types as otel_types
54
53
  from pydantic_evals.reporting import EvaluationReport
54
+ from pydantic_monty import AsyncMontyRemote
55
55
  from pymongo.monitoring import CommandFailedEvent as CommandFailedEvent, CommandStartedEvent as CommandStartedEvent, CommandSucceededEvent as CommandSucceededEvent
56
56
  from snowflake.connector.connection import SnowflakeConnection
57
57
  from sqlalchemy import Engine
@@ -527,13 +527,13 @@ class Logfire:
527
527
  It records Monty sessions, executed code, inputs, outputs, external calls,
528
528
  exceptions, printed text, and pool metrics. Recorded values are subject to Logfire's configured scrubbing.
529
529
  """
530
- def agent_sandboxes(self, *, api_key: str | None = None, url: str | None = None, max_processes: int | None | _Unset = ..., checkout_timeout: float | None | _Unset = ..., request_timeout: float | None | _Unset = ..., metadata: Callable[[], Mapping[str, str]] | None | _Unset = ..., connect_headers: Callable[[], Mapping[str, str]] | None | _Unset = ..., feed_duration_limit_grace: float | None | _Unset = ..., turn_duration_limit_grace: float | None | _Unset = ..., auto_resume: bool | _Unset = ..., **kwargs: Any) -> AgentSandboxPool:
530
+ def agent_sandboxes(self, *, api_key: str | None = None, url: str | None = None, max_processes: int | None | _Unset = ..., checkout_timeout: float | None | _Unset = ..., request_timeout: float | None | _Unset = ..., metadata: Callable[[], Mapping[str, str]] | None | _Unset = ..., connect_headers: Callable[[], Mapping[str, str]] | None | _Unset = ..., feed_duration_limit_grace: float | None | _Unset = ..., turn_duration_limit_grace: float | None | _Unset = ..., auto_resume: bool | _Unset = ..., **kwargs: Any) -> AsyncMontyRemote:
531
531
  """Connect to Logfire Agent Sandboxes, remote Pydantic Monty workers hosted by Logfire.
532
532
 
533
533
  Requires the `agent-sandboxes` extra, e.g. `pip install 'logfire[agent-sandboxes]'`.
534
534
 
535
- Returns a wrapper around a [`pydantic_monty.AsyncMontyRemote`][pydantic_monty.AsyncMontyRemote] pool;
536
- use it as an async context manager and check out sessions from it:
535
+ Returns a [`pydantic_monty.AsyncMontyRemote`][pydantic_monty.AsyncMontyRemote] pool that
536
+ authenticates with your Logfire API key. Use it as an async context manager and check out sessions from it:
537
537
 
538
538
  ```py
539
539
  import logfire
@@ -549,9 +549,16 @@ class Logfire:
549
549
 
550
550
  No connection is made until a session is checked out.
551
551
 
552
- Checkout accepts the same options and yields the same Monty sessions as `AsyncMontyRemote`.
553
- Authentication and capacity refusals raise `RuntimeError` with Logfire hints, chained from
554
- the original `MontyRefusedError`. Other errors pass through unchanged.
552
+ Because the pool is a plain `AsyncMontyRemote`, you can pass this method wherever a Monty pool
553
+ factory is expected, for example `CodeMode(monty_sandbox=logfire.agent_sandboxes)` in Pydantic AI.
554
+
555
+ Checkout errors from the sandboxes server are Monty's own exceptions; this method does not wrap them.
556
+ An exception raised by your `metadata` callback propagates unchanged. A refused checkout raises
557
+ `MontyRefusedError`. For `UNAUTHENTICATED` or
558
+ `PERMISSION_DENIED`, check that the key is a project API key with the
559
+ `project:execute_agent_sandboxes` scope, that its region matches the server URL, and that Agent
560
+ Sandboxes are enabled for the project. For `RESOURCE_EXHAUSTED`, lower `max_processes` or retry
561
+ after a delay.
555
562
 
556
563
  The Logfire platform records sandbox usage itself. The current trace context is sent
557
564
  with each session so those spans join the caller's trace.
@@ -1,6 +1,7 @@
1
1
  import re
2
2
  import typing_extensions
3
3
  from .constants import ATTRIBUTES_CONFIG as ATTRIBUTES_CONFIG, ATTRIBUTES_JSON_SCHEMA_KEY as ATTRIBUTES_JSON_SCHEMA_KEY, ATTRIBUTES_LOGGING_NAME as ATTRIBUTES_LOGGING_NAME, ATTRIBUTES_LOG_LEVEL_NAME_KEY as ATTRIBUTES_LOG_LEVEL_NAME_KEY, ATTRIBUTES_LOG_LEVEL_NUM_KEY as ATTRIBUTES_LOG_LEVEL_NUM_KEY, ATTRIBUTES_MESSAGE_KEY as ATTRIBUTES_MESSAGE_KEY, ATTRIBUTES_MESSAGE_TEMPLATE_KEY as ATTRIBUTES_MESSAGE_TEMPLATE_KEY, ATTRIBUTES_PACKAGE_VERSIONS as ATTRIBUTES_PACKAGE_VERSIONS, ATTRIBUTES_PENDING_SPAN_REAL_PARENT_KEY as ATTRIBUTES_PENDING_SPAN_REAL_PARENT_KEY, ATTRIBUTES_SAMPLE_RATE_KEY as ATTRIBUTES_SAMPLE_RATE_KEY, ATTRIBUTES_SCRUBBED_KEY as ATTRIBUTES_SCRUBBED_KEY, ATTRIBUTES_SPAN_TYPE_KEY as ATTRIBUTES_SPAN_TYPE_KEY, ATTRIBUTES_TAGS_KEY as ATTRIBUTES_TAGS_KEY, MESSAGE_FORMATTED_VALUE_LENGTH_LIMIT as MESSAGE_FORMATTED_VALUE_LENGTH_LIMIT, RESOURCE_ATTRIBUTES_VERSION as RESOURCE_ATTRIBUTES_VERSION
4
+ from .json_encoder import logfire_json_dumps as logfire_json_dumps
4
5
  from .stack_info import STACK_INFO_KEYS as STACK_INFO_KEYS
5
6
  from .utils import ReadableSpanDict as ReadableSpanDict, truncate_string as truncate_string
6
7
  from _typeshed import Incomplete
@@ -62,7 +63,7 @@ class SpanScrubber:
62
63
  and hold and mutate state about the span being scrubbed, specifically the scrubbed notes.
63
64
  """
64
65
  scrubbed: list[ScrubbedNote]
65
- did_scrub: bool
66
+ scrub_count: int
66
67
  def __init__(self, parent: Scrubber) -> None: ...
67
68
  def scrub_span(self, span: ReadableSpanDict): ...
68
69
  def scrub_log(self, log: LogRecord) -> LogRecord: ...
@@ -2,7 +2,6 @@ from .. import Logfire as Logfire
2
2
  from .._internal.constants import ATTRIBUTES_LOGGING_ARGS_KEY as ATTRIBUTES_LOGGING_ARGS_KEY, ATTRIBUTES_LOGGING_NAME as ATTRIBUTES_LOGGING_NAME, ATTRIBUTES_MESSAGE_KEY as ATTRIBUTES_MESSAGE_KEY, ATTRIBUTES_MESSAGE_TEMPLATE_KEY as ATTRIBUTES_MESSAGE_TEMPLATE_KEY, ATTRIBUTES_TAGS_KEY as ATTRIBUTES_TAGS_KEY, LOGGING_TO_OTEL_LEVEL_NUMBERS as LOGGING_TO_OTEL_LEVEL_NUMBERS
3
3
  from .._internal.utils import is_instrumentation_suppressed as is_instrumentation_suppressed
4
4
  from _typeshed import Incomplete
5
- from collections.abc import Mapping as Mapping
6
5
  from logging import Handler as LoggingHandler, LogRecord
7
6
  from typing import Any, ClassVar
8
7
 
@@ -77,9 +77,10 @@ class TailSamplingProcessor(WrapperSpanProcessor):
77
77
  """
78
78
  get_tail_sample_rate: Incomplete
79
79
  deferred_processor: Incomplete
80
+ prepare_ended_span: Incomplete
80
81
  traces: dict[int, TraceBuffer]
81
82
  lock: Incomplete
82
- def __init__(self, processor: SpanProcessor, get_tail_sample_rate: Callable[[TailSamplingSpanInfo], float], deferred_processor: SpanProcessor | None = None) -> None: ...
83
+ def __init__(self, processor: SpanProcessor, get_tail_sample_rate: Callable[[TailSamplingSpanInfo], float], deferred_processor: SpanProcessor | None = None, *, prepare_ended_span: Callable[[ReadableSpan], ReadableSpan] | None = None) -> None: ...
83
84
  def on_start(self, span: Span, parent_context: context.Context | None = None) -> None: ...
84
85
  def on_end(self, span: ReadableSpan) -> None: ...
85
86
  def check_span(self, span_info: TailSamplingSpanInfo) -> bool:
@@ -18,6 +18,9 @@ class SpanLevel:
18
18
  `<`, `>`, `<=`, or `>=`, so e.g. `level >= 'error'` is valid.
19
19
 
20
20
  Will raise an exception if compared to a non-string or an invalid level name.
21
+
22
+ Hashing a level warns and uses its name, so `level in {'warn', 'error'}` works,
23
+ but `level in {13}` does not. Prefer `level.name in {...}`.
21
24
  """
22
25
  number: int
23
26
  @classmethod
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "logfire-api"
7
- version = "5.5.0"
7
+ version = "5.6.0"
8
8
  description = "Shim for the Logfire SDK which does nothing unless Logfire is installed"
9
9
  authors = [
10
10
  { name = "Pydantic Team", email = "engineering@pydantic.dev" },
@@ -1,42 +0,0 @@
1
- from collections.abc import Awaitable as Awaitable, Callable, Mapping
2
- from contextlib import AbstractAsyncContextManager
3
- from logfire import Logfire as Logfire
4
- from logfire.exceptions import LogfireConfigError as LogfireConfigError
5
- from logfire.propagate import get_context as get_context
6
- from pydantic_monty import AsyncMontyRemote, AsyncMontySession as AsyncMontySession, ExternalModule as ExternalModule, OSPolicy, ResourceLimits, TypeCheckFormat
7
- from typing import Any
8
- from typing_extensions import TypedDict, Unpack
9
-
10
- class AgentSandboxCheckoutOptions(TypedDict, total=False):
11
- """Keyword options forwarded unchanged to AsyncMontyRemote.checkout."""
12
- script_name: str
13
- limits: ResourceLimits | None
14
- type_check: bool
15
- type_check_stubs: str | None
16
- type_check_format: TypeCheckFormat | None
17
- type_check_color: bool
18
- assert_message_annotations: bool | int
19
- print_flush_interval: float | None
20
- os_policy: OSPolicy | None
21
- external_modules: Mapping[str, ExternalModule | Callable[[], Awaitable[ExternalModule]]] | None
22
- ephemeral: bool | None
23
- profile: str | None
24
-
25
- class AgentSandboxPool:
26
- """An async Monty remote pool that adds Logfire hints when checkout is refused.
27
-
28
- Monty's native pool and refusal exception cannot be subclassed. Hinted refusals raise
29
- RuntimeError, with the original MontyRefusedError available as the chained cause.
30
- """
31
- def __init__(self, pool: AsyncMontyRemote) -> None: ...
32
- async def __aenter__(self) -> AgentSandboxPool: ...
33
- async def __aexit__(self, *args: Any) -> None: ...
34
- def checkout(self, **kwargs: Unpack[AgentSandboxCheckoutOptions]) -> AbstractAsyncContextManager[AsyncMontySession]:
35
- """Check out a session with the options and defaults of AsyncMontyRemote.checkout."""
36
-
37
- def agent_sandboxes_url(base_url: str) -> str:
38
- """Validate and normalize a supplied or derived Logfire Agent Sandboxes URL.
39
-
40
- The client opens its gRPC stream at the root of this URL, so the base URL must not have a path.
41
- """
42
- def create_agent_sandboxes(logfire_instance: Logfire, *, api_key: str | None, url: str | None, metadata: Callable[[], Mapping[str, str]] | None = None, connect_headers: Callable[[], Mapping[str, str]] | None = None, **kwargs: Any) -> AgentSandboxPool: ...
File without changes
File without changes