Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Type warnings in Event and Metrics when OpenTelemetry tracing is unavailable (Elixir 1.20)

クローズ 初心者向け
#1,242 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #1243 @whatyouhide による — マージ済み

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
領域
observability

調査の方向性

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 の本文から書いたものです。

説明

Bug Elixir Waiting for: Product Owner
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
  1. Create a project on Elixir 1.20.x that depends on {:sentry, "~> 14.0"} and doesn't include opentelemetry.
  2. 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/0 calls put_trace_context(contexts). The tracing branch matches on TraceContext.current(); the other branch returns contexts unchanged.
  • Sentry.Metrics: trace_context/0 is TraceContext.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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

getsentry/sentry-elixir のほかの issue

getsentry/sentry-elixir の issue をすべて見る

似ている issue

Elixir の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。