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.
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.
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.
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.
`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`.
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.
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`.
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.
`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
`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.
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`.
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.
Fixes#5572Fixes#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.
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
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.
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.
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`.