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

Abierto
#137,091 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
47/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
csharp
Área
tooling

Línea de trabajo

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.

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

Descripción

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.

Lenguaje dominante
C#
Estrellas
18.4k
Forks
5.8k
Merge medio
2 d 12 h
PR fusionados (30 d)
581

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

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

Todos los issues de dotnet/runtime

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.