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

未关闭
#1,854 4 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

@YoussefElshemi 已经在做这个了。

开始于 2026年10月27日。

  • #1857 来自 @YoussefElshemi —— 未关闭

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
csharp
领域
observability

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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?

主要语言
C#
星标
4.4k
派生
987
平均合并
2 天 6 小时
30 天内合并 PR
4

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

sshnet/SSH.NET 的其他 Issue

查看 sshnet/SSH.NET 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。