Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Cerrado Apto para principiantes
#1,242 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Ya se ha fusionado un pull request relacionado.

  • #1243 de @whatyouhide — fusionado

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
65/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo

Línea de trabajo

Empieza en lib/sentry/event.ex en generate_contexts/0 (alrededor de la línea 505) y en lib/sentry/metrics.ex en record_metric/4 (alrededor de la línea 165), donde current_trace_context/0 se define como nil cuando Sentry.OpenTelemetry.VersionChecker.tracing_compatible?() es falso. Mueve la rama de compilación para que envuelva el código que usa el contexto de traza, como propone quien reportó el problema. Está terminado cuando compilar sin OpenTelemetry en Elixir 1.20 no genera advertencias y mix test sigue pasando.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Elixir
Estrellas
693
Forks
218
Merge medio
2 d 4 h
PR fusionados (30 d)
21

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de getsentry/sentry-elixir

Todos los issues de getsentry/sentry-elixir

Issues similares

Más issues de Elixir

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.