Skip to content

Commit 16b4001

Browse files
WIP tracing support
1 parent 1b6788d commit 16b4001

17 files changed

+639
-156
lines changed

build.sh

100644100755
Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
#!/usr/bin/env bash
2-
3-
echo $(bash --version 2>&1 | head -n 1)
4-
5-
set -eo pipefail
6-
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
7-
8-
###########################################################################
9-
# CONFIGURATION
10-
###########################################################################
11-
12-
BUILD_PROJECT_FILE="$SCRIPT_DIR/.build/.build.csproj"
13-
TEMP_DIRECTORY="$SCRIPT_DIR//.tmp"
14-
15-
DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
16-
DOTNET_INSTALL_URL="https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh"
17-
DOTNET_CHANNEL="Current"
18-
19-
export DOTNET_CLI_TELEMETRY_OPTOUT=1
20-
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
21-
22-
###########################################################################
23-
# EXECUTION
24-
###########################################################################
25-
26-
function FirstJsonValue {
27-
perl -nle 'print $1 if m{"'$1'": "([^"\-]+)",?}' <<< ${@:2}
28-
}
29-
30-
# If global.json exists, load expected version
31-
if [ -f "$DOTNET_GLOBAL_FILE" ]; then
32-
DOTNET_VERSION=$(FirstJsonValue "version" $(cat "$DOTNET_GLOBAL_FILE"))
33-
if [ "$DOTNET_VERSION" == "" ]; then
34-
unset DOTNET_VERSION
35-
fi
36-
fi
37-
38-
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
39-
if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version) == "$DOTNET_VERSION") ]]; then
40-
export DOTNET_EXE="$(command -v dotnet)"
41-
else
42-
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
43-
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
44-
45-
# Download install script
46-
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
47-
mkdir -p "$TEMP_DIRECTORY"
48-
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
49-
chmod +x "$DOTNET_INSTALL_FILE"
50-
51-
# Install by channel or version
52-
if [ -z ${DOTNET_VERSION+x} ]; then
53-
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
54-
else
55-
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
56-
fi
57-
fi
58-
59-
echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)"
60-
61-
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false
62-
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"
1+
#!/usr/bin/env bash
2+
3+
echo $(bash --version 2>&1 | head -n 1)
4+
5+
set -eo pipefail
6+
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
7+
8+
###########################################################################
9+
# CONFIGURATION
10+
###########################################################################
11+
12+
BUILD_PROJECT_FILE="$SCRIPT_DIR/.build/.build.csproj"
13+
TEMP_DIRECTORY="$SCRIPT_DIR//.tmp"
14+
15+
DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
16+
DOTNET_INSTALL_URL="https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh"
17+
DOTNET_CHANNEL="Current"
18+
19+
export DOTNET_CLI_TELEMETRY_OPTOUT=1
20+
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
21+
22+
###########################################################################
23+
# EXECUTION
24+
###########################################################################
25+
26+
function FirstJsonValue {
27+
perl -nle 'print $1 if m{"'$1'": "([^"\-]+)",?}' <<< ${@:2}
28+
}
29+
30+
# If global.json exists, load expected version
31+
if [ -f "$DOTNET_GLOBAL_FILE" ]; then
32+
DOTNET_VERSION=$(FirstJsonValue "version" $(cat "$DOTNET_GLOBAL_FILE"))
33+
if [ "$DOTNET_VERSION" == "" ]; then
34+
unset DOTNET_VERSION
35+
fi
36+
fi
37+
38+
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
39+
if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version) == "$DOTNET_VERSION") ]]; then
40+
export DOTNET_EXE="$(command -v dotnet)"
41+
else
42+
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
43+
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
44+
45+
# Download install script
46+
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
47+
mkdir -p "$TEMP_DIRECTORY"
48+
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
49+
chmod +x "$DOTNET_INSTALL_FILE"
50+
51+
# Install by channel or version
52+
if [ -z ${DOTNET_VERSION+x} ]; then
53+
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
54+
else
55+
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
56+
fi
57+
fi
58+
59+
echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)"
60+
61+
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false
62+
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"

src/Dap.Protocol/DapReceiver.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ protected virtual IEnumerable<Renor> GetRenor(JToken @object)
6060
yield break;
6161
}
6262

63-
yield return new Notification(@event.Value<string>(), request.TryGetValue("body", out var body) ? body : null);
63+
yield return new Notification(@event.Value<string>(), request.TryGetValue("body", out var body) ? body : null){
64+
TraceState = request.TryGetValue("tracestate", out var ts) ? ts.Value<string>() : null,
65+
TraceParent = request.TryGetValue("traceparent", out var tp) ? tp.Value<string>() : null,};
6466
yield break;
6567
}
6668

@@ -81,16 +83,29 @@ protected virtual IEnumerable<Renor> GetRenor(JToken @object)
8183
// This makes it so that the cancel handler implementer must still return a positive response even if the request didn't make it through.
8284
if (ro.TryGetValue("requestId", out var requestId))
8385
{
84-
yield return new Notification(JsonRpcNames.CancelRequest, JObject.FromObject(new { id = requestId }));
86+
yield return new Notification(JsonRpcNames.CancelRequest, JObject.FromObject(new { id = requestId })){
87+
TraceState = request.TryGetValue("tracestate", out var ts) ? ts.Value<string>() : null,
88+
TraceParent = request.TryGetValue("traceparent", out var tp) ? tp.Value<string>() : null,
89+
};
8590
ro.Remove("requestId");
8691
}
92+
else
93+
{
94+
yield return new Request(sequence, RequestNames.Cancel, ro) {
95+
TraceState = request.TryGetValue("tracestate", out var ts) ? ts.Value<string>() : null,
96+
TraceParent = request.TryGetValue("traceparent", out var tp) ? tp.Value<string>() : null,
97+
};
98+
yield break;
99+
}
100+
}
87101

88-
yield return new Request(sequence, RequestNames.Cancel, ro);
102+
{
103+
yield return new Request(sequence, requestName, requestObject) {
104+
TraceState = request.TryGetValue("tracestate", out var ts) ? ts.Value<string>() : null,
105+
TraceParent = request.TryGetValue("traceparent", out var tp) ? tp.Value<string>() : null,
106+
};
89107
yield break;
90108
}
91-
92-
yield return new Request(sequence, requestName, requestObject);
93-
yield break;
94109
}
95110

96111
if (messageType == "response")

src/Dap.Protocol/DebugAdapterConverters/DapClientNotificationConverter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ public override void WriteJson(JsonWriter writer, OutgoingNotification value, Js
3333
writer.WritePropertyName("body");
3434
serializer.Serialize(writer, value.Params);
3535
}
36+
if (value.TraceParent != null)
37+
{
38+
writer.WritePropertyName("traceparent");
39+
writer.WriteValue(value.TraceParent);
40+
}
41+
if (value.TraceState != null)
42+
{
43+
writer.WritePropertyName("tracestate");
44+
writer.WriteValue(value.TraceState);
45+
}
3646

3747
writer.WriteEndObject();
3848
}

src/Dap.Protocol/DebugAdapterConverters/DapClientRequestConverter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public override void WriteJson(JsonWriter writer, OutgoingRequest value, JsonSer
2828
writer.WritePropertyName("arguments");
2929
serializer.Serialize(writer, value.Params);
3030
}
31+
if (value.TraceParent != null)
32+
{
33+
writer.WritePropertyName("traceparent");
34+
writer.WriteValue(value.TraceParent);
35+
}
36+
if (value.TraceState != null)
37+
{
38+
writer.WritePropertyName("tracestate");
39+
writer.WriteValue(value.TraceState);
40+
}
3141

3242
writer.WriteEndObject();
3343
}

src/Dap.Shared/DebugAdapterRequestRouter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ internal class DebugAdapterRequestRouter : RequestRouterBase<IHandlerDescriptor>
1212
private readonly DebugAdapterHandlerCollection _collection;
1313

1414
public DebugAdapterRequestRouter(
15-
DebugAdapterHandlerCollection collection, ISerializer serializer, IServiceScopeFactory serviceScopeFactory, ILogger<DebugAdapterRequestRouter> logger
15+
DebugAdapterHandlerCollection collection, ISerializer serializer, IServiceScopeFactory serviceScopeFactory, ILogger<DebugAdapterRequestRouter> logger,
16+
IActivityTracingStrategy? activityTracingStrategy = null
1617
)
17-
: base(serializer, serviceScopeFactory, logger) =>
18+
: base(serializer, serviceScopeFactory, logger, activityTracingStrategy) =>
1819
_collection = collection;
1920

2021
public IDisposable Add(IJsonRpcHandler handler) => _collection.Add(handler);
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
using Newtonsoft.Json;
2+
13
namespace OmniSharp.Extensions.JsonRpc.Client
24
{
3-
public class OutgoingNotification
5+
public class OutgoingNotification : ITraceData
46
{
57
public string Method { get; set; } = null!;
68

79
public object? Params { get; set; }
10+
11+
/// <summary>
12+
/// Gets or sets the data for the <see href="https://www.w3.org/TR/trace-context/">W3C Trace Context</see> <c>traceparent</c> value.
13+
/// </summary>
14+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
15+
public string? TraceParent { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the data for the <see href="https://www.w3.org/TR/trace-context/">W3C Trace Context</see> <c>tracestate</c> value.
19+
/// </summary>
20+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
21+
public string? TraceState { get; set; }
822
}
923
}

src/JsonRpc/Client/OutgoingRequest.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33
namespace OmniSharp.Extensions.JsonRpc.Client
44
{
5-
public class OutgoingRequest
5+
public class OutgoingRequest : ITraceData
66
{
77
public object? Id { get; set; }
88

99
public string? Method { get; set; }
1010

1111
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
1212
public object? Params { get; set; }
13+
14+
/// <summary>
15+
/// Gets or sets the data for the <see href="https://www.w3.org/TR/trace-context/">W3C Trace Context</see> <c>traceparent</c> value.
16+
/// </summary>
17+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
18+
public string? TraceParent { get; set; }
19+
20+
/// <summary>
21+
/// Gets or sets the data for the <see href="https://www.w3.org/TR/trace-context/">W3C Trace Context</see> <c>tracestate</c> value.
22+
/// </summary>
23+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
24+
public string? TraceState { get; set; }
1325
}
1426
}

0 commit comments

Comments
 (0)