Commit Graph

61 Commits

Author SHA1 Message Date
lovasoa 1af44a79d0 fmt 2026-04-13 02:44:47 +02:00
Ophir LOJKINE 08ae59e696 Suppress startup logs for CLI-only invocations (#1250) 2026-03-19 10:42:29 +01:00
Ophir LOJKINE fda4af3c8a Remove reqwest/tower from default OTLP graph (#1248)
* chore: remove reqwest from default OTLP dependency graph

* fix: run OTLP hyper exporters on tokio async runtime

* fix: propagate OTLP init errors without panic

* fix: surface OTLP exporter failures in default logs

* feat: use awc for OTLP HTTP exports

* refactor: share awc client construction with telemetry
2026-03-16 02:22:37 +01:00
Ophir LOJKINE d1e8154222 Add OpenTelemetry distributed tracing support (#1234)
* add OpenTelemetry distributed tracing support

When OTEL_EXPORTER_OTLP_ENDPOINT is set, enables full tracing pipeline
with OTLP export, W3C traceparent propagation, and spans for HTTP
requests, SQL file execution, DB pool acquire, and query execution.
Falls back to env_logger when unset.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix OTel example: tracing init, Dockerfile, Tempo config

- Fix tracing-log bridge initialization order (set subscriber first,
  then LogTracer) to avoid double-set panic
- Add dedicated Dockerfile for example using release profile (avoids
  OOM with superoptimized LTO in Docker)
- Use debian:trixie-slim runtime for glibc compatibility
- Fix nginx image to nginx:otel (official image with OTel module)
- Fix nginx.conf: move otel_trace directives into location block
- Pin Tempo to 2.6.1 (latest has partition ring issues in single-node)
- Fix otel-collector exporter alias (otlp → otlp_grpc)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* propagate trace context to PostgreSQL via application_name

After acquiring a DB connection, set the W3C traceparent as the
PostgreSQL application_name (or MySQL session variable). This makes
trace IDs visible in pg_stat_activity and PostgreSQL logs, enabling
direct correlation between Grafana Tempo traces and database-side
monitoring.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* rewrite OTel example README with setup guides for all major providers

Comprehensive documentation covering:
- Step-by-step quick start for the Docker Compose example
- How OpenTelemetry works (spans, collectors, backends)
- Setup guides for Grafana Tempo, Jaeger, Grafana Cloud, Datadog,
  Honeycomb, New Relic, and Axiom with exact env vars and doc links
- PostgreSQL trace correlation via application_name
- Environment variable reference
- Troubleshooting section

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix todo example: use :title (POST variable) instead of $title

The form submits via POST, so the title field must be referenced with
the : prefix (POST parameter) rather than $ (GET parameter).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* set code.filepath and code.lineno span attributes to user SQL files

OTel span attributes now reference the user's .sql file path and line
number instead of the SQLPage Rust source code. Also improves span
naming, adds JSON log formatting, custom root span builder, and
Grafana dashboard provisioning for the OTel example.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* npm run fix

* use stable OTel semantic convention attribute names

- code.filepath → code.file.path, code.lineno → code.line.number
- db.statement → db.query.text, db.system → db.system.name
- Disable auto code location (.with_location(false)) so spans
  reference user SQL files, not SQLPage Rust source
- Remove redundant sqlpage.file attribute (code.file.path suffices)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* use OTel semantic convention values for db.system.name

Use well-known values from the OpenTelemetry registry instead of raw
DBMS name strings. Cast line numbers to i64 for correct span recording.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* remove json-subscriber dependency

The custom logfmt layer in telemetry.rs replaces it with zero extra
dependencies and precise control over field selection and ordering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* add Loki + Promtail log aggregation to OTel example

Adds two new services (Loki, Promtail) to scrape SQLPage container logs
and display them in Grafana alongside traces. The home dashboard now
shows a logs panel with trace_id derived fields linking to Tempo.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* add OTel spans for request parsing, rendering, sqlpage functions, and OIDC

Add targeted spans to account for previously untraced time:
- http.parse_request: request/form parsing before SQL execution
- render: template rendering and response streaming
- subprocess: sqlpage.exec() with process.command attribute
- http.client: sqlpage.fetch()/fetch_with_meta() with OTel HTTP client
  semantic conventions (http.request.method, url.full, http.response.status_code)
- sqlpage.file: sqlpage.run_sql() nested file execution
- oidc.callback + http.client: OIDC token exchange

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* add oidc.jwt.verify span for OIDC token verification

This span covers JWT signature verification and claims validation,
which runs on every authenticated request via get_token_claims().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* add enduser.id attribute to oidc.jwt.verify span

Records the OIDC subject claim (sub) as enduser.id after successful
JWT verification, following OTel semantic conventions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* add OTel user.* attributes to oidc.jwt.verify span

Record user.id (sub), user.name (preferred_username), user.full_name
(name), and user.email from OIDC claims after JWT verification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* add sqlpage.file.load span and attributes to http.parse_request

The gap before http.parse_request was the SQL file cache lookup -
now covered by the sqlpage.file.load span with code.file.path.

http.parse_request now records http.request.method and content_type,
which helps identify slow multipart/form-data parsing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix clippy pedantic warnings

* unify log format: logfmt with colors, no OTel noise

Use the custom logfmt layer for both OTel and non-OTel modes instead
of falling back to env_logger. This eliminates the tracing→log bridge
dumping all span fields (user agents, otel.kind, request_id, etc.)
and only shows: ts, level, target, msg, method, path, status,
file, client_ip, and trace_id (when valid).

Adds terminal color support (bold red for errors, green for info,
dim for timestamps/targets). Emits one log line per completed
successful request. Errors are logged once by the error handler.
Suppresses trace_id=000...0 when no real trace context exists.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* use .instrument() instead of .entered() for async spans

Span guards from .entered() do not propagate correctly across await
points. Switch to tracing::Instrument to ensure spans are properly
associated with their async tasks throughout their lifetime.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* preserve multi-line error formatting in terminal log output

When stderr is a terminal and the log message contains newlines
(e.g. SQL syntax errors with source highlighting and arrows),
print the metadata on the first line and the message below with
its original formatting. Machine output (non-terminal) remains
single-line logfmt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* use root Dockerfile for OTel example, add CARGO_PROFILE build arg

Remove the example's custom Dockerfile and use the main one with a
CARGO_PROFILE=release build arg to avoid OOM from fat LTO in
memory-constrained Docker environments. The build scripts now
read CARGO_PROFILE from the environment, defaulting to
superoptimized for backward compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* add db.query.parameter and db.response.returned_rows span attributes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add official blog post about tracing

* add http.request.body.size and url.query span attributes

Add http.request.body.size to HTTP client spans (fetch, fetch_with_meta)
and to the server-side http.parse_request span (from Content-Length header).
Add url.query to the http.parse_request span.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Replace Promtail with the OpenTelemetry Collector

* Refactor telemetry logging helpers

* Clamp traced fetch body size

* Clamp traced fetch_with_meta body size

* Silence noisy PostgreSQL collector logs

* make startup logs parseable

* update terminal log formats

* Ingest real PostgreSQL logs with trace IDs

* Use raw traceparent for PostgreSQL tracing

* Update opentelemetry example for PostgreSQL query events

* Add nginx logs to opentelemetry example

* Parse nginx error log severity correctly

* Log all span fields when debug logging is enabled

* Rename telemetry example directory

* Fix PostgreSQL Loki log ingestion

* `LOG_LEVEL` is now the primary environment variable for configuring SQLPage's log filter. `RUST_LOG` remains supported as an alias.

* Skip empty trace IDs in logs

* add db errors to otel traces

* add healthcheck

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 15:52:32 +01:00
lovasoa e3334380af Move CLI parsing to separate module
fix potential cli parsing crash
2025-07-24 23:20:10 +02:00
lovasoa 7f7549ec38 fix clippy errors
introduced by https://github.com/sqlpage/SQLPage/pull/943
2025-07-24 22:45:45 +02:00
Andrews Innovations 453701c17c Added create-migration command line instruction (#943)
* Added create-migration command line instruction

This update adds a command line interface to create migrations directly with sqlpage, and have it manage the timestamps and uniqueness of migration names.

* Update sqlpage/migrations/README.md

Co-authored-by: Ophir LOJKINE <contact@ophir.dev>

* Update sqlpage/migrations/README.md

Co-authored-by: Ophir LOJKINE <contact@ophir.dev>

* Updated with changes for config directory, migration output

Now respects the configuration_directory environment variable.

It also outputs the path of the new migration created when it is created, and takes care to display that path relative to the current working directory.

Lastly, the execution of create-migration command was moved above the rest of the initialization, so that creating a new migration does not run existing migrations. This allows you to create multiple migrations before you run sqlpage normally again to execute them.

---------

Co-authored-by: Ophir LOJKINE <contact@ophir.dev>
2025-06-25 10:45:39 +02:00
lovasoa c00446ca21 clippy 2025-05-06 22:47:12 +02:00
lovasoa c78f764b81 improve cli parsing 2024-09-05 22:56:31 +02:00
lovasoa b64a6d29f9 clean database connection closing on shutdown 2024-08-28 20:40:31 +02:00
lovasoa c76610a2ca remove success message on error 2024-08-05 15:24:54 +02:00
lovasoa 678818aed9 apply database migrations before initializing on-database filesystem
this allows populating the in-database filesystem in migrations
fixes https://github.com/lovasoa/SQLpage/issues/461
2024-06-26 22:26:30 +02:00
lovasoa 24191c5301 fix missing page body on authentication error
remove duplicated code
add test for http basic auth
2024-06-22 09:09:12 +02:00
lovasoa e7ff2ef2ac fix default sqlite database creation
When no database_url is specified in the configuration file, the path to the default database being created in "sqlpage/sqlpage.db" was incorrect when the canonical path to the current folder contained a "?" character (which is always the case on windows because of UNC paths).

fixes #413
2024-06-16 13:38:01 +02:00
lovasoa e3d7ac33c0 clarify message 2024-06-14 19:34:41 +02:00
lovasoa 1a737f2fbb suggest connecting from localhost 2024-06-14 19:33:51 +02:00
lovasoa e22362ece9 display SQLPage version in the logs on startup
fixes https://github.com/lovasoa/SQLpage/issues/390
2024-06-09 23:22:01 +02:00
lovasoa 231216ad6e fix incorrect console message at start
SQLPage listens on all public interfaces by default, so
it is accessible by other computers on the same network. This used to be hidden in log messages, make it obvious instead.

fixes https://github.com/lovasoa/SQLpage/issues/387
2024-06-09 20:01:40 +02:00
lovasoa 867ee9c743 simplify unix socket binding error handling 2024-05-29 16:27:13 +02:00
Vlad Lasky c24d101cae Added new configuration option 'unix_socket'.
This specifies a path to a UNIX socket file to listen on instead of the TCP port.

If specified, SQLPage will accept HTTP connections only on this socket and not on any TCP port. This option is mutually exclusive with the `listen_on` and `port` options.

Useful when running SQLpage behind a proxy server like Nginx, as the overhead for communication using Unix Domain Sockets is less than when using the TCP stack.
2024-05-18 10:36:45 +10:00
Ophir LOJKINE e3fb2f8acc Introduce SQLPAGE_CONFIGURATION_DIRECTORY (#243)
* Introduce SQLPAGE_CONFIGURATION_DIRECTORY

Makes the configuration directory configurable instead of it being hardcoded to "./sqlpage/"

* logging
2024-02-25 19:23:17 +01:00
lovasoa c67f3266a1 small usability improvements 2023-12-01 01:28:33 +01:00
lovasoa fc38f0d238 log all requests by default 2023-12-01 00:20:13 +01:00
lovasoa 57f5a713a9 implement bulk csv import 2023-11-27 00:57:21 +01:00
lovasoa aa1e635ca4 Added support for .env files 2023-11-26 17:48:50 +01:00
lovasoa e6690115bf remove chdir on startup
#141
2023-11-25 20:25:48 +01:00
Ophir LOJKINE 8216313fc9 http/2 and automatic https (#140)
* better docs for multi-select

* wip

* fix bug in corporate conundrum demo

* update dependencies

* Fix bug with variable assignment

fixes #138

* Files (#139)

* document future file functions

* make forms multipart when they contain a file field

* extract http request data reading logic

* start work on file upload

* multipart post data parsing

* millisecond precision in logs

* implement customizable upload file size limits

* wip: add file handling functions

* file handling pseudo-functions

* clippy

* fmt

* Add file upload functionality to changelog

* fix example

* update datetime parsing

* add support for samesite cookies and document cookie expiration

* add support for https

* clippy

* ignore certs

* revert changes to default config

* changelog
2023-11-25 12:55:21 +01:00
Ophir LOJKINE 332420bc18 Files (#139)
* document future file functions

* make forms multipart when they contain a file field

* extract http request data reading logic

* start work on file upload

* multipart post data parsing

* millisecond precision in logs

* implement customizable upload file size limits

* wip: add file handling functions

* file handling pseudo-functions

* clippy

* fmt
2023-11-24 23:49:53 +01:00
lovasoa 9a6c674138 Split out database migration code 2023-10-02 16:42:52 +02:00
lovasoa 69a1aab0e4 new sqlpage.current_working_directory() function 2023-09-17 18:18:10 +02:00
lovasoa a897a1321c new configuration parameter: web_root
see https://github.com/lovasoa/SQLpage/discussions/87
2023-09-17 17:14:50 +02:00
lovasoa 251ea0307d add integration test, and expose more as library 2023-08-27 21:56:59 +02:00
lovasoa 6c1db243fe Include index.sql by default 2023-05-14 19:53:54 +02:00
lovasoa 1f389cb6dc easier configuration, better default configuration 2023-02-02 01:41:59 +01:00
lovasoa 221833ea37 allow serving static files from the database
serve static files from the virtual filesystem
2023-01-19 23:42:49 +01:00
lovasoa a116609f0f fix file loading from database 2023-01-15 17:21:42 +01:00
lovasoa d5353f3ae7 in-database embedded file-system for true serverless usage 2023-01-15 16:16:03 +01:00
lovasoa 131b29829a architecture changes to allow future dynamic headers 2022-11-14 01:00:56 +01:00
lovasoa 3d191afbf9 pedantic clippy 2022-11-12 13:03:33 +01:00
lovasoa 6b106e0818 Make the file cache generic 2022-09-12 02:01:39 +04:00
lovasoa b0fd1ac2ab format 2022-09-07 22:08:44 +02:00
lovasoa e47953d447 Refactor http server for easier sql caching integration 2022-09-07 22:08:30 +02:00
lovasoa 6114789a39 format 2022-09-06 14:45:43 +02:00
lovasoa 20cf4d7b05 wiser DATABASE_URL defaults 2022-09-06 14:44:50 +02:00
lovasoa e854828393 format 2022-09-03 13:55:36 +02:00
lovasoa 32240dcf72 Improve error handling 2022-09-03 13:49:19 +02:00
lovasoa b7af6dbce2 Add support for postgres
The current implementation is quite inefficient.
Parse the SQL on the rust side
Prepare statements and execute them one by one.
2022-09-02 23:58:30 +02:00
lovasoa 36164f3304 Better separation of database logic
Allow the use of a PORT env variable
2022-09-01 19:32:55 +02:00
lovasoa a9222f5114 Add lambda serverless compile target 2022-08-31 23:55:12 +02:00
lovasoa e8b4fba5fa better separation between http server and database 2022-08-29 21:32:06 +02:00