Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#1,242 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
observability

Direzione di ricerca

Inizia da lib/sentry/event.ex in generate_contexts/0 (intorno alla riga 505) e da lib/sentry/metrics.ex in record_metric/4 (intorno alla riga 165), dove current_trace_context/0 è definita come nil quando Sentry.OpenTelemetry.VersionChecker.tracing_compatible?() è falso. Sposta il ramo di compilazione in modo che racchiuda il codice che usa il contesto di traccia, come propone chi ha segnalato il problema. Il lavoro è completato quando la compilazione senza OpenTelemetry su Elixir 1.20 non produce avvisi e mix test continua a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Elixir
Stelle
694
Fork
217
Merge medio
2g 6h
PR unite (30g)
20

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/sentry-elixir

Tutte le issue di getsentry/sentry-elixir

Issue simili

Altre issue su Elixir

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.