Skip to content

Commit

Permalink
WIP tracing support (#553)
Browse files Browse the repository at this point in the history
* WIP tracing support
* Added unit tests,
* Moved integration tests to allow for modifying xunit behavior
  • Loading branch information
david-driscoll authored Apr 24, 2021
1 parent 12277eb commit 005c87f
Show file tree
Hide file tree
Showing 69 changed files with 870 additions and 164 deletions.
15 changes: 15 additions & 0 deletions LSP.sln
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dap.Protocol.Proposals", "s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Protocol.Proposals", "src\Protocol.Proposals\Protocol.Proposals.csproj", "{201B1CA7-AB12-41AD-9246-BC30F2EBE2DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lsp.Integration.Tests", "test\Lsp.Integration.Tests\Lsp.Integration.Tests.csproj", "{72A74595-A278-46F0-9C8B-3151C9681B91}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -357,6 +359,18 @@ Global
{201B1CA7-AB12-41AD-9246-BC30F2EBE2DF}.Release|x64.Build.0 = Release|Any CPU
{201B1CA7-AB12-41AD-9246-BC30F2EBE2DF}.Release|x86.ActiveCfg = Release|Any CPU
{201B1CA7-AB12-41AD-9246-BC30F2EBE2DF}.Release|x86.Build.0 = Release|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Debug|x64.ActiveCfg = Debug|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Debug|x64.Build.0 = Debug|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Debug|x86.ActiveCfg = Debug|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Debug|x86.Build.0 = Debug|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Release|Any CPU.Build.0 = Release|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Release|x64.ActiveCfg = Release|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Release|x64.Build.0 = Release|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Release|x86.ActiveCfg = Release|Any CPU
{72A74595-A278-46F0-9C8B-3151C9681B91}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -385,6 +399,7 @@ Global
{58E83291-1ED9-4921-A12F-F2450AB17F47} = {2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}
{D43637CC-94E6-4ED4-BAA3-E5D1AD3285F5} = {D764E024-3D3F-4112-B932-2DB722A1BACC}
{201B1CA7-AB12-41AD-9246-BC30F2EBE2DF} = {D764E024-3D3F-4112-B932-2DB722A1BACC}
{72A74595-A278-46F0-9C8B-3151C9681B91} = {2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D38DD0EC-D095-4BCD-B8AF-2D788AF3B9AE}
Expand Down
Empty file modified build.sh
100644 → 100755
Empty file.
30 changes: 24 additions & 6 deletions src/Dap.Protocol/DapReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ protected virtual IEnumerable<Renor> GetRenor(JToken @object)
var sequence = id.Value<long>();
var messageType = type.Value<string>();

var properties = request.Properties().ToLookup(z => z.Name, StringComparer.OrdinalIgnoreCase);

if (messageType == "event")
{
if (!request.TryGetValue("event", out var @event))
Expand All @@ -60,7 +62,10 @@ protected virtual IEnumerable<Renor> GetRenor(JToken @object)
yield break;
}

yield return new Notification(@event.Value<string>(), request.TryGetValue("body", out var body) ? body : null);
yield return new Notification(@event.Value<string>(), request.TryGetValue("body", out var body) ? body : null) {
TraceState = properties["tracestate"].FirstOrDefault()?.Value<string>(),
TraceParent = properties["traceparent"].FirstOrDefault()?.Value<string>()
};
yield break;
}

Expand All @@ -81,16 +86,29 @@ protected virtual IEnumerable<Renor> GetRenor(JToken @object)
// This makes it so that the cancel handler implementer must still return a positive response even if the request didn't make it through.
if (ro.TryGetValue("requestId", out var requestId))
{
yield return new Notification(JsonRpcNames.CancelRequest, JObject.FromObject(new { id = requestId }));
yield return new Notification(JsonRpcNames.CancelRequest, JObject.FromObject(new { id = requestId })) {
TraceState = properties["tracestate"].FirstOrDefault()?.Value<string>(),
TraceParent = properties["traceparent"].FirstOrDefault()?.Value<string>()
};
ro.Remove("requestId");
}
else
{
yield return new Request(sequence, RequestNames.Cancel, ro) {
TraceState = properties["tracestate"].FirstOrDefault()?.Value<string>(),
TraceParent = properties["traceparent"].FirstOrDefault()?.Value<string>()
};
yield break;
}
}

yield return new Request(sequence, RequestNames.Cancel, ro);
{
yield return new Request(sequence, requestName, requestObject) {
TraceState = properties["tracestate"].FirstOrDefault()?.Value<string>(),
TraceParent = properties["traceparent"].FirstOrDefault()?.Value<string>()
};
yield break;
}

yield return new Request(sequence, requestName, requestObject);
yield break;
}

if (messageType == "response")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public override void WriteJson(JsonWriter writer, OutgoingNotification value, Js
writer.WritePropertyName("body");
serializer.Serialize(writer, value.Params);
}
if (value.TraceParent != null)
{
writer.WritePropertyName("traceparent");
writer.WriteValue(value.TraceParent);
if (!string.IsNullOrWhiteSpace(value.TraceState))
{
writer.WritePropertyName("tracestate");
writer.WriteValue(value.TraceState);
}
}

writer.WriteEndObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public override void WriteJson(JsonWriter writer, OutgoingRequest value, JsonSer
writer.WritePropertyName("arguments");
serializer.Serialize(writer, value.Params);
}
if (value.TraceParent != null)
{
writer.WritePropertyName("traceparent");
writer.WriteValue(value.TraceParent);
if (!string.IsNullOrWhiteSpace(value.TraceState))
{
writer.WritePropertyName("tracestate");
writer.WriteValue(value.TraceState);
}
}

writer.WriteEndObject();
}
Expand Down
5 changes: 3 additions & 2 deletions src/Dap.Shared/DebugAdapterRequestRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ internal class DebugAdapterRequestRouter : RequestRouterBase<IHandlerDescriptor>
private readonly DebugAdapterHandlerCollection _collection;

public DebugAdapterRequestRouter(
DebugAdapterHandlerCollection collection, ISerializer serializer, IServiceScopeFactory serviceScopeFactory, ILogger<DebugAdapterRequestRouter> logger
DebugAdapterHandlerCollection collection, ISerializer serializer, IServiceScopeFactory serviceScopeFactory, ILogger<DebugAdapterRequestRouter> logger,
IActivityTracingStrategy? activityTracingStrategy = null
)
: base(serializer, serviceScopeFactory, logger) =>
: base(serializer, serviceScopeFactory, logger, activityTracingStrategy) =>
_collection = collection;

public IDisposable Add(IJsonRpcHandler handler) => _collection.Add(handler);
Expand Down
69 changes: 36 additions & 33 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"/>
<PropertyGroup>
<PackageVersion Condition="'$(GitVersion_NuGetVersion)' != ''">$(GitVersion_NuGetVersion)</PackageVersion>
<AssemblyVersion>0.0.9.9</AssemblyVersion>
<AssemblyVersion Condition="'$(GitVersion_AssemblySemVer)' != ''">$(GitVersion_Major).$(GitVersion_Minor).0.0</AssemblyVersion>
<FileVersion Condition="'$(GitVersion_AssemblySemVer)' != ''">$(GitVersion_AssemblySemVer)</FileVersion>
<InformationalVersion Condition="'$(GitVersion_InformationalVersion)' != ''">$(GitVersion_InformationalVersion)</InformationalVersion>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Client.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>JsonRpc.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Dap.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Lsp.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>TestingUtils, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"/>
<PropertyGroup>
<PackageVersion Condition="'$(GitVersion_NuGetVersion)' != ''">$(GitVersion_NuGetVersion)</PackageVersion>
<AssemblyVersion>0.0.9.9</AssemblyVersion>
<AssemblyVersion Condition="'$(GitVersion_AssemblySemVer)' != ''">$(GitVersion_Major).$(GitVersion_Minor).0.0</AssemblyVersion>
<FileVersion Condition="'$(GitVersion_AssemblySemVer)' != ''">$(GitVersion_AssemblySemVer)</FileVersion>
<InformationalVersion Condition="'$(GitVersion_InformationalVersion)' != ''">$(GitVersion_InformationalVersion)</InformationalVersion>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Client.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>JsonRpc.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Dap.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Lsp.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Lsp.Integration.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>TestingUtils, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
16 changes: 15 additions & 1 deletion src/JsonRpc/Client/OutgoingNotification.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
using Newtonsoft.Json;

namespace OmniSharp.Extensions.JsonRpc.Client
{
public record OutgoingNotification
public record OutgoingNotification : ITraceData
{
public string Method { get; set; } = null!;

public object? Params { get; set; }

/// <summary>
/// Gets or sets the data for the <see href="https://www.w3.org/TR/trace-context/">W3C Trace Context</see> <c>traceparent</c> value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string? TraceParent { get; set; }

/// <summary>
/// Gets or sets the data for the <see href="https://www.w3.org/TR/trace-context/">W3C Trace Context</see> <c>tracestate</c> value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string? TraceState { get; set; }
}
}
14 changes: 13 additions & 1 deletion src/JsonRpc/Client/OutgoingRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@

namespace OmniSharp.Extensions.JsonRpc.Client
{
public record OutgoingRequest
public record OutgoingRequest : ITraceData
{
public object? Id { get; set; }

public string? Method { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public object? Params { get; set; }

/// <summary>
/// Gets or sets the data for the <see href="https://www.w3.org/TR/trace-context/">W3C Trace Context</see> <c>traceparent</c> value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string? TraceParent { get; set; }

/// <summary>
/// Gets or sets the data for the <see href="https://www.w3.org/TR/trace-context/">W3C Trace Context</see> <c>tracestate</c> value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string? TraceState { get; set; }
}
}
Loading

0 comments on commit 005c87f

Please sign in to comment.