Skip to content

Commit 470d83a

Browse files
authored
Merge pull request #129 from digma-ai/feature/anonymousfunc_activity
support:
2 parents 1f2303c + fc4f2e9 commit 470d83a

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

rider/Digma.Rider.Plugin/Digma.Rider/Discovery/CodeObjectsDiscoveryMethodProcessor.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Diagnostics.CodeAnalysis;
34
using Digma.Rider.Protocol;
45
using Digma.Rider.Util;
56
using JetBrains.ReSharper.Psi.CSharp.Tree;
67
using JetBrains.ReSharper.Psi.Tree;
8+
using JetBrains.ReSharper.Psi.VB.Tree;
79
using JetBrains.Util;
810
using static Digma.Rider.Logging.Logger;
911
using static JetBrains.Util.Logging.Logger;
12+
using IBlock = JetBrains.ReSharper.Psi.CSharp.Tree.IBlock;
13+
using ILambdaExpression = JetBrains.ReSharper.Psi.CSharp.Tree.ILambdaExpression;
14+
using ILocalVariableDeclaration = JetBrains.ReSharper.Psi.CSharp.Tree.ILocalVariableDeclaration;
1015

1116
namespace Digma.Rider.Discovery
1217
{
@@ -66,9 +71,13 @@ public override bool InteriorShouldBeProcessed(ITreeNode element)
6671
case IBlock block:
6772
case ICSharpStatement cSharpStatement:
6873
case IMultipleLocalVariableDeclaration multipleLocalVariableDeclaration:
74+
case ILocalVariableDeclaration localVariableDeclaration:
75+
case IExpressionInitializer expressionInitializer:
76+
case ILambdaExpression lambdaExpression:
77+
case ILocalFunctionDeclaration localFunctionDeclaration:
6978
return true;
7079
}
71-
80+
7281
return false;
7382
}
7483

@@ -82,7 +91,7 @@ public override void ProcessBeforeInterior(ITreeNode element)
8291
Log(Logger, "in '{0}' for method '{1}' in file '{2}'",
8392
element,
8493
_functionDeclaration, DiscoveryContext.PsiSourceFile.Name);
85-
var spanDiscovery = new SpanDiscovery(localVariableDeclaration);
94+
var spanDiscovery = new SpanDiscovery(localVariableDeclaration, _methodInfo.Name);
8695
if (spanDiscovery.InstLibrary == null || spanDiscovery.SpanName == null)
8796
{
8897
if (spanDiscovery.HasReferenceResolvingErrors)

rider/Digma.Rider.Plugin/Digma.Rider/Discovery/SpanDiscovery.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using JetBrains.Annotations;
2+
using JetBrains.ReSharper.Feature.Services.Html;
23
using JetBrains.ReSharper.Psi;
34
using JetBrains.ReSharper.Psi.CSharp.Tree;
45
using JetBrains.ReSharper.Psi.Resolve;
@@ -10,6 +11,7 @@ namespace Digma.Rider.Discovery
1011

1112
public class SpanDiscovery
1213
{
14+
private readonly string _methodName;
1315
private const string ActivitySourceClassName = "System.Diagnostics.ActivitySource";
1416
private const string StartActivityMethodName = "StartActivity";
1517

@@ -19,8 +21,9 @@ public class SpanDiscovery
1921
public bool HasReferenceResolvingErrors { get; private set; } = false;
2022

2123

22-
public SpanDiscovery([NotNull] ILocalVariableDeclaration localVariableDeclaration)
24+
public SpanDiscovery([NotNull] ILocalVariableDeclaration localVariableDeclaration , string methodName)
2325
{
26+
_methodName = methodName;
2427
var expressionInitializer = localVariableDeclaration.Children<IExpressionInitializer>().FirstNotNull();
2528
var value = expressionInitializer?.Value;
2629
if (value is IInvocationExpression expression)
@@ -48,15 +51,18 @@ private void DiscoverFromInvocationExpression([NotNull] IInvocationExpression in
4851
}
4952
}
5053

51-
//the arguments to Activity.StartActivity("the argument")
54+
/*
55+
* the arguments to Activity.StartActivity("the argument")
56+
* or Activity.StartActivity()
57+
*/
5258
private string DiscoverSpanNameFromInvocationArguments([NotNull] IArgumentList invocationExpressionArgumentList)
5359
{
5460
if (invocationExpressionArgumentList.Arguments.Count is 1 or 2)
5561
{
5662
return GetTextFromArgument(invocationExpressionArgumentList.Arguments[0]);
5763
}
5864

59-
return null;
65+
return invocationExpressionArgumentList.Arguments.Count == 0 ? _methodName : null;
6066
}
6167

6268
private string DiscoverInstrumentationLibraryFromInvokedExpression(

0 commit comments

Comments
 (0)