533 Commits
Author SHA1 Message Date
Quentin Gliech 77c5709ff6 Move to the split sentry-tracing layers 2026-11-19 17:02:17 +01:00
Quentin Gliech fa9da2798c Fix the clippy lints introduced by Rust 1.100 2026-11-17 16:12:44 +01:00
Quentin Gliech f54bd61e8a Acquire the user sync lock when issuing a compatibility token from the CLI (#6045) 2026-11-06 15:36:26 +01:00
Quentin Gliech 5f065b1072 Record the requester on Sentry events
Events reported to Sentry had no user attached, so we could not tell how many users an issue affected. Record the requester of the current log context: the user ID for users, and tags for OAuth 2.0 clients and the homeserver.

This is done in `before_send`, which runs in the task capturing the event, rather than on the scope when the requester is known: sentry-tracing forks the hub each time a span is entered, so a scope change made inside a span is lost once it exits, and spans entered earlier keep their own copy of the scope.
2026-10-30 10:10:32 +01:00
Quentin Gliech 27d4fdcfea Attach stack traces to errors reported to Sentry
Errors logged through `tracing` were reported without a stack trace, so Sentry grouped them by the error messages, splitting issues whenever a message contained an ID. With the `attach_stacktrace` option and the `backtrace` feature of `sentry-tracing`, an event with both a message and an error gets a synthetic exception carrying the stack trace of where it was logged. `record_error!` now logs the error as an `error` field with its message, so that it gets one too. Frames from MAS crates are marked as in-app.

Errors logged from a shared place, like the job runner, would then all be grouped together, so the fingerprint also includes the tag of the log context, e.g. the queue of the job, and the path of the GraphQL resolver the error comes from. Requests are left out, as their tag is the HTTP method.

This changes the grouping and the titles of most existing issues.
2026-10-30 10:10:32 +01:00
Quentin Gliech d5e6937947 Explain that traces are off unless a sampling rate is configured 2026-10-30 10:05:04 +01:00
Quentin Gliech 2339281355 Fix typos in the comment about the Sentry layer order 2026-10-30 10:05:04 +01:00
Quentin Gliech a367ce6311 Describe better what the LogContextLayer does with the sentry::Hub 2026-10-30 10:05:04 +01:00
Quentin Gliech fc05ecc995 Report each job as its own Sentry transaction
sentry-tracing picks the parent of a span from the Sentry hub, not from the tracing span tree, so the `job.run` spans ended up as children of the `worker.tick` span despite being created without a parent. Creating the span within the log context of the job, which now has its own hub, makes it the root of its own transaction.

Every span without a parent in a log context now starts a transaction, so only sample the ones we start deliberately: HTTP requests and jobs. Other ones, like the job worker loop spans, would otherwise create a transaction on every wakeup of the worker. The sampler keeps following the sampling decision of the incoming trace, like the fixed rate it replaces.
2026-10-30 10:05:04 +01:00
Quentin Gliech 4036833b4a Run the activity tracker and the policy data reload in log contexts
They ran outside of any log context, so they still used the Sentry hubs of the worker threads, collecting breadcrumbs from unrelated tasks. The policy data reload gets a log context per reload, like a job.
2026-10-30 10:05:04 +01:00
Quentin Gliech 36ed7d3942 Give each log context its own Sentry hub
`NewSentryLayer::new_from_top` derived the hub of each request from the hub of the worker thread the request started on. Those thread hubs collect the breadcrumbs of every task which isn't bound to a hub of its own, like the listener's connection tasks, so every event reported in production carried 100 unrelated "Failed to serve connection" breadcrumbs.

Log contexts already delimit each unit of work: requests, jobs, connections, the worker loop. Each now binds a Sentry hub starting with an empty scope, which replaces the `NewSentryLayer`.
2026-10-30 10:05:04 +01:00
Quentin Gliech 473a592e2d Move the Sentry setup to its own module 2026-10-30 10:05:04 +01:00
Quentin Gliech 5e0c9af91b Report errors returned by CLI commands to Sentry
Errors bubbling up from a command, e.g. a server failing to start, were only printed on exit and never reported to Sentry.
2026-10-29 14:20:48 +01:00
Quentin Gliech d679c84002 Disable Sentry tracing when traces_sample_rate is not set
An unset `telemetry.sentry.traces_sample_rate` used to mean a rate of
0.0, which still records the transaction of any request carrying a
sampled `sentry-trace` header. Since any client can send that header,
leaving the option unset now disables tracing entirely. Setting it to
0.0 explicitly keeps the previous behaviour.
2026-10-28 10:22:11 +01:00
Quentin Gliech 82d71c0ead Upgrade OpenTelemetry to 0.33 and Sentry to 0.49
This bumps the `opentelemetry` crates to 0.33,
`opentelemetry-resource-detectors` to 0.13, `tracing-opentelemetry` to
0.34, and `sentry`, `sentry-tower` and `sentry-tracing` to 0.49. The
process and Tokio instrumentation crates move to 0.3 and the Prometheus
text exporter to 0.4, their releases for OpenTelemetry 0.33. Everything
stays on reqwest 0.13, so the shared `mas_http::reqwest_client()` can
still be handed to both the OTLP exporters and the Sentry transport.

`sentry::ClientOptions` is now non-exhaustive, so it is built with its
setters instead of a struct literal. The
`experimental_metrics_custom_reader` feature of `opentelemetry_sdk` is
now enabled explicitly, as we use `ManualReader` directly instead of
relying on the Prometheus exporter enabling it.

The OTLP exporters now retry failed exports by default (up to 3 retries
with exponential backoff, on HTTP 429, 502, 503 and 504). When the
configuration sets no endpoint, an invalid `OTEL_EXPORTER_OTLP_ENDPOINT`
or `OTEL_EXPORTER_OTLP_{TRACES,METRICS}_ENDPOINT` environment variable
now fails startup instead of falling back to `localhost`.
2026-10-28 10:22:11 +01:00
Quentin Gliech 498f701de7 Implement the Jaeger trace propagator in-tree
The `opentelemetry-jaeger-propagator` crate was removed upstream after
0.32 (open-telemetry/opentelemetry-rust#3710), but Synapse propagates
traces with the Jaeger `uber-trace-id` header, so MAS needs to keep
supporting it.

The in-tree propagator only handles that header, including the
URL-encoded form jaeger-client-python sends and the debug flag set by
Synapse's forced tracing. Baggage (`uberctx-*` headers) is not
propagated. A missing or malformed header is ignored without logging,
so the filter for the upstream crate's "invalid header" warning goes
away too.
2026-10-28 10:22:11 +01:00
Quentin Gliech 2b9be9b185 Acquire the user sync lock when issuing a compatibility token from the CLI
`mas-cli manage issue-compatibility-token` created the device on the
homeserver before committing the compat session, without holding the
per-user sync lock. A concurrent `SyncDevicesJob` could list the
sessions before the commit and sync the device list after the device
was created, removing it from the homeserver and leaving an active
token that Synapse rejects.

Fixes #6044
2026-10-13 10:14:37 +02:00
Quentin Gliech 2d3bf03d63 Upgrade to rand 0.10 and the next RustCrypto generation
`rand` 0.10 and the new RustCrypto generation both build on `rand_core`
0.10, so they have to move together:

 - `rand`, `rand_chacha` and `rand_core` 0.10
 - `digest` 0.11, `sha2` 0.11, `hmac` 0.13, `const-oid` 0.10
 - `elliptic-curve` 0.14, `ecdsa` 0.17, `p256`, `p384` and `k256` 0.14,
   `signature` 3
 - `der`, `spki` and `sec1` 0.8, `pkcs8` 0.11, `pem-rfc7468` 1.0
 - `rsa` 0.10.0-rc.19 and `pkcs1` 0.8.0-rc.5, which have no stable
   release yet. They are pinned exactly, because release candidates
   break their API between releases.
 - `argon2` 0.6 and `pbkdf2` 0.13

On the `rand` side, `RngCore` becomes `Rng` and the old `Rng` becomes
`RngExt`. `gen_*` becomes `random_*`, `thread_rng` becomes `rng`,
`distributions` becomes `distr`, and `from_rng` can no longer fail. On
the crypto side, `mas-jose` and `mas-keystore` move to `BoxedUint` for
RSA, to the `pkcs1` and `pkcs8` reference types, and to the `Generate`
trait for key generation, and `mas-jose` no longer depends on
`generic-array`. Password hashing goes through `hash_password_with_rng`.

Stored data is unaffected. The password hashing snapshots are unchanged,
so bcrypt, Argon2 and PBKDF2 produce the same hashes for the same input
and salt, and `pbkdf2` 0.13 keeps the same defaults (SHA-256, 600 000
rounds). The keystore snapshots change only because keys generated from
a seeded RNG differ. The snapshots of keys loaded from files are
unchanged.

`opa-wasm` 0.3.3 already uses this generation, so most of the duplicate
crates it pulled in go away. The `deny.toml` skip list now names what
still pulls the older versions: cookie, sqlx, headers, wasmtime and pest
for RustCrypto, and opentelemetry_sdk, sentry and ulid for `rand` 0.9.
2026-10-09 15:42:26 +02:00
Quentin Gliech 2762927a47 Fix the lints introduced by clippy 1.98
The new `unused_async_trait_impl` lint flags `async fn` trait impls without any `.await`. The `FromRequestParts` impls that only read from the request parts now return `std::future::ready(...)` directly. The GraphQL module gets a module-wide allow: async-graphql's `#[Object]` refuses non-async resolvers and its `Enum` derive emits async trait impls of its own.

Also drop the `?` on two `return Err(...)?` statements in the introspection handler, flagged by `needless_return_with_question_mark`.
2026-09-10 15:53:23 +02:00
Olivier 'reivilibre bebc7731dd Implement hard shutdown and exit for task timeout (#5930) 2026-09-04 13:52:54 +01:00
adis veletanlic 76bc2647c1 Merge branch 'main' into feat/lifecycle-task-hard-timeout 2026-08-19 14:33:53 +02:00
defaultdino 35be69bf15 implement hard shutdown and exit for task timeout 2026-08-19 14:30:51 +02:00
Kai A. Hiller 0bd67a9f9a Add unittest for database connection via pgpass 2026-08-18 13:13:49 +02:00
Quentin Gliech 8892cc7eb8 Remove the GraphQL playground (#5914) 2026-08-10 14:57:59 +02:00
Quentin Gliech c3b5fa3b0c Remove the GraphQL playground
The interactive playground page and its route/config option are gone; the GraphQL API itself (POST /graphql) is unaffected. External GraphQL usage is deprecated anyway in favour of the REST admin API.
2026-08-07 12:26:42 +02:00
Quentin Gliech 146b7fe379 Update the Sentry transport to use the new options API 2026-08-07 10:07:38 +02:00
Quentin Gliech 9d521acd02 Replace Unix socket on startup & allow setting permissions (#5858) 2026-07-28 13:48:39 +02:00
Quentin GliechandErik Johnston fc94b550db Use Utf8Path::with_added_extension for constructing the temporary socket path
Co-Authored-By: Erik Johnston <erikj@element.io>
2026-07-28 13:21:34 +02:00
networkException bdfeee2ceb Add password_file config variant for email and database 2026-07-26 17:57:40 +02:00
Kai A. Hiller 2e47d7a119 Add client_uri config for static clients 2026-07-24 13:09:38 +02:00
Quentin Gliech cd78f82f9c Replace Unix socket on startup & allow setting permissions
Fixes #5572
Fixes #2424

This makes it so that MAS binds on a temporary path on startup, sets
permissions and then moves it to the configured path. This means that we don't
error out anymore if there is a stale socket file, and that it is safe to
rollout a new process without killing the old one first, without breaking
connections.
2026-07-13 13:46:47 +02:00
Quentin Gliech 13d10dfe7e Adapt to the sd-notify 0.5 API changes
`notify()` lost its `unset_env` argument, and `watchdog_enabled()` now
returns an `Option<Duration>` directly.
2026-07-02 22:22:51 +02:00
Quentin Gliech 1d1bcbaf26 cli: clean up the doctor homeserver checks
MSC2965 changed the discovery mechanism to stop relying on .well-known
documents a while back. We removed references to this in the configuration
manual some time ago (see e3d1b8abfa) but
`mas-cli doctor` was still checking for it.

See element-hq/backend-internal#5 as well
2026-06-25 19:04:18 +02:00
Quentin Gliech e42d85d14e Merge branch 'main' into the requester logging branch 2026-06-18 13:43:59 +02:00
Quentin Gliech e4157b4b02 Log the GraphQL operation type and name (#5736) 2026-06-18 13:34:55 +02:00
Quentin Gliech e0c03b06e8 deps: upgrade reqwest 0.13, sentry 0.48, opentelemetry 0.32
We need to group the sentry and opentelemetry bumps together because they both
upgraded reqwest to 0.13.

- reqwest 0.12 -> 0.13: rename the rustls feature to rustls-no-provider,
  add the now-opt-in 'form' feature.
- sentry 0.46 -> 0.48: add rustls-no-provider so Sentry's reqwest 0.13
  transport reuses our process-wide aws-lc-rs provider.
- opentelemetry 0.31 -> 0.32 / tracing-opentelemetry 0.33: update the
  get_otel_context call in mas-context for the new signature.

opentelemetry-jaeger-propagator 0.32 is deprecated upstream but still
published; we keep it for now (with an expect(deprecated)) and will
vendor it in-tree once it's actually removed.
2026-06-17 19:00:25 +02:00
Quentin Gliech 269c1d9caf Merge branch 'main' into the requester logging branch 2026-06-17 17:57:16 +02:00
Quentin Gliech 9133820368 Merge branch 'main' into the GraphQL logging branch 2026-06-17 17:57:16 +02:00
Quentin Gliech a2533cd3f3 Track and log the client IP address (#5734) 2026-06-17 17:45:06 +02:00
Quentin Gliech eb0ef6380c Merge branch 'main' into quenting/upstream-pass-parameters 2026-06-17 14:54:37 +02:00
Quentin Gliech 9e60371aeb mas-cli: log the requester on the request log line
Add `requester=...` to the `http.server.response` log line, reading the
`Requester` recorded on the request's `LogContext`.
2026-06-17 14:14:24 +02:00
Quentin Gliech 98106df25a mas-cli: log the GraphQL operation on the request log line
Read the `GraphQlOperation` set by the GraphQL handler from the response
extensions in the logging middleware, and record the operation type and name
on the `http.server.response` log line when present.
2026-06-17 14:14:24 +02:00
Quentin Gliech 31b0b208c0 Record the client address on the HTTP request span 2026-06-17 14:14:24 +02:00
Quentin Gliech 4cea9320d1 Track the client IP address for the whole request and log it 2026-06-17 14:14:23 +02:00
Quentin GliechandOlivier 'reivilibre' a209eef119 Apply suggestion from @reivilibre
Co-authored-by: Olivier 'reivilibre' <oliverw@element.io>
2026-06-17 12:51:40 +02:00
Quentin Gliech 21795d70dc Fix clippy lints for Rust 1.96.0
Rust 1.96.0 enables several new clippy lints. Apply the machine-applicable
fixes (`duration_suboptimal_units`, `map_unwrap_or`, `manual_is_variant_and`,
`unnecessary_trailing_comma`, `while_let_loop`) and suppress the
`result_large_err` lint in the config test modules, where the closures passed to
`Jail::expect_with` are required to return the large `figment::Error`.
2026-06-16 15:38:22 +02:00
Quentin Gliech 632d64d199 Per-provider registration token requirement (#5605) 2026-06-10 10:05:46 +02:00
Quentin Gliech 3025708520 Add a configuration option to disable device code auto-fill 2026-05-28 13:30:25 +02:00
Eric Eastwood ee88379fc4 Remove unused lint ignores 2026-05-21 16:44:20 -05:00
Eric Eastwood fa23689962 #[allow -> #[expect 2026-05-21 16:37:47 -05:00