Type warnings in Event and Metrics when OpenTelemetry tracing is unavailable (Elixir 1.20)
メンテナーはふだん 2 日以内に返信
関連するプルリクエストがすでにマージされています。
- #1243 @whatyouhide による — マージ済み
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 65/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
調査の方向性
lib/sentry/event.ex の generate_contexts/0(505行目付近)と、lib/sentry/metrics.ex の record_metric/4(165行目付近)から始めてください。Sentry.OpenTelemetry.VersionChecker.tracing_compatible?() が偽の場合、current_trace_context/0 は nil として定義されています。報告者の提案どおり、コンパイル時の分岐がトレースコンテキストを使うコードを囲むように移動してください。OpenTelemetry なしで Elixir 1.20 でコンパイルしたときに警告が出ず、mix test が引き続き成功すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Issue Description
When OpenTelemetry tracing isn't available (Sentry.OpenTelemetry.VersionChecker.tracing_compatible?() is false at compile time), compiling sentry as a dependency on Elixir 1.20 emits two type warnings:
warning: the right-hand side of || will always execute:
current_trace_context()
because the left-hand side always evaluates to:
dynamic(nil)
└─ lib/sentry/metrics.ex:165: Sentry.Metrics.record_metric/4
warning: the following clause will never match:
{trace_id, span_id} ->
because it attempts to match on the result of:
current_trace_context()
which has type:
dynamic(nil)
└─ lib/sentry/event.ex:505: Sentry.Event.generate_contexts/0
In that configuration current_trace_context/0 is compiled as defp current_trace_context, do: nil in both modules. The type checker can then prove the callers' tuple branch dead. Line numbers are from master at db03025; 13.5.0 and 14.0.0 warn the same way.
Reproduction Steps
- Create a project on Elixir 1.20.x that depends on
{:sentry, "~> 14.0"}and doesn't include opentelemetry. rm -rf _build && mix compile.
Expected Behavior
sentry compiles without warnings.
Actual Behavior
The two warnings above, on every fresh compile of the dependency.
Elixir Version
1.20.2 and 1.20.4 (OTP 29)
SDK Version
14.0.0 (also 13.5.0 and master at db03025)
Integration and Its Version
None needed. Any app without a tracing-compatible OpenTelemetry setup hits this.
Proposed fix
Put the compile-time branch around the code that uses the trace context, instead of around a function that returns nil:
Sentry.Event:generate_contexts/0callsput_trace_context(contexts). The tracing branch matches onTraceContext.current(); the other branch returnscontextsunchanged.Sentry.Metrics:trace_context/0isTraceContext.current() || {generate_trace_id(), nil}in the tracing branch and{generate_trace_id(), nil}in the other.
Behaviour stays the same on both sides. I have this on a branch: the warnings are gone when compiled without OpenTelemetry, and mix test passes (1186 tests). Happy to open the PR if this approach works for you.
- 主要言語
- Elixir
- スター
- 693
- フォーク
- 218
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 21
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
getsentry/sentry-elixir のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
getsentry/sentry-elixir#1233 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 10/100
getsentry/sentry-elixir#1232 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
traces_sampler example doesn't match the actual context provided再び着手できるかも @solnic が 329 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンBug Elixir Traces Waiting for: Product Owner
getsentry/sentry-elixir#945 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
Better oban error grouping再び着手できるかも @solnic が 430 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンElixir Errors Improvement
getsentry/sentry-elixir#936 · コメント 1 件 · リアクション 2 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
Custom fingerprint added to GenServer call crashes by client再び着手できるかも @solnic が 437 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンBug Elixir Errors
getsentry/sentry-elixir#933 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
getsentry/sentry-elixir の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
ci-cd
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
carverauto/serviceradar#5648 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
opentelemetry_bandit: handler is detached when a client disconnects before the request starts (get_peer_data raises :enotconn)対応中かも @yordis が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
open-telemetry/opentelemetry-erlang-contrib#846 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100