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

Ouverte
#1,854 4 commentaires 3 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 3 jours

@YoussefElshemi y travaille déjà.

Depuis le 27/10/2026.

  • #1857 par @YoussefElshemi — ouverte

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
35/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Active
Stack technique
csharp
Domaine
observability

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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?

Langage dominant
C#
Étoiles
4.4k
Forks
987
Merge moyen
2 j 6 h
PR mergées (30 j)
4

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de sshnet/SSH.NET

Toutes les issues de sshnet/SSH.NET

Issues similaires

Plus d'issues C#

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.