Proposal: built-in tracing and metrics via ActivitySource/Meter

Aperta
#1,854 4 commenti 3 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@YoussefElshemi ci sta già lavorando.

Dal 27/10/2026.

  • #1857 di @YoussefElshemi — aperta

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
observability

Direzione di ricerca

Read the working prototype linked in the issue and inspect the existing Internal* methods it hooks into. The proposal covers tracing for connections, SFTP operations, and command execution, plus an operation duration metric; existing unit tests and integration tests are reported passing. Before implementation, resolve the dependency, attribute naming, command secrecy, and first PR scope questions; done means the agreed telemetry scope is covered and verified.

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

Descrizione

Hi, I'd like to propose adding built-in tracing and metrics to SSH.NET using System.Diagnostics.ActivitySource and Meter, the same approach Npgsql and the MongoDB driver use.

I first opened an OpenTelemetry contrib package that wraps ISftpClient/ISshClient (https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/5781). An OTel maintainer suggested building it into the library instead, so users only need AddSource("Renci.SshNet") and AddMeter("Renci.SshNet"). That also works with other backends (Datadog, App Insights), and covers cases a wrapper can't reach: CreateCommand + Execute, Begin*/End*, non-seekable streams.

I have a working prototype: https://github.com/YoussefElshemi/SSH.NET/tree/native-telemetry

  • Spans:
    • Connect (ssh/sftp/scp/netconf)
    • SFTP UploadFile, DownloadFile, ListDirectory
    • SshCommand execution
  • Metric: ssh.client.operation.duration histogram (seconds)
  • Where it hooks in: the existing Internal* methods, so every overload is covered
  • When nobody is listening: no allocation or extra work
  • Tests: existing unit tests pass. New integration tests pass on net48/net8/net9/net10.

Questions before I go further:

  1. It adds System.Diagnostics.DiagnosticSource (8.0.1) as a dependency on net462/netstandard2.0 only. Is that acceptable?
  2. Attribute names like ssh.operation.name, sftp.transfer.bytes and ssh.command.exit_code aren't official OpenTelemetry names yet. Any preference?
  3. Command text isn't recorded, since it may contain secrets. Should there be an opt-in?
  4. Should a first PR stay this small, or also cover Exists/Delete/Rename/SCP?

Would you be open to a PR along these lines?

Lingua principale
C#
Stelle
4.4k
Fork
987
Merge medio
2g 6h
PR unite (30g)
4

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 sshnet/SSH.NET

Tutte le issue di sshnet/SSH.NET

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.