Skip to content

Commit cedb8bd

Browse files
authored
Merge pull request #22 from digma-ai/target_netstandard
change framework target to netstandard
2 parents c465afd + 508849f commit cedb8bd

12 files changed

+53
-52
lines changed

src/OpenTelemetry.Instrumentation.Digma/Diagnostic/HttpEndpointDiagnosticObserver.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System.Diagnostics;
22
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Http.Features;
34
using Microsoft.AspNetCore.Mvc.Controllers;
45
using Microsoft.Extensions.DependencyInjection;
56

67
namespace OpenTelemetry.Instrumentation.Digma.Diagnostic;
7-
88
public static class HttpDiagnosticObserverExtensions
99
{
1010
public static IServiceCollection UseDigmaHttpDiagnosticObserver(this IServiceCollection serviceCollection)
@@ -30,16 +30,16 @@ public void OnNext(KeyValuePair<string, object?> pair)
3030
if (pair.Key != "Microsoft.AspNetCore.Routing.EndpointMatched")
3131
return;
3232

33-
var context = (HttpContext) pair.Value;
34-
var endpoint = context?.GetEndpoint();
35-
var descriptor = endpoint?.Metadata.GetMetadata<ControllerActionDescriptor>();
36-
if (descriptor == null)
37-
return;
33+
var httpContext = (HttpContext) pair.Value;
34+
if(httpContext == null)return;
35+
var endpointFeature = httpContext.Features?.Get<IEndpointFeature>();
36+
var descriptor = endpointFeature?.Endpoint.Metadata.GetMetadata<ControllerActionDescriptor>();
37+
if (descriptor == null) return;
3838
SpanUtils.AddCommonTags(descriptor.ControllerTypeInfo, descriptor.MethodInfo, Activity.Current);
3939
}
4040

4141
public bool CanHandle(string diagnosticListener)
4242
{
4343
return diagnosticListener == "Microsoft.AspNetCore";
4444
}
45-
}
45+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace OpenTelemetry.Instrumentation.Digma.Diagnostic;
2-
3-
public interface IDigmaDiagnosticObserver:IObserver<KeyValuePair<string, object?>>
2+
public interface IDigmaDiagnosticObserver : IObserver<KeyValuePair<string, object?>>
43
{
54
bool CanHandle(string diagnosticListener);
65
}

src/OpenTelemetry.Instrumentation.Digma/DigmaConfigurationOptions.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,20 @@
1414
// limitations under the License.
1515
// </copyright>
1616

17-
namespace OpenTelemetry.Instrumentation.Digma
17+
namespace OpenTelemetry.Instrumentation.Digma;
18+
public class DigmaConfigurationOptions
1819
{
19-
public class DigmaConfigurationOptions
20-
{
21-
private const string DEFAULT_COMMIT_ENV_VAR = "DEPLOYMENT_COMMIT_ID";
22-
private const string DEFAULT_DEPLOYMENT_ENV_ENV_VAR = "DEPLOYMENT_ENV";
23-
private const string DEFAULT_DIGMA_ENV_ENV_VAR = "DIGMA_ENV";
20+
private const string DEFAULT_COMMIT_ENV_VAR = "DEPLOYMENT_COMMIT_ID";
21+
private const string DEFAULT_DEPLOYMENT_ENV_ENV_VAR = "DEPLOYMENT_ENV";
22+
private const string DEFAULT_DIGMA_ENV_ENV_VAR = "DIGMA_ENV";
2423

25-
public string? NamespaceRoot { get; set; } = null;
26-
public string? Environment { get; set; } = null;
27-
public string CommitIdEnvVariable { get; set; } = DEFAULT_COMMIT_ENV_VAR;
28-
[Obsolete($"Please use {nameof(DigmaEnvironmentEnvVariable)}")]
29-
public string EnvironmentEnvVariable { get; set; } = DEFAULT_DEPLOYMENT_ENV_ENV_VAR;
30-
public string DigmaEnvironmentEnvVariable { get; set; } = DEFAULT_DIGMA_ENV_ENV_VAR;
31-
public string? CommitId { get; set; } = null;
32-
public string? SpanMappingPattern { get; set; } = "";
33-
public string? SpanMappingReplacement { get; set; } = "";
34-
}
35-
}
24+
public string? NamespaceRoot { get; set; } = null;
25+
public string? Environment { get; set; } = null;
26+
public string CommitIdEnvVariable { get; set; } = DEFAULT_COMMIT_ENV_VAR;
27+
[Obsolete("Please use DigmaEnvironmentEnvVariable")]
28+
public string EnvironmentEnvVariable { get; set; } = DEFAULT_DEPLOYMENT_ENV_ENV_VAR;
29+
public string DigmaEnvironmentEnvVariable { get; set; } = DEFAULT_DIGMA_ENV_ENV_VAR;
30+
public string? CommitId { get; set; } = null;
31+
public string? SpanMappingPattern { get; set; } = "";
32+
public string? SpanMappingReplacement { get; set; } = "";
33+
}

src/OpenTelemetry.Instrumentation.Digma/DigmaInstrumentationHelperExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace OpenTelemetry.Instrumentation.Digma;
2323

2424
public static class DigmaInstrumentationHelperExtensions
2525
{
26-
private static readonly HashSet<string> IgnoreNamespaces = new() { "Microsoft", "System" };
26+
private static readonly HashSet<string> IgnoreNamespaces = new HashSet<string>() {"Microsoft", "System"};
2727

2828
public static ResourceBuilder AddDigmaAttributes(this ResourceBuilder builder,
2929
Action<DigmaConfigurationOptions>? configure = null)
@@ -63,10 +63,12 @@ public static ResourceBuilder AddDigmaAttributes(this ResourceBuilder builder,
6363
{
6464
options.Environment = Environment.GetEnvironmentVariable(options.DigmaEnvironmentEnvVariable) ?? "";
6565
}
66+
6667
if (string.IsNullOrWhiteSpace(options.Environment))
6768
{
6869
options.Environment = Environment.GetEnvironmentVariable(options.EnvironmentEnvVariable) ?? "";
6970
}
71+
7072
if (string.IsNullOrWhiteSpace(options.Environment))
7173
{
7274
options.Environment = hostName + "[local]";
@@ -84,4 +86,4 @@ public static ResourceBuilder AddDigmaAttributes(this ResourceBuilder builder,
8486
});
8587
return builder;
8688
}
87-
}
89+
}

src/OpenTelemetry.Instrumentation.Digma/EndpointMonitoring.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ public Task StopAsync(CancellationToken cancellationToken)
2424
_observer.Dispose();
2525
return Task.CompletedTask;
2626
}
27-
28-
27+
28+
2929
private class DiagnosticSubscriber : IObserver<DiagnosticListener>, IDisposable
3030
{
3131
private readonly IEnumerable<IDigmaDiagnosticObserver> _diagnosticObservers;
3232
private readonly List<IDisposable> _subscriptions;
33+
3334
public DiagnosticSubscriber(IEnumerable<IDigmaDiagnosticObserver> diagnosticObservers)
3435
{
3536
_diagnosticObservers = diagnosticObservers;
@@ -53,7 +54,7 @@ public void OnError(Exception error)
5354
public void OnNext(DiagnosticListener value)
5455
{
5556
var diagnosticObserver = _diagnosticObservers.FirstOrDefault(o => o.CanHandle(value.Name));
56-
if(diagnosticObserver is null) return;
57+
if (diagnosticObserver == null) return;
5758
var subscription = value.Subscribe(diagnosticObserver);
5859
_subscriptions.Add(subscription);
5960
}
@@ -71,4 +72,3 @@ public void Dispose()
7172
}
7273

7374

74-

src/OpenTelemetry.Instrumentation.Digma/Helpers/Attributes/ActivitiesAttributesAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ private static void EnsureAttributeSyntax(string[] attributes, string[][] attrib
6262
" The correct syntax is \"key:value\"");
6363
}
6464
}
65-
}
65+
}

src/OpenTelemetry.Instrumentation.Digma/Helpers/Attributes/NoActivityAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ namespace OpenTelemetry.Instrumentation.Digma.Helpers.Attributes;
33
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
44
public class NoActivityAttribute : Attribute
55
{
6-
}
6+
}

src/OpenTelemetry.Instrumentation.Digma/Helpers/Attributes/TraceActivityAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ public TraceActivityAttribute(string? name = null, bool recordExceptions = true)
1111
Name = name;
1212
RecordExceptions = recordExceptions;
1313
}
14-
}
14+
}

src/OpenTelemetry.Instrumentation.Digma/Helpers/SpanNamingSchema.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Reflection;
22

33
namespace OpenTelemetry.Instrumentation.Digma.Helpers;
4-
54
public interface IActivityNamingSchema
65
{
76
public string GetSpanName(Type classType, MethodInfo method);
@@ -29,4 +28,4 @@ public string GetSpanName(Type classType, MethodInfo method)
2928
{
3029
return $"{classType.Name}.{method.Name}";
3130
}
32-
}
31+
}

src/OpenTelemetry.Instrumentation.Digma/Helpers/TracingDecorator.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using OpenTelemetry.Trace;
55

66
namespace OpenTelemetry.Instrumentation.Digma.Helpers;
7-
87
public class TraceDecorator<TDecorated> : DispatchProxy where TDecorated : class
98
{
109
private ActivitySource _activity;
@@ -23,23 +22,25 @@ public static TDecorated Create(TDecorated decorated, IActivityNamingSchema? act
2322
bool decorateAllMethods = true)
2423
{
2524
object proxy = Create<TDecorated, TraceDecorator<TDecorated>>()!;
26-
((TraceDecorator<TDecorated>)proxy!).SetParameters(decorated, activityNamingSchema, decorateAllMethods);
25+
((TraceDecorator<TDecorated>) proxy!).SetParameters(decorated, activityNamingSchema, decorateAllMethods);
2726

28-
return (TDecorated)proxy;
27+
return (TDecorated) proxy;
2928
}
3029

31-
private void SetParameters(TDecorated decorated, IActivityNamingSchema? spanNamingSchema, bool decorateAllMethods)
30+
private void SetParameters(TDecorated decorated, IActivityNamingSchema? spanNamingSchema,
31+
bool decorateAllMethods)
3232
{
3333
_decorated = decorated;
34-
_activity = new(_decorated!.GetType().FullName!);
34+
_activity = new ActivitySource(_decorated!.GetType().FullName!);
3535
_decorateAllMethods = decorateAllMethods;
3636
if (spanNamingSchema != null)
3737
{
3838
_namingSchema = spanNamingSchema;
3939
}
4040
}
4141

42-
private object? InvokeDecoratedExecution(Activity? activity, MethodInfo? targetMethod, object?[]? args, bool? recordException)
42+
private object? InvokeDecoratedExecution(Activity? activity, MethodInfo? targetMethod, object?[]? args,
43+
bool? recordException)
4344
{
4445
object? result;
4546
try
@@ -48,13 +49,13 @@ private void SetParameters(TDecorated decorated, IActivityNamingSchema? spanNami
4849
}
4950
catch (Exception e)
5051
{
51-
if(recordException ?? true)
52+
if (recordException ?? true)
5253
activity?.RecordException(e);
53-
54+
5455
activity?.Dispose();
5556
throw;
5657
}
57-
58+
5859
if (result is Task resultTask)
5960
{
6061
resultTask.ContinueWith(task =>
@@ -66,7 +67,7 @@ private void SetParameters(TDecorated decorated, IActivityNamingSchema? spanNami
6667

6768
activity?.Dispose();
6869
}, TaskContinuationOptions.AttachedToParent | TaskContinuationOptions.ExecuteSynchronously);
69-
70+
7071
return result;
7172
}
7273

@@ -82,7 +83,7 @@ private void SetParameters(TDecorated decorated, IActivityNamingSchema? spanNami
8283
if (noActivityAttribute == null && (_decorateAllMethods || activityAttribute != null))
8384
{
8485
var classType = _decorated!.GetType();
85-
86+
8687
var defaultSpanName = _namingSchema.GetSpanName(classType, targetMethod);
8788
var activity = _activity.StartActivity(activityAttribute?.Name ?? defaultSpanName);
8889

@@ -97,7 +98,8 @@ private void SetParameters(TDecorated decorated, IActivityNamingSchema? spanNami
9798

9899
private void InjectAttributes(MethodInfo targetMethod, Activity? activity)
99100
{
100-
var methodActivityAttributes = targetMethod.GetCustomAttribute<ActivitiesAttributesAttribute>(inherit: false);
101+
var methodActivityAttributes =
102+
targetMethod.GetCustomAttribute<ActivitiesAttributesAttribute>(inherit: false);
101103
var classActivityAttributes =
102104
_decorated.GetType().GetCustomAttribute<ActivitiesAttributesAttribute>(inherit: false);
103105

@@ -117,4 +119,4 @@ private void InjectAttributes(MethodInfo targetMethod, Activity? activity)
117119
}
118120
}
119121
}
120-
}
122+
}

0 commit comments

Comments
 (0)