Skip to content

Commit

Permalink
Activity is non cls compliant - workaround the warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas committed Jul 29, 2019
1 parent 64a2390 commit c76aaa7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public static class W3CActivityExtensions
/// <param name="activity">Activity to generate W3C context on.</param>
/// <returns>The same Activity for chaining.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
#pragma warning disable CS3002 // Return type is not CLS-compliant
public static Activity GenerateW3CContext(this Activity activity)
#pragma warning restore CS3002 // Return type is not CLS-compliant
#pragma warning restore CS3001 // Argument type is not CLS-compliant
{
activity.SetVersion(W3CConstants.DefaultVersion);
activity.SetSampled(W3CConstants.TraceFlagRecordedAndNotRequested);
Expand All @@ -48,7 +52,9 @@ public static Activity GenerateW3CContext(this Activity activity)
/// <param name="activity">Activity to check.</param>
/// <returns>True if Activity has W3C properties, false otherwise.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
public static bool IsW3CActivity(this Activity activity)
#pragma warning restore CS3001 // Argument type is not CLS-compliant
{
return activity != null && activity.Tags.Any(t => t.Key == W3CConstants.TraceIdTag);
}
Expand All @@ -59,7 +65,11 @@ public static bool IsW3CActivity(this Activity activity)
/// <param name="activity">Activity to update W3C context on.</param>
/// <returns>The same Activity for chaining.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
#pragma warning disable CS3002 // Return type is not CLS-compliant
public static Activity UpdateContextOnActivity(this Activity activity)
#pragma warning restore CS3002 // Return type is not CLS-compliant
#pragma warning restore CS3001 // Argument type is not CLS-compliant
{
if (activity == null || activity.Tags.Any(t => t.Key == W3CConstants.TraceIdTag))
{
Expand All @@ -79,7 +89,9 @@ public static Activity UpdateContextOnActivity(this Activity activity)
/// <param name="activity">Activity to read W3C context from.</param>
/// <returns>traceparent header value.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
public static string GetTraceparent(this Activity activity)
#pragma warning restore CS3001 // Argument type is not CLS-compliant
{
string version = null, traceId = null, spanId = null, sampled = null;
foreach (var tag in activity.Tags)
Expand Down Expand Up @@ -115,7 +127,9 @@ public static string GetTraceparent(this Activity activity)
/// <param name="activity">Activity to set W3C context on.</param>
/// <param name="value">Valid traceparent header like 00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
public static void SetTraceparent(this Activity activity, string value)
#pragma warning restore CS3001 // Argument type is not CLS-compliant
{
if (activity.IsW3CActivity())
{
Expand Down Expand Up @@ -175,7 +189,9 @@ public static void SetTraceparent(this Activity activity, string value)
/// <param name="activity">Activity to get tracestate from.</param>
/// <returns>tracestate header value.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
public static string GetTracestate(this Activity activity) =>
#pragma warning restore CS3001 // Argument type is not CLS-compliant
activity.Tags.FirstOrDefault(t => t.Key == W3CConstants.TracestateTag).Value;

/// <summary>
Expand All @@ -184,7 +200,9 @@ public static string GetTracestate(this Activity activity) =>
/// <param name="activity">Activity to set tracestate on.</param>
/// <param name="value">tracestate header value.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
public static void SetTracestate(this Activity activity, string value) =>
#pragma warning restore CS3001 // Argument type is not CLS-compliant
activity.AddTag(W3CConstants.TracestateTag, value);

/// <summary>
Expand All @@ -194,7 +212,9 @@ public static void SetTracestate(this Activity activity, string value) =>
/// <param name="activity">Activity to get traceId from.</param>
/// <returns>TraceId value or null if it does not exist.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
public static string GetTraceId(this Activity activity) => activity.Tags.FirstOrDefault(t => t.Key == W3CConstants.TraceIdTag).Value;
#pragma warning restore CS3001 // Argument type is not CLS-compliant

/// <summary>
/// Gets SpanId from the Activity.
Expand All @@ -203,7 +223,9 @@ public static void SetTracestate(this Activity activity, string value) =>
/// <param name="activity">Activity to get spanId from.</param>
/// <returns>SpanId value or null if it does not exist.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
public static string GetSpanId(this Activity activity) => activity.Tags.FirstOrDefault(t => t.Key == W3CConstants.SpanIdTag).Value;
#pragma warning restore CS3001 // Argument type is not CLS-compliant

/// <summary>
/// Gets ParentSpanId from the Activity.
Expand All @@ -212,7 +234,9 @@ public static void SetTracestate(this Activity activity, string value) =>
/// <param name="activity">Activity to get ParentSpanId from.</param>
/// <returns>ParentSpanId value or null if it does not exist.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
public static string GetParentSpanId(this Activity activity) => activity.Tags.FirstOrDefault(t => t.Key == W3CConstants.ParentSpanIdTag).Value;
#pragma warning restore CS3001 // Argument type is not CLS-compliant

/// <summary>
/// Sets Activity W3C context on the telemetry.
Expand All @@ -223,7 +247,9 @@ public static void SetTracestate(this Activity activity, string value) =>
[EditorBrowsable(EditorBrowsableState.Never)]
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification =
"This method has different code for Net45/NetCore")]
#pragma warning disable CS3001 // Argument type is not CLS-compliant
public static void UpdateTelemetry(this Activity activity, ITelemetry telemetry, bool forceUpdate)
#pragma warning restore CS3001 // Argument type is not CLS-compliant
{
if (activity == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public static void StopOperation<T>(this TelemetryClient telemetryClient, IOpera
operation.Dispose();
}

#pragma warning disable CS3001 // Argument type is not CLS-compliant
/// <summary>
/// Creates an operation object with a respective telemetry item using <see cref="Activity"/> instance that holds tracing context.
/// </summary>
Expand Down Expand Up @@ -218,6 +219,7 @@ public static void StopOperation<T>(this TelemetryClient telemetryClient, IOpera
/// <param name="activity">Activity to get tracing context and telemetry properties from.</param>
/// <returns>Operation item object with a new telemetry item having current start time and timestamp.</returns>
public static IOperationHolder<T> StartOperation<T>(this TelemetryClient telemetryClient, Activity activity) where T : OperationTelemetry, new()
#pragma warning restore CS3001 // Argument type is not CLS-compliant
{
if (telemetryClient == null)
{
Expand Down

0 comments on commit c76aaa7

Please sign in to comment.