Skip to content

Commit 41c44f1

Browse files
committed
Fixup doc and style warnings.
1 parent 14afe63 commit 41c44f1

File tree

4 files changed

+188
-122
lines changed

4 files changed

+188
-122
lines changed

src/Shared/Grpc/Tracing/DiagnosticActivityExtensions.cs

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
// NOTE: Modified from https://github.com/Azure/durabletask/blob/main/src/DurableTask.Core/Tracing/DiagnosticActivityExtensions.cs
5-
64
using System.Diagnostics;
75
using System.Linq.Expressions;
86
using System.Reflection;
97

8+
// NOTE: Modified from https://github.com/Azure/durabletask/blob/main/src/DurableTask.Core/Tracing/DiagnosticActivityExtensions.cs
109
namespace Microsoft.DurableTask.Tracing;
1110

1211
/// <summary>
13-
/// Replica from System.Diagnostics.DiagnosticSource >= 6.0.0
12+
/// Replica from System.Diagnostics.DiagnosticSource >= 6.0.0.
1413
/// </summary>
1514
enum ActivityStatusCode
1615
{
16+
/// <summary>
17+
/// The default value indicating the status code is not initialized.
18+
/// </summary>
1719
Unset = 0,
18-
OK = 1,
20+
21+
/// <summary>
22+
/// Indicates the operation has been validated and completed successfully.
23+
/// </summary>
24+
Ok = 1,
25+
26+
/// <summary>
27+
/// Indicates an error was encountered during the operation.
28+
/// </summary>
1929
Error = 2,
2030
}
2131

@@ -24,39 +34,56 @@ enum ActivityStatusCode
2434
/// </summary>
2535
static class DiagnosticActivityExtensions
2636
{
27-
static readonly Action<Activity, string> s_setSpanId;
28-
static readonly Action<Activity, ActivityStatusCode, string> s_setStatus;
37+
static readonly Action<Activity, string> SetSpanIdMethod;
38+
static readonly Action<Activity, ActivityStatusCode, string> SetStatusMethod;
2939

3040
static DiagnosticActivityExtensions()
3141
{
3242
BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
33-
s_setSpanId = (typeof(Activity).GetField("_spanId", flags) ?? throw new InvalidOperationException("The field Activity._spanId was not found.")).CreateSetter<Activity, string>();
34-
s_setStatus = CreateSetStatus();
43+
SetSpanIdMethod = (typeof(Activity).GetField("_spanId", flags) ?? throw new InvalidOperationException("The field Activity._spanId was not found.")).CreateSetter<Activity, string>();
44+
SetStatusMethod = CreateSetStatus();
3545
}
3646

47+
/// <summary>
48+
/// Explicitly sets the span ID for the given activity.
49+
/// </summary>
50+
/// <param name="activity">The activity on which to set the span ID.</param>
51+
/// <param name="spanId">The span ID to set.</param>
3752
public static void SetSpanId(this Activity activity, string spanId)
38-
=> s_setSpanId(activity, spanId);
53+
=> SetSpanIdMethod(activity, spanId);
3954

55+
/// <summary>
56+
/// Explicitly sets the status code and description for the given activity.
57+
/// </summary>
58+
/// <param name="activity">The activity on which to set the span ID.</param>
59+
/// <param name="status">The status to set.</param>
60+
/// <param name="description">The description to set.</param>
4061
public static void SetStatus(this Activity activity, ActivityStatusCode status, string description)
41-
=> s_setStatus(activity, status, description);
62+
=> SetStatusMethod(activity, status, description);
4263

4364
static Action<Activity, ActivityStatusCode, string> CreateSetStatus()
4465
{
45-
MethodInfo method = typeof(Activity).GetMethod("SetStatus");
66+
MethodInfo? method = typeof(Activity).GetMethod("SetStatus");
67+
4668
if (method is null)
4769
{
48-
return (activity, status, description) => {
70+
return (activity, status, description) =>
71+
{
72+
#pragma warning disable CA1510
4973
if (activity is null)
5074
{
5175
throw new ArgumentNullException(nameof(activity));
5276
}
53-
string str = status switch
77+
#pragma warning restore CA1510
78+
79+
string? str = status switch
5480
{
5581
ActivityStatusCode.Unset => "UNSET",
56-
ActivityStatusCode.OK => "OK",
82+
ActivityStatusCode.Ok => "OK",
5783
ActivityStatusCode.Error => "ERROR",
5884
_ => null,
5985
};
86+
6087
activity.SetTag("otel.status_code", str);
6188
activity.SetTag("otel.status_description", description);
6289
};

src/Shared/Grpc/Tracing/FieldInfoExtensionMethods.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
// NOTE: Modified from https://github.com/Azure/durabletask/blob/main/src/DurableTask.Core/Tracing/FieldInfoExtensionMethods.cs
5-
64
using System.Linq.Expressions;
75
using System.Reflection;
86

7+
// NOTE: Modified from https://github.com/Azure/durabletask/blob/main/src/DurableTask.Core/Tracing/FieldInfoExtensionMethods.cs
98
namespace Microsoft.DurableTask.Tracing;
109

1110
/// <summary>
@@ -23,10 +22,17 @@ static class FieldInfoExtensionMethods
2322
/// <returns>A re-usable action to set the field.</returns>
2423
internal static Action<TTarget, TValue> CreateSetter<TTarget, TValue>(this FieldInfo fieldInfo)
2524
{
25+
#pragma warning disable CA1510
2626
if (fieldInfo == null)
2727
{
2828
throw new ArgumentNullException(nameof(fieldInfo));
2929
}
30+
#pragma warning restore CA1510
31+
32+
if (fieldInfo.DeclaringType is null)
33+
{
34+
throw new ArgumentException("FieldInfo.DeclaringType cannot be null.", nameof(fieldInfo));
35+
}
3036

3137
ParameterExpression targetExp = Expression.Parameter(typeof(TTarget), "target");
3238
Expression source = targetExp;
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
// NOTE: Modified from https://github.com/Azure/durabletask/blob/main/src/DurableTask.Core/Tracing/TraceActivityConstants.cs
5-
4+
// Modified from https://github.com/Azure/durabletask/blob/main/src/DurableTask.Core/Tracing/TraceActivityConstants.cs.
65
namespace Microsoft.DurableTask.Tracing;
76

7+
/// <summary>
8+
/// Constants for trace activity names used in Durable Task Framework.
9+
/// </summary>
810
class TraceActivityConstants
911
{
12+
/// <summary>
13+
/// The name of the activity that represents orchestration operations.
14+
/// </summary>
1015
public const string Orchestration = "orchestration";
16+
17+
/// <summary>
18+
/// The name of the activity that represents activity operations.
19+
/// </summary>
1120
public const string Activity = "activity";
21+
22+
/// <summary>
23+
/// The name of the activity that represents entity operations.
24+
/// </summary>
1225
public const string Event = "event";
26+
27+
/// <summary>
28+
/// The name of the activity that represents timer operations.
29+
/// </summary>
1330
public const string Timer = "timer";
1431

32+
/// <summary>
33+
/// The name of the activity that represents an operation to create an orchestration.
34+
/// </summary>
1535
public const string CreateOrchestration = "create_orchestration";
36+
37+
/// <summary>
38+
/// The name of the activity that represents an operation to raise an event.
39+
/// </summary>
1640
public const string OrchestrationEvent = "orchestration_event";
1741
}

0 commit comments

Comments
 (0)