Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public void OnCapturedParameters(
string methodName,
string methodModuleName,
string? methodDeclaringTypeName,
ResolvedParameterInfo[] parameters
ResolvedParameterInfo[] parameters,
uint methodToken,
Guid moduleVersionId
)
{
Activity? currentActivity = Activity.Current;
Expand All @@ -76,6 +78,8 @@ ResolvedParameterInfo[] parameters
_eventSource.CapturedParameterStart(
requestId,
captureId,
methodToken,
moduleVersionId,
currentActivity?.Id ?? string.Empty,
currentActivity?.IdFormat ?? ActivityIdFormat.Unknown,
currentThreadId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ bool isParameterTypeByRef
public void CapturedParameterStart(
Guid RequestId,
Guid CaptureId,
uint methodToken,
Guid moduleVersionId,
string activityId,
ActivityIdFormat activityIdFormat,
int managedThreadId,
Expand All @@ -126,7 +128,7 @@ public void CapturedParameterStart(
string methodDeclaringTypeName
)
{
Span<EventData> data = stackalloc EventData[8];
Span<EventData> data = stackalloc EventData[10];

using PinnedData pinnedActivityId = PinnedData.Create(activityId);
using PinnedData pinnedMethodName = PinnedData.Create(methodName);
Expand All @@ -135,6 +137,8 @@ string methodDeclaringTypeName

SetValue(ref data[ParameterCapturingEvents.CapturedParametersStartPayloads.RequestId], RequestId);
SetValue(ref data[ParameterCapturingEvents.CapturedParametersStartPayloads.CaptureId], CaptureId);
SetValue(ref data[ParameterCapturingEvents.CapturedParametersStartPayloads.MethodToken], methodToken);
SetValue(ref data[ParameterCapturingEvents.CapturedParametersStartPayloads.ModuleVersionId], moduleVersionId);
SetValue(ref data[ParameterCapturingEvents.CapturedParametersStartPayloads.ActivityId], pinnedActivityId);
SetValue(ref data[ParameterCapturingEvents.CapturedParametersStartPayloads.ActivityIdFormat], activityIdFormat);
SetValue(ref data[ParameterCapturingEvents.CapturedParametersStartPayloads.ThreadId], managedThreadId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public bool EnterProbe(ulong uniquifier, object[] args)
instrumentedMethod.MethodSignature.MethodName,
instrumentedMethod.MethodSignature.ModuleName,
instrumentedMethod.MethodSignature.TypeName,
resolvedArgs);
resolvedArgs,
Convert.ToUInt32(instrumentedMethod.MethodSignature.MethodToken),
instrumentedMethod.MethodSignature.ModuleVersionId
);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static class Names

public string MethodName { get; } = GetMethodName(method);

public int MethodToken { get; } = GetMethodToken(method);

public Guid ModuleVersionId { get; } = GetModuleVersionId(method);

public IReadOnlyList<ParameterSignature> Parameters { get; } = EmitParameters(method);

private static string GetMethodName(MethodInfo method)
Expand All @@ -58,6 +62,30 @@ private static string GetMethodName(MethodInfo method)
return builder.ToString();
}

private static int GetMethodToken(MethodInfo method)
{
try
{
return method.MetadataToken;
}
catch
{
return 0;
}
}

private static Guid GetModuleVersionId(MethodInfo method)
{
try
{
return method.Module.ModuleVersionId;
}
catch
{
return Guid.Empty;
}
}

private static string? EmitTypeName(Type? type)
{
// For a generic declaring type, trim the arity information and replace it with the known generic argument names.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ public sealed class CapturedMethod

[JsonPropertyName("parameters")]
public IList<CapturedParameter> Parameters { get; init; } = [];

[JsonPropertyName("methodToken")]
public required uint MethodToken { get; init; }

[JsonPropertyName("moduleVersionId")]
public required Guid ModuleVersionId { get; init; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public async Task WriteParameters(ICapturedParameters parameters, CancellationTo
TypeModuleName = param.TypeModuleName,
Value = param.Value,
EvalFailReason = param.EvalFailReason
}).ToList()
}).ToList(),
MethodToken = capture.MethodToken,
ModuleVersionId = capture.ModuleVersionId
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ internal interface ICapturedParameters

string MethodName { get; }

public uint MethodToken { get; }

public Guid ModuleVersionId { get; }

IReadOnlyList<ParameterInfo> Parameters { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -155,8 +156,16 @@ await RunTestCaseCore(
Assert.NotNull(capturedMethods);
CapturedMethod actualMethod = Assert.Single(capturedMethods);

// This corresponds with the type used in expectedCapturedMethod
MethodInfo methodInfo = typeof(SampleMethods.StaticTestMethodSignatures).GetMethod(
expectedCapturedMethod.MethodName);
Assert.NotNull(methodInfo);

Assert.Equal(expectedCapturedMethod.TypeName, actualMethod.TypeName);
Assert.Equal(expectedCapturedMethod.MethodName, actualMethod.MethodName);
Assert.Equal(expectedCapturedMethod.ModuleName, actualMethod.ModuleName);
Assert.Equal(methodInfo.Module.ModuleVersionId, actualMethod.ModuleVersionId);
Assert.Equal(methodInfo.MetadataToken, (int)actualMethod.MethodToken);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed class CapturedParameters : ICapturedParameters
{
private readonly List<ParameterInfo> _parameters = [];

public CapturedParameters(string? activityId, ActivityIdFormat activityIdFormat, int threadId, DateTime capturedDateTime, string methodName, string methodTypeName, string methodModuleName)
public CapturedParameters(string? activityId, ActivityIdFormat activityIdFormat, int threadId, DateTime capturedDateTime, string methodName, string methodTypeName, string methodModuleName, uint methodToken, Guid moduleVersionId)
{
ActivityId = activityId;
ActivityIdFormat = activityIdFormat;
Expand All @@ -23,6 +23,8 @@ public CapturedParameters(string? activityId, ActivityIdFormat activityIdFormat,
TypeName = methodTypeName;
ModuleName = methodModuleName;
CapturedDateTime = capturedDateTime;
MethodToken = methodToken;
ModuleVersionId = moduleVersionId;
}

public void AddParameter(ParameterInfo parameter)
Expand All @@ -45,5 +47,9 @@ public void AddParameter(ParameterInfo parameter)
public IReadOnlyList<ParameterInfo> Parameters => _parameters;

public DateTime CapturedDateTime { get; }

public uint MethodToken { get; }

public Guid ModuleVersionId { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ internal sealed class CapturedParametersBuilder
{
private readonly Dictionary<Guid, CapturedParameters> _capturedParameters = new();

public bool TryStartNewCaptureResponse(Guid captureId, string? activityId, ActivityIdFormat activityIdFormat, int threadId, DateTime capturedDateTime, string methodName, string methodTypeName, string methodModuleName)
public bool TryStartNewCaptureResponse(Guid captureId, string? activityId, ActivityIdFormat activityIdFormat, int threadId, DateTime capturedDateTime, string methodName, string methodTypeName, string methodModuleName, uint methodToken, Guid moduleVersionId)
{
return _capturedParameters.TryAdd(captureId, new CapturedParameters(activityId, activityIdFormat, threadId, capturedDateTime, methodName, methodTypeName, methodModuleName));
return _capturedParameters.TryAdd(captureId, new CapturedParameters(activityId, activityIdFormat, threadId, capturedDateTime, methodName, methodTypeName, methodModuleName, methodToken, moduleVersionId));
}

public bool TryFinalizeParameters(Guid captureId, [NotNullWhen(true)] out ICapturedParameters? capturedParameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ private void Callback(TraceEvent traceEvent)
{
Guid requestId = traceEvent.GetPayload<Guid>(ParameterCapturingEvents.CapturedParametersStartPayloads.RequestId);
Guid captureId = traceEvent.GetPayload<Guid>(ParameterCapturingEvents.CapturedParametersStartPayloads.CaptureId);
uint methodToken = traceEvent.GetPayload<uint>(ParameterCapturingEvents.CapturedParametersStartPayloads.MethodToken);
Guid moduleVersionId = traceEvent.GetPayload<Guid>(ParameterCapturingEvents.CapturedParametersStartPayloads.ModuleVersionId);
string activityId = traceEvent.GetPayload<string>(ParameterCapturingEvents.CapturedParametersStartPayloads.ActivityId);
ActivityIdFormat activityIdFormat = traceEvent.GetPayload<ActivityIdFormat>(ParameterCapturingEvents.CapturedParametersStartPayloads.ActivityIdFormat);
int threadId = traceEvent.GetPayload<int>(ParameterCapturingEvents.CapturedParametersStartPayloads.ThreadId);
Expand All @@ -124,7 +126,9 @@ private void Callback(TraceEvent traceEvent)
traceEvent.TimeStamp,
methodName: methodName,
methodTypeName: methodDeclaringTypeName,
methodModuleName: methodModuleName);
methodModuleName: methodModuleName,
methodToken: methodToken,
moduleVersionId: moduleVersionId);

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ public static class CapturedParametersStartPayloads
{
public const int RequestId = 0;
public const int CaptureId = 1;
public const int ActivityId = 2;
public const int ActivityIdFormat = 3;
public const int ThreadId = 4;
public const int MethodName = 5;
public const int MethodModuleName = 6;
public const int MethodDeclaringTypeName = 7;
public const int MethodToken = 2;
public const int ModuleVersionId = 3;
public const int ActivityId = 4;
public const int ActivityIdFormat = 5;
public const int ThreadId = 6;
public const int MethodName = 7;
public const int MethodModuleName = 8;
public const int MethodDeclaringTypeName = 9;
}

public static class CapturedParametersStopPayloads
Expand Down
Loading