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
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ internal SpanCodeOrigin(DebuggerSettings settings)

internal void SetCodeOriginForExitSpan(Span? span)
{
if (ShouldSkipExitSpan())
if (span?.Tags is WebTags { SpanKind: SpanKinds.Server })
{
// entry span
Log.Debug("SetCodeOriginForExitSpan: Skipping server entry span {SpanID}. Code origin will be added later. Service {ServiceName}, Resource: {ResourceName}, Operation: {OperationName}", span.SpanId, span.ServiceName, span.ResourceName, span.OperationName);
return;
}

if (span == null)
if (ShouldSkipExitSpan())
{
Log.Debug("Can not add code origin for exit span when span is null");
return;
}

if (span.Tags is WebTags { SpanKind: SpanKinds.Server })
if (span == null)
{
// entry span
Log.Debug("Skipping span {SpanID}, we will add entry span code origin for it later. Resource: {ResourceName}, Operation: {OperationName}", span.SpanId, span.ResourceName, span.OperationName);
Log.Debug("Can not add code origin for exit span when span is null");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,13 @@ private void OnRoutingEndpointMatched(object arg)
}
else if (routeEndpoint?.RequestDelegate?.TryDuckCast<Target>(out var target) == true && target is { Handler: { } handler })
{
Log.Debug("RouteEndpoint?.RequestDelegate?.Method is null. Extracting code origin from RouteEndpoint.RequestDelegate.Target.Handler {Handler}", handler);
CurrentCodeOrigin?.SetCodeOriginForEntrySpan(rootSpan, handler.Target?.GetType(), handler.Method);
}
else
{
Log.Debug("RouteEndpoint?.RequestDelegate?.Method is null and could not extract handler from RouteEndpoint.RequestDelegate.Target");
}
}

if (isFirstExecution)
Expand Down Expand Up @@ -633,9 +638,16 @@ private void OnMvcBeforeAction(object arg)

if (span is not null)
{
if (isCodeOriginEnabled && TryGetTypeAndMethod(typedArg, out var type, out var method))
if (isCodeOriginEnabled)
{
CurrentCodeOrigin?.SetCodeOriginForEntrySpan(rootSpan, type, method);
if (TryGetTypeAndMethod(typedArg, out var type, out var method))
{
CurrentCodeOrigin?.SetCodeOriginForEntrySpan(rootSpan, type, method);
}
else
{
Log.Debug("Could not extract type and method from {ActionDescriptor}", typedArg.ActionDescriptor?.DisplayName);
}
}

CurrentSecurity.CheckPathParamsFromAction(httpContext, span, typedArg.ActionDescriptor?.Parameters, typedArg.RouteData.Values);
Expand Down Expand Up @@ -663,14 +675,22 @@ private bool TryGetTypeAndMethod(BeforeActionStruct beforeAction, out Type type,
{
foreach (var part in compiledPageActionDescriptor.HandlerMethods)
{
if (part.TryDuckCast(out HandlerMethodDescriptorStruct methodDesc)
&& string.Equals(methodDesc.HttpMethod, beforeAction.HttpContext.Request.Method, StringComparison.OrdinalIgnoreCase))
if (part.TryDuckCast(out HandlerMethodDescriptorStruct methodDesc))
{
type = compiledPageActionDescriptor.HandlerTypeInfo;
method = methodDesc.MethodInfo;
return true;
if (string.Equals(methodDesc.HttpMethod, beforeAction.HttpContext.Request.Method, StringComparison.OrdinalIgnoreCase))
{
type = compiledPageActionDescriptor.HandlerTypeInfo;
method = methodDesc.MethodInfo;
return true;
}
else
{
Log.Debug("Ignoring handler method {Method} for HTTP method {HttpMethod}", methodDesc.MethodInfo.Name, methodDesc.HttpMethod);
}
}
}

Log.Debug("No matching handler method found for HTTP method {HttpMethod}", beforeAction.HttpContext.Request.Method);
}
}
catch (Exception e)
Expand Down
Loading