Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đã đóng Phù hợp với người mới
#1,242 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Một pull request liên quan đã được merge.

  • #1243 của @whatyouhide — đã merge

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
observability

Hướng nghiên cứu

Bắt đầu từ lib/sentry/event.ex tại generate_contexts/0 (khoảng dòng 505) và lib/sentry/metrics.ex tại record_metric/4 (khoảng dòng 165), nơi current_trace_context/0 được định nghĩa là nil khi Sentry.OpenTelemetry.VersionChecker.tracing_compatible?() trả về false. Di chuyển nhánh rẽ tại thời điểm biên dịch để nó bao quanh đoạn mã sử dụng ngữ cảnh trace, như người báo lỗi đề xuất. Hoàn thành khi biên dịch không có OpenTelemetry trên Elixir 1.20 không sinh ra cảnh báo nào và mix test vẫn pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Elixir
Star
693
Fork
218
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
21

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của getsentry/sentry-elixir

Tất cả issue của getsentry/sentry-elixir

Issue tương tự

Thêm issue về Elixir

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.