[Analyzer Proposal]: Check for correct event ID passed to `EventSource.WriteEvent` based on the `System.Diagnostics.Tracing.EventAttribute`

Đang mở
#137,091 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 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
47/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
tooling

Hướng nghiên cứu

Read the EventSource validation path in src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs, especially the method linked in the issue, and examine existing Roslyn analyzer patterns in the repository. Determine how to validate that WriteEvent receives the ID declared by EventAttribute, then define completion as covering the proposed analyzer and removing the runtime IL inspection. The issue does not name analyzer files or tests, so locate those before estimating the implementation.

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

Mô tả

api-suggestion area-System.Diagnostics.Tracing code-analyzer untriaged

Today, EventSource does a best effort check at runtime (by inspecting the IL body of the method) that event methods of the following shape pass the matching event ID to their attribute:

[Event(1)]
public void OnInterestingEvent()
{
    if (IsEnabled()) { WriteEvent(1,...); }
}

This means that we're inspecting the IL body of each method on event source enablement:

https://github.com/dotnet/runtime/blob/a4106c734319b45fd6576e0a6dcd8bbdd08f8e7c/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs#L3697

This also means that we carry this around in all of our apps if any event source format is supported (ETW, eventpipe, etc).

I propose that we move this validation into an analyzer and remove it from the runtime validation. Since it's already best effort, it is a good fit for a Roslyn analyzer.

Ngôn ngữ chính
C#
Star
18.4k
Fork
5.8k
Merge trung bình
2 ngày 12 giờ
Pull request đã merge (30 ngày)
581

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

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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 dotnet/runtime

Tất cả issue của dotnet/runtime

Issue tương tự

Thêm issue về C#

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.