diff --git a/pyproject.toml b/pyproject.toml index ca157fb71..8431b1e75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,7 @@ dependencies = [ "typing-extensions >= 4.1.0", "tomli >= 2.0.1; python_version < '3.11'", "executing >= 2.0.1", + "inline-snapshot", ] [project.optional-dependencies] @@ -142,7 +143,7 @@ dev = [ "opentelemetry-instrumentation-aws-lambda>=0.42b0", "eval-type-backport >= 0.2.0", "requests-mock >= 1.12.1", - "inline-snapshot >= 0.17.1", + "inline-snapshot>=0.17.1", "structlog >= 24.4.0", "loguru >= 0.7.3", "ruff >= 0.8.3", @@ -206,12 +207,14 @@ docs = [ "mkdocs-llmstxt>=0.2.0", ] + [tool.inline-snapshot] -default-flags = ["disable"] format-command = "ruff format --stdin-filename {filename}" +show-updates = true [tool.uv.sources] logfire-api = { workspace = true } +inline-snapshot = { git = "https://github.com/15r10nk/inline-snapshot.git", rev = "customize" } [tool.uv] default-groups = ["dev", "docs"] diff --git a/tests/conftest.py b/tests/conftest.py index afdeabdf8..d0001e726 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,6 +10,7 @@ import anyio._backends._asyncio # noqa # type: ignore import pytest from agents.tracing import get_trace_provider +from inline_snapshot.plugin import Builder, Import, customize from opentelemetry import trace from opentelemetry.sdk._logs.export import SimpleLogRecordProcessor from opentelemetry.sdk.metrics.export import InMemoryMetricReader @@ -222,3 +223,21 @@ def vcr_config() -> dict[str, Any]: 'filter_headers': SENSITIVE_HEADERS, 'before_record_response': scrub_headers, } + + +@customize +def logfire_handler(value: Any, builder: Builder, local_vars: dict[str, Any], global_vars: dict[str, Any]) -> Any: + all_vars = {**global_vars, **local_vars} + for var in ['redis_port', 'HANDLER_NAME', 'code_function']: + if var in all_vars and all_vars[var] == value: + return builder.create_code(var) + + for attr in ['started_at', 'ended_at']: + if 's' in local_vars and hasattr(var := local_vars['s'], attr) and getattr(var, attr) == value: + return builder.create_code(f's.{attr}') + + if value == os.getcwd(): + return builder.create_code('os.getcwd()', imports=[Import('os')]) + + if value == sys.version: + return builder.create_code('sys.version', imports=[Import('sys')]) diff --git a/uv.lock b/uv.lock index 701ee0e54..f05c4fa50 100644 --- a/uv.lock +++ b/uv.lock @@ -659,7 +659,7 @@ name = "cffi" version = "2.0.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "pycparser", version = "2.23", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10' and implementation_name != 'PyPy'" }, + { name = "pycparser", version = "2.23", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10' and implementation_name != 'PyPy' and platform_python_implementation != 'PyPy'" }, { name = "pycparser", version = "3.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.10' and implementation_name != 'PyPy'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/eb/56/b1ba7935a17738ae8453301356628e8147c79dbb825bcbc73dc7401f9846/cffi-2.0.0.tar.gz", hash = "sha256:44d1b5909021139fe36001ae048dbdde8214afa20200eda0f64c068cac5d5529", size = 523588, upload-time = "2025-09-08T23:24:04.541Z" } @@ -1512,7 +1512,7 @@ name = "exceptiongroup" version = "1.3.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "typing-extensions", marker = "python_full_version < '3.13'" }, + { name = "typing-extensions", marker = "python_full_version < '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/50/79/66800aadf48771f6b62f7eb014e352e5d06856655206165d775e675a02c9/exceptiongroup-1.3.1.tar.gz", hash = "sha256:8b412432c6055b0b7d14c310000ae93352ed6754f70fa8f7c34141f91c4e3219", size = 30371, upload-time = "2025-11-21T23:01:54.787Z" } wheels = [ @@ -2372,7 +2372,7 @@ wheels = [ [[package]] name = "inline-snapshot" version = "0.31.1" -source = { registry = "https://pypi.org/simple" } +source = { git = "https://github.com/15r10nk/inline-snapshot.git?rev=customize#8a3d36362a58fe9574480866f61394cdfb2422cf" } dependencies = [ { name = "asttokens" }, { name = "executing" }, @@ -2380,10 +2380,7 @@ dependencies = [ { name = "pytest", version = "9.0.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.10'" }, { name = "rich" }, { name = "tomli", marker = "python_full_version < '3.11'" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/1c/b1/52b5ee59f73ed31d5fe21b10881bf2d121d07d54b23c0b6b74186792e620/inline_snapshot-0.31.1.tar.gz", hash = "sha256:4ea5ed70aa1d652713bbfd750606b94bd8a42483f7d3680433b3e92994495f64", size = 2606338, upload-time = "2025-11-07T07:36:18.932Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/ba/52/945db420380efbda8c69a7a4a16c53df9d7ac50d8217286b9d41e5d825ff/inline_snapshot-0.31.1-py3-none-any.whl", hash = "sha256:7875a73c986a03388c7e758fb5cb8a43d2c3a20328aa1d851bfb4ed536c4496f", size = 71965, upload-time = "2025-11-07T07:36:16.836Z" }, + { name = "typing-extensions" }, ] [[package]] @@ -3158,6 +3155,7 @@ version = "4.20.0" source = { editable = "." } dependencies = [ { name = "executing" }, + { name = "inline-snapshot" }, { name = "opentelemetry-exporter-otlp-proto-http" }, { name = "opentelemetry-instrumentation" }, { name = "opentelemetry-sdk" }, @@ -3377,6 +3375,7 @@ docs = [ [package.metadata] requires-dist = [ { name = "executing", specifier = ">=2.0.1" }, + { name = "inline-snapshot", git = "https://github.com/15r10nk/inline-snapshot.git?rev=customize" }, { name = "openinference-instrumentation-dspy", marker = "extra == 'dspy'", specifier = ">=0" }, { name = "openinference-instrumentation-litellm", marker = "extra == 'litellm'", specifier = ">=0" }, { name = "opentelemetry-exporter-otlp-proto-http", specifier = ">=1.39.0,<1.40.0" }, @@ -3438,7 +3437,7 @@ dev = [ { name = "google-genai", specifier = ">=0" }, { name = "greenlet", specifier = ">=3.1.1" }, { name = "httpx", specifier = ">=0.27.2" }, - { name = "inline-snapshot", specifier = ">=0.17.1" }, + { name = "inline-snapshot", git = "https://github.com/15r10nk/inline-snapshot.git?rev=customize" }, { name = "langchain", specifier = ">=0.0.27" }, { name = "langchain-openai", specifier = ">=0.3.17" }, { name = "langgraph", specifier = ">=0" },