Commit Graph

10 Commits

Author SHA1 Message Date
Thomas Eizinger
a5086af352 chore(rust): remove JSON logging (#7854)
Nobody looks at these logs, writing them uses unnecessary CPU + storage
on users devices. It also means we have 1 background thread less because
we need one less non-blocking writer.
2025-01-27 23:35:07 +00:00
Thomas Eizinger
dd6b52b236 chore(rust): share edition key via workspace table (#7451) 2024-12-03 00:28:06 +00:00
Thomas Eizinger
2c26fc9c0e ci: lint Rust dependencies using cargo deny (#7390)
One of Rust's promises is "if it compiles, it works". However, there are
certain situations in which this isn't true. In particular, when using
dynamic typing patterns where trait objects are downcast to concrete
types, having two versions of the same dependency can silently break
things.

This happened in #7379 where I forgot to patch a certain Sentry
dependency. A similar problem exists with our `tracing-stackdriver`
dependency (see #7241).

Lastly, duplicate dependencies increase the compile-times of a project,
so we should aim for having as few duplicate versions of a particular
dependency as possible in our dependency graph.

This PR introduces `cargo deny`, a linter for Rust dependencies. In
addition to linting for duplicate dependencies, it also enforces that
all dependencies are compatible with an allow-list of licenses and it
warns when a dependency is referred to from multiple crates without
introducing a workspace dependency. Thanks to existing tooling
(https://github.com/mainmatter/cargo-autoinherit), transitioning all
dependencies to workspace dependencies was quite easy.

Resolves: #7241.
2024-11-22 00:17:28 +00:00
Thomas Eizinger
19f51568c2 chore(rust): don't pass errors as values for debug logs (#7318)
Our logging library `tracing` supports structured logging. Structured
logging means we can include values within a `tracing::Event` without
having to immediately format it as a string. Processing these values -
such as errors - as their original type allows the various `tracing`
layers to capture and represent them as they see fit.

One of these layers is responsible for sending ERROR and WARN events to
Sentry, as part of which `std::error::Error` values get automatically
captured as so-called "sentry exceptions".

Unfortunately, there is a caveat: If an `std::error::Error` value is
included in an event that does not get mapped to an exception, the
`error` field is completely lost. See
https://github.com/getsentry/sentry-rust/issues/702 for details.

To work around this, we introduce a `err_with_sources` adapter that an
error and all its sources together into a string. For all
`tracing::debug!` statements, we then use this to report these errors.

It is really unfortunate that we have to do this and cannot use the same
mechanism, regardless of the log level. However, until this is fixed
upstream, this will do and gives us better information in the log
submitted to Sentry.
2024-11-12 04:00:02 +00:00
Thomas Eizinger
12ca4f1cc7 chore(connlib): introduce telemetry log target (#7147)
With #7105, all ERROR events from `tracing` get logged as exceptions in
Sentry and all WARN events get logged as "messages". We don't want to
fill up the user's harddrive with logs which means we have to be
somewhat conservative, what gets logged on INFO and above (with INFO
being the default log level). There are certain events though where it
would be useful to know, how often they happen because too many of them
can indicate a problem.

To solve this problem, we introduce a dedicated `telemetry` log target
that the tracing-sentry integration layer watches for. Events for the
`telemetry` log target that gets logged on TRACE will be sampled at a
rate of 1% and submitted as messages to Sentry.
2024-10-24 01:24:45 +00:00
Thomas Eizinger
990324b2ec chore(rust): enable sentry-tracing integration (#7105)
Using the `sentry-tracing` integration, we can automatically capture
events based on what we log via `tracing`. The mapping is defined as
follows:

- ERROR: Gets captured as a fatal error
- WARN: Gets captured as a message
- INFO: Gets captured as a breadcrumb
- `_`: Does not get captured at all

If telemetry isn't active / configured, this integration does nothing.
It is therefore safe to just always enable it.
2024-10-22 23:23:49 +00:00
dependabot[bot]
13b7c11d76 build(deps): Bump nu-ansi-term from 0.46.0 to 0.50.1 in /rust (#7113)
Bumps [nu-ansi-term](https://github.com/nushell/nu-ansi-term) from
0.46.0 to 0.50.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/nushell/nu-ansi-term/releases">nu-ansi-term's
releases</a>.</em></p>
<blockquote>
<h2>v0.50.1</h2>
<h2>What's Changed</h2>
<ul>
<li>Remove unused import by <a
href="https://github.com/nickelc"><code>@​nickelc</code></a> in <a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/63">nushell/nu-ansi-term#63</a></li>
<li>Update <code>windows-sys</code> to 0.52 by <a
href="https://github.com/nickelc"><code>@​nickelc</code></a> in <a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/62">nushell/nu-ansi-term#62</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/nushell/nu-ansi-term/compare/v0.50.0...v0.50.1">https://github.com/nushell/nu-ansi-term/compare/v0.50.0...v0.50.1</a></p>
<h2>v0.50.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Rename the LICENCE file to LICENSE by <a
href="https://github.com/newpavlov"><code>@​newpavlov</code></a> in <a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/51">nushell/nu-ansi-term#51</a></li>
<li>gnu_legacy: with GNU, write foreground first, else background first.
by <a href="https://github.com/sylvestre"><code>@​sylvestre</code></a>
in <a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/54">nushell/nu-ansi-term#54</a></li>
<li>Bump to 0.50 by <a
href="https://github.com/kubouch"><code>@​kubouch</code></a> in <a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/56">nushell/nu-ansi-term#56</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/newpavlov"><code>@​newpavlov</code></a>
made their first contribution in <a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/51">nushell/nu-ansi-term#51</a></li>
<li><a href="https://github.com/sylvestre"><code>@​sylvestre</code></a>
made their first contribution in <a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/54">nushell/nu-ansi-term#54</a></li>
<li><a href="https://github.com/kubouch"><code>@​kubouch</code></a> made
their first contribution in <a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/56">nushell/nu-ansi-term#56</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/nushell/nu-ansi-term/compare/v0.49.0...v0.50.0">https://github.com/nushell/nu-ansi-term/compare/v0.49.0...v0.50.0</a></p>
<h2>v0.49.0</h2>
<p>This release attempts to fix API limitations of the previous
<code>0.48.0</code> release.
You can now again construct <code>Style</code> directly through its
fields.</p>
<h2>Breaking changes</h2>
<h3>coming from <code>0.47.0</code></h3>
<ul>
<li>Style has now a <code>prefix_with_reset</code> field to enable
additional reset sequences that are introduced before setting a
style.</li>
</ul>
<h3>coming from <code>0.48.0</code></h3>
<ul>
<li><code>Style.with_reset</code> has been renamed to
<code>Style.prefix_with_reset</code></li>
<li><code>AnsiGenericString::hyperlink()</code> changed in signature
from <code>...(&amp;mut self, ...)</code> to <code>...(self, ...) -&gt;
Self</code></li>
<li><code>AnsiGenericString::icon()</code> and <code>::cwd()</code> have
been removed for now.</li>
</ul>
<h2>What's Changed</h2>
<ul>
<li>Fix Re-enabling manual Style creation by <a
href="https://github.com/mhelsley"><code>@​mhelsley</code></a> in <a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/47">nushell/nu-ansi-term#47</a></li>
<li>Use chaining for <code>AnsiGenericString::hyperlink</code> by <a
href="https://github.com/sholderbach"><code>@​sholderbach</code></a> in
<a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/48">nushell/nu-ansi-term#48</a></li>
<li>Make <code>Style.with_reset</code> more explicit as
<code>prefix_with_reset</code> by <a
href="https://github.com/sholderbach"><code>@​sholderbach</code></a> in
<a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/50">nushell/nu-ansi-term#50</a></li>
<li>Bump version for 0.49 release by <a
href="https://github.com/sholderbach"><code>@​sholderbach</code></a> in
<a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/49">nushell/nu-ansi-term#49</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/nushell/nu-ansi-term/compare/v0.48.0...v0.49.0">https://github.com/nushell/nu-ansi-term/compare/v0.48.0...v0.49.0</a></p>
<h2>v0.48.0</h2>
<blockquote>
<p><strong>Warning</strong>
This release introduces an unintended breaking change for users that
want to construct <code>Style</code> directly. (see <a
href="https://redirect.github.com/nushell/nu-ansi-term/issues/46">#46</a>
for tracking)</p>
</blockquote>
<h2>New features</h2>
<p>This release <a
href="https://redirect.github.com/nushell/nu-ansi-term/pull/43">introduces
support</a> to express several OSC control codes by calling methods on
<code>AnsiGenericString</code>. Primarily you can now mark particular
text with a hyperlink by calling <code>.hyperlink()</code> on it.</p>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/nushell/nu-ansi-term/blob/main/CHANGELOG.md">nu-ansi-term's
changelog</a>.</em></p>
<blockquote>
<h1>Changelog</h1>
<h2>v0.47.0 (2023-03-13)</h2>
<h3>Breaking changes</h3>
<ul>
<li>Bumped minimum supported Rust version (MSRV) to 1.62.1</li>
<li>Change of <code>Color::default()</code> value to the ANSI default
color <code>Color::Default</code> (code <code>39</code> and
<code>49</code> for foreground and background respectively). This
replaces <code>Color::White</code> as the default value.</li>
</ul>
<h3>Other changes</h3>
<ul>
<li><code>const</code>ification of several functions and methods.</li>
<li>Improved CI workflow.</li>
<li>Updated to Rust edition 2021.</li>
<li>Replaced <code>winapi</code> dependency with
<code>windows-sys</code>.</li>
<li>Removed <code>overload</code> dependency.</li>
<li>Added <code>AnsiGenericString::as_str()</code> to allow access to
the underlying string.</li>
<li>Fixed typos in README.</li>
<li>Added <code>CHANGELOG.md</code> for changes since forking
<code>ansi_term</code>.</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="0912f8f6a3"><code>0912f8f</code></a>
bump version number 0.50.1</li>
<li><a
href="b902580d8f"><code>b902580</code></a>
Update <code>windows-sys</code> to 0.52 (<a
href="https://redirect.github.com/nushell/nu-ansi-term/issues/62">#62</a>)</li>
<li><a
href="cc9b338a00"><code>cc9b338</code></a>
Remove unused import (<a
href="https://redirect.github.com/nushell/nu-ansi-term/issues/63">#63</a>)</li>
<li><a
href="eaf4f5ff47"><code>eaf4f5f</code></a>
Bump to 0.50 (<a
href="https://redirect.github.com/nushell/nu-ansi-term/issues/56">#56</a>)</li>
<li><a
href="6c7e2627fe"><code>6c7e262</code></a>
gnu_legacy: with GNU, write fg first, else bg first. (<a
href="https://redirect.github.com/nushell/nu-ansi-term/issues/54">#54</a>)</li>
<li><a
href="f1c83ff292"><code>f1c83ff</code></a>
Rename the LICENCE file to LICENSE (<a
href="https://redirect.github.com/nushell/nu-ansi-term/issues/51">#51</a>)</li>
<li><a
href="eaa7d7f7e7"><code>eaa7d7f</code></a>
Bump version for 0.49 release (<a
href="https://redirect.github.com/nushell/nu-ansi-term/issues/49">#49</a>)</li>
<li><a
href="b972a62dce"><code>b972a62</code></a>
Make <code>Style.with_reset</code> more explicit as
<code>prefix_with_reset</code> (<a
href="https://redirect.github.com/nushell/nu-ansi-term/issues/50">#50</a>)</li>
<li><a
href="b853460c71"><code>b853460</code></a>
Use chaining for <code>AnsiGenericString::hyperlink</code> (<a
href="https://redirect.github.com/nushell/nu-ansi-term/issues/48">#48</a>)</li>
<li><a
href="76e507cecd"><code>76e507c</code></a>
Fix Re-enabling manual Style creation (<a
href="https://redirect.github.com/nushell/nu-ansi-term/issues/47">#47</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/nushell/nu-ansi-term/compare/v0.46.0...v0.50.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=nu-ansi-term&package-manager=cargo&previous-version=0.46.0&new-version=0.50.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-22 16:05:56 +00:00
Thomas Eizinger
3d6ed6dde7 refactor(connlib): respond with SERVFAIL on resolver error (#7067)
Currently, any failure in the `StubResolver` while processing a query
results only in a log but no response. For UDP DNS queries, that isn't
too bad because the client will simply retry. With the upcoming support
for TCP DNS queries in #6944, we should really always reply with a
message.

This PR refactors the handling of DNS messages to always generate a
reply. In the case of an error, we reply with SERVFAIL.

This opens up a few more refactorings where we can now collapse the
handling of some branches into the same. As part of that, I noticed the
recurring need for "unwrapping" a `Result<(), E>` and logging the error.
To make that easier, I introduced an extension trait that does exactly
that.
2024-10-17 03:01:59 +00:00
Thomas Eizinger
857bbf5d98 chore(connlib): introduce custom logging format (#7024)
This PR introduces a custom logging format for all Rust-components. It
is more or less a copy of `tracing_subscriber::fmt::format::Compact`
with the main difference that span-names don't get logged.

Spans are super useful because they allow us to record contextual
values, like the current connection ID, for a certain scope. What is IMO
less useful about them is that in the default formatter configuration,
active spans cause a right-drift of the actual log message.

The actual log message is still what most accurately describes, what
`connlib` is currently doing. Spans only add contextual information that
the reader may use for further understand what is happening. This
optional nature of the utility of spans IMO means that they should come
_after_ the actual log message.

Resolves: #7014.
2024-10-14 18:09:38 +00:00
Thomas Eizinger
bed625a312 chore(rust): make logging more ergonomic (#6237)
Setting up a logger is something that pretty much every entrypoint needs
to do, be it a test, a shared library embedded in another app or a
standalone application. Thus, it makes sense to introduce a dedicated
crate that allows us to bundle all the things together, how we want to
do logging.

This allows us to introduce convenience functions like
`firezone_logging::test` which allow you to construct a logger for a
test as a one-liner.

Crucially though, introducing `firezone-logging` gives us a place to
store a default log directive that silences very noisy crates. When
looking into a problem, it is common to start by simply setting the
log-filter to `debug`. Without further action, this floods the output
with logs from crates like `netlink_proto` on Linux. It is very unlikely
that those are the logs that you want to see. Without a preset filter,
the only alternative here is to explicitly turn off the log filter for
`netlink_proto` by typing something like
`RUST_LOG=netlink_proto=off,debug`. Especially when debugging issues
with customers, this is annoying.

Log filters can be overridden, i.e. a 2nd filter that matches the exact
same scope overrides a previous one. Thus, with this design it is still
possible to activate certain logs at runtime, even if they have silenced
by default.

I'd expect `firezone-logging` to attract more functionality in the
future. For example, we want to support re-loading of log-filters on
other platforms. Additionally, where logs get stored could also be
defined in this crate.

---------

Signed-off-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Reactor Scram <ReactorScram@users.noreply.github.com>
2024-08-10 05:17:03 +00:00