Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwesh Bankwar committed Nov 9, 2023
1 parent b1c8bd4 commit bea7bd5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ private static void HookOrProcessResult(HttpWebRequest request)
private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncCallback, Activity activity, object result, bool forceResponseCopy, HttpWebRequest request, long startTimestamp)
{
HttpStatusCode? httpStatusCode = null;
object errorType = null;
string errorType = null;

// Activity may be null if we are not tracing in these cases:
// 1. No listeners
Expand Down Expand Up @@ -461,7 +461,7 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC
if (SpanHelper.ResolveSpanStatusForHttpStatusCode(ActivityKind.Client, (int)httpStatusCode.Value) == ActivityStatusCode.Error)
{
// override the errorType to statusCode for failures.
errorType = TelemetryHelper.GetBoxedStatusCode(httpStatusCode.Value);
errorType = TelemetryHelper.GetStatusCodeString(httpStatusCode.Value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation;

internal static class TelemetryHelper
{
public static readonly object[] BoxedStatusCodes;
public static readonly (object, string)[] BoxedStatusCodes;

static TelemetryHelper()
{
BoxedStatusCodes = new object[500];
BoxedStatusCodes = new (object, string)[500];
for (int i = 0, c = 100; i < BoxedStatusCodes.Length; i++, c++)
{
BoxedStatusCodes[i] = c;
BoxedStatusCodes[i] = (c, c.ToString());
}
}

Expand All @@ -36,9 +36,20 @@ public static object GetBoxedStatusCode(HttpStatusCode statusCode)
int intStatusCode = (int)statusCode;
if (intStatusCode >= 100 && intStatusCode < 600)
{
return BoxedStatusCodes[intStatusCode - 100];
return BoxedStatusCodes[intStatusCode - 100].Item1;
}

return intStatusCode;
return statusCode;
}

public static string GetStatusCodeString(HttpStatusCode statusCode)
{
int intStatusCode = (int)statusCode;
if (intStatusCode >= 100 && intStatusCode < 600)
{
return BoxedStatusCodes[intStatusCode - 100].Item2;
}

return statusCode.ToString();
}
}

0 comments on commit bea7bd5

Please sign in to comment.