Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<PackageVersion Include="PolySharp" Version="1.16.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.35.0.4138" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
<!-- Should stay on LTS .NET releases. -->
<PackageVersion Include="System.Formats.Asn1" Version="10.0.14" />
<PackageVersion Include="Testcontainers" Version="4.16.0" />
Expand Down
36 changes: 36 additions & 0 deletions src/Renci.SshNet/BaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ internal IServiceFactory ServiceFactory
get { return _serviceFactory; }
}

/// <summary>
/// Gets the protocol name used in telemetry for this client.
/// </summary>
private protected virtual string TelemetryProtocolName
{
get { return "ssh"; }
}

/// <summary>
/// Gets the connection info.
/// </summary>
Expand Down Expand Up @@ -209,6 +217,20 @@ public void Connect()
{
CheckDisposed();

using var operation = SshNetTelemetry.StartOperation(TelemetryProtocolName, "Connect", _connectionInfo);
try
{
ConnectCore();
}
catch (Exception ex)
{
operation?.SetError(ex);
throw;
}
}

private void ConnectCore()
{
// TODO (see issue #1758):
// we're not stopping the keep-alive timer and disposing the session here
//
Expand Down Expand Up @@ -278,6 +300,20 @@ public async Task ConnectAsync(CancellationToken cancellationToken)
CheckDisposed();
cancellationToken.ThrowIfCancellationRequested();

using var operation = SshNetTelemetry.StartOperation(TelemetryProtocolName, "Connect", _connectionInfo);
try
{
await ConnectCoreAsync(cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
operation?.SetError(ex);
throw;
}
}

private async Task ConnectCoreAsync(CancellationToken cancellationToken)
{
// TODO (see issue #1758):
// we're not stopping the keep-alive timer and disposing the session here
//
Expand Down
6 changes: 6 additions & 0 deletions src/Renci.SshNet/NetConfClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ public XmlDocument ClientCapabilities
/// </value>
public bool AutomaticMessageIdHandling { get; set; }

/// <inheritdoc/>
private protected override string TelemetryProtocolName
{
get { return "netconf"; }
}

/// <summary>
/// Sends the receive RPC.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions src/Renci.SshNet/Renci.SshNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<PackageReference Include="Microsoft.Bcl.Cryptography" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Formats.Asn1" />
</ItemGroup>
Expand Down
Loading