mirror of
https://github.com/simonw/datasette.git
synced 2026-09-04 07:34:15 +02:00
Datasette core is gaining OpenTelemetry spans alongside the existing hand-rolled tracer. This commit only lays the groundwork - no span is emitted yet. Core takes a runtime dependency on opentelemetry-api and nothing more. It deliberately never creates a TracerProvider, configures an exporter, or touches sampling: that belongs to whoever runs Datasette, normally via an opentelemetry-instrument agent. Owning a provider in core was tried in an earlier design and produced a cross-request span leak, a process-global provider that tests could not tear down, and a sampling env var that silently blanked output. With no provider installed every span is a NonRecordingSpan and costs approximately nothing. datasette/telemetry.py exposes the module-level tracer plus sql_attribute(), which truncates SQL to 2048 characters. On a public instance the SQL is attacker-controlled and unbounded - someone can paste a 10MB query into ?sql= - so it must never reach a telemetry pipeline verbatim. opentelemetry-sdk goes in the dev dependency group only, because the test suite needs it to assert on spans while the package itself must not import it. tests/test_telemetry.py enforces that by importing datasette in a fresh interpreter and inspecting sys.modules, which catches a lazy import inside a function body that a grep would miss. conftest.py gains a session-scoped autouse fixture installing an SDK provider with an InMemorySpanExporter. It has to be session-scoped because set_tracer_provider() is effectively once-per-process - a second call logs a warning and is ignored. SimpleSpanProcessor rather than BatchSpanProcessor, so assertions made right after a request never race a background export thread. The otel_spans fixture that later tickets assert against is added here too. test_datasette_package_never_imports_the_sdk is moved to the front of the run. Late in a serial run the pytest process holds enough threads that the fork half of subprocess' fork+exec segfaults the interpreter on macOS/CPython 3.13. That reproduces with any subprocess call in that position on an unmodified tree, so it is a pre-existing hazard rather than something this commit introduces; the repo already moves its other subprocess-spawning tests to the front for related reasons. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| plugins | ||
| test_templates | ||
| __init__.py | ||
| build_small_spatialite_db.py | ||
| conftest.py | ||
| ext.c | ||
| fixtures.py | ||
| spatialite.db | ||
| test-datasette-load-plugins.sh | ||
| test_actions_sql.py | ||
| test_actor_restriction_bug.py | ||
| test_allowed_many.py | ||
| test_allowed_resources.py | ||
| test_api.py | ||
| test_api_write.py | ||
| test_auth.py | ||
| test_autocomplete.py | ||
| test_base_view.py | ||
| test_cli.py | ||
| test_cli_serve_get.py | ||
| test_cli_serve_server.py | ||
| test_column_types.py | ||
| test_config_dir.py | ||
| test_config_permission_rules.py | ||
| test_crossdb.py | ||
| test_csrf_middleware.py | ||
| test_csv.py | ||
| test_custom_pages.py | ||
| test_datasette_https_server.sh | ||
| test_debug_autocomplete.py | ||
| test_default_deny.py | ||
| test_docs.py | ||
| test_docs_plugins.py | ||
| test_error_shape.py | ||
| test_extras.py | ||
| test_facets.py | ||
| test_fd_leak.py | ||
| test_filters.py | ||
| test_fixtures.py | ||
| test_html.py | ||
| test_internal_db.py | ||
| test_internals_database.py | ||
| test_internals_datasette.py | ||
| test_internals_datasette_client.py | ||
| test_internals_request.py | ||
| test_internals_response.py | ||
| test_internals_urls.py | ||
| test_jump.py | ||
| test_label_column_for_table.py | ||
| test_lifespan.py | ||
| test_load_extensions.py | ||
| test_messages.py | ||
| test_multipart.py | ||
| test_package.py | ||
| test_permission_endpoints.py | ||
| test_permissions.py | ||
| test_playwright.py | ||
| test_plugins.py | ||
| test_publish_cloudrun.py | ||
| test_publish_heroku.py | ||
| test_pytest_autoclose_plugin.py | ||
| test_queries.py | ||
| test_restriction_sql.py | ||
| test_routes.py | ||
| test_schema_endpoints.py | ||
| test_search_tables.py | ||
| test_spatialite.py | ||
| test_stored_queries.py | ||
| test_success_envelope.py | ||
| test_table_api.py | ||
| test_table_html.py | ||
| test_telemetry.py | ||
| test_template_context.py | ||
| test_token_handler.py | ||
| test_tracer.py | ||
| test_utils.py | ||
| test_utils_check_callable.py | ||
| test_utils_permissions.py | ||
| test_utils_sql_analysis.py | ||
| test_write_sql_operation_decisions.py | ||
| test_write_wrapper.py | ||
| utils.py | ||