Commit Graph

16 Commits

Author SHA1 Message Date
Thomas Eizinger
de2afb23be chore: exclude noisy crates from Sentry breadcrumbs (#7189) 2024-10-30 14:09:43 +00:00
Thomas Eizinger
7037830b19 chore(connlib): submit DEBUG events as breadcrumbs (#7177)
This should give us much more context for a particular error without
having to bother a customer with sending us the logs / digging for them
ourselves in our staging or production environment.

Resolves: #7176.
2024-10-29 23:39:07 +00:00
Thomas Eizinger
1f7a0430b7 chore(rust): record tracing WARNs as Sentry exceptions (#7166)
It appears that I have misunderstood the documentation of
`sentry-tracing`. When a message gets logged as an event (rather than an
"exception") `std::error::Error`s attached as tracing `Value`s do not
get recorded. It doesn't really matter whether we record our events as
exceptions or messages. We should ideally look at all of them and
particularly noisy ones can be muted forever in Sentry so we don't end
up in a "boy who cried wolf" situation. Therefore, this PR changes our
event filter to also submit WARNs as exceptions to make sure they get
logged accordingly.

Resolves: #7161.
Related: https://github.com/getsentry/sentry-rust/issues/702.
2024-10-28 14:07:42 +00:00
Thomas Eizinger
82fcad0a3b refactor(rust): only send telemetry spans to Sentry (#7153)
With the introduction of the `tracing-sentry` integration in #7105, we
started sending tracing spans to Sentry. By default, all spans with
level INFO and above get sampled at the configured rate and sent to
Sentry.

This results in a lot of useless transaction in Sentry because we use
INFO level spans in multiple places in connlib to attach contextual
information like the current connection ID.

This PR introduces the concept of `telemetry` spans which - similar to
the `telemetry` log target in #7147 - qualifies a span for being sent to
Sentry. By convention, these are also defined as requiring the TRACE
level. This ensures we won't ever see them as part of regular log
output.
2024-10-24 20:25:26 +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
80c5b0df71 refactor(connlib): replace LogUnwrap with macros (#7138)
Using a trait means the call-site of the log message will always be the
`log_unwrap` module, despite the `#[track_caller]` annotation. That one
only works for `std::panic::Location` unfortunately which `tracing`
isn't using.

Macros will be evaluated earlier and thus the messages will show up with
the correct module name.
2024-10-23 23:44:23 +00:00
Thomas Eizinger
6eecfc0cfb fix: replace panics with Result for IP packets (#7135)
My theory for this issue is that we receive a UDP DNS response from an
upstream server that is bigger than our MTU and thus forwarding it
fails.

This PR doesn't fix that issue by itself but only mitigates the actual
panic. To properly fix the underlying issue, we need to parse the DNS
message. Truncate it and set the TC bit.

Related: #7121.
2024-10-23 16:25:12 +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
73eebd2c4d refactor(rust): consistently record errors as tracing::Value (#7104)
Our logging library, `tracing` supports structured logging. This is
useful because it preserves the more than just the string representation
of a value and thus allows the active logging backend(s) to capture more
information for a particular value.

In the case of errors, this is especially useful because it allows us to
capture the sources of a particular error.

Unfortunately, recording an error as a tracing value is a bit cumbersome
because `tracing::Value` is only implemented for `&dyn
std::error::Error`. Casting an error to this is quite verbose. To make
it easier, we introduce two utility functions in `firezone-logging`:

- `std_dyn_err`
- `anyhow_dyn_err`

Tracking errors as correct `tracing::Value`s will be especially helpful
once we enable Sentry's `tracing` integration:
https://docs.rs/sentry-tracing/latest/sentry_tracing/#tracking-errors
2024-10-22 04:46:26 +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
a9f515a453 chore(rust): use #[expect] instead of #[allow] (#6692)
The `expect` attribute is similar to `allow` in that it will silence a
particular lint. In addition to `allow` however, `expect` will fail as
soon as the lint is no longer emitted. This ensures we don't end up with
stale `allow` attributes in our codebase. Additionally, it provides a
way of adding a `reason` to document, why the lint is being suppressed.
2024-09-16 13:51:12 +00:00
Reactor Scram
5a44151bba test(bin-shared): improve network notifier test (#6676)
On Windows, the network notifier always notifies once at startup. We
make the DNS notifier and Linux match this behavior, and we assert it in
the unit test.

Part of a yak shave towards removing Tauri.
2024-09-13 14:53:13 +00:00
Reactor Scram
ac2d4cd95e chore(rust): disable ANSI coloring in log files (#6508)
Closes #6467

It's still enabled for the stdout / stderr logs
2024-08-30 20:23:48 +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