Родитель
b1e5d51c58
Коммит
53a4422d01
|
@ -900,6 +900,41 @@
|
|||
{
|
||||
module.Initialize(this.configuration);
|
||||
|
||||
Activity httpActivity = new Activity("Azure.SomeClient.Http.Request")
|
||||
.AddTag("http.method", "PATCH")
|
||||
.AddTag("http.url", "http://host/path?query#fragment")
|
||||
.AddTag("otel.status_code", "ERROR");
|
||||
|
||||
var payload = new HttpRequestMessage();
|
||||
listener.StartActivity(httpActivity, payload);
|
||||
httpActivity.AddTag("http.status_code", "503");
|
||||
|
||||
listener.StopActivity(httpActivity, payload);
|
||||
|
||||
var telemetry = this.sentItems.Last() as DependencyTelemetry;
|
||||
|
||||
Assert.IsNotNull(telemetry);
|
||||
Assert.AreEqual("PATCH /path", telemetry.Name);
|
||||
Assert.AreEqual("host", telemetry.Target);
|
||||
Assert.AreEqual("http://host/path?query#fragment", telemetry.Data);
|
||||
Assert.AreEqual("503", telemetry.ResultCode);
|
||||
Assert.AreEqual("Http", telemetry.Type);
|
||||
Assert.IsFalse(telemetry.Success.Value);
|
||||
|
||||
Assert.IsNull(telemetry.Context.Operation.ParentId);
|
||||
Assert.AreEqual(httpActivity.TraceId.ToHexString(), telemetry.Context.Operation.Id);
|
||||
Assert.AreEqual(httpActivity.SpanId.ToHexString(), telemetry.Id);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AzureClientSpansAreCollectedForHttpNotSuccessResponseAndNoStatusCode()
|
||||
{
|
||||
using (var listener = new DiagnosticListener("Azure.SomeClient"))
|
||||
using (var module = new DependencyTrackingTelemetryModule())
|
||||
{
|
||||
module.Initialize(this.configuration);
|
||||
|
||||
Activity httpActivity = new Activity("Azure.SomeClient.Http.Request")
|
||||
.AddTag("http.method", "PATCH")
|
||||
.AddTag("http.url", "http://host/path?query#fragment");
|
||||
|
@ -926,6 +961,30 @@
|
|||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AzureClientSpansAreCollectedAndHttpStatusCodeIsIgnoredWithExplicitStatusCode()
|
||||
{
|
||||
using (var listener = new DiagnosticListener("Azure.SomeClient"))
|
||||
using (var module = new DependencyTrackingTelemetryModule())
|
||||
{
|
||||
module.Initialize(this.configuration);
|
||||
|
||||
Activity httpActivity = new Activity("Azure.SomeClient.Http.Request")
|
||||
.AddTag("http.method", "PATCH")
|
||||
.AddTag("http.url", "http://host/path?query#fragment")
|
||||
.AddTag("otel.status_code", "UNSET");
|
||||
|
||||
var payload = new HttpRequestMessage();
|
||||
listener.StartActivity(httpActivity, payload);
|
||||
httpActivity.AddTag("http.status_code", "503");
|
||||
|
||||
listener.StopActivity(httpActivity, payload);
|
||||
|
||||
var telemetry = this.sentItems.Last() as DependencyTelemetry;
|
||||
Assert.IsTrue(telemetry.Success.Value);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AzureClientSpansAreCollectedForHttpException()
|
||||
{
|
||||
|
|
|
@ -253,6 +253,8 @@
|
|||
string method = null;
|
||||
string url = null;
|
||||
string status = null;
|
||||
bool failed = false;
|
||||
bool hasExplicitStatus = false;
|
||||
|
||||
foreach (var tag in activity.Tags)
|
||||
{
|
||||
|
@ -276,6 +278,11 @@
|
|||
{
|
||||
status = tag.Value;
|
||||
}
|
||||
else if (tag.Key == "otel.status_code")
|
||||
{
|
||||
hasExplicitStatus = true;
|
||||
failed = string.Equals(tag.Value, "ERROR", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: could be optimized to avoid full URI parsing and allocation
|
||||
|
@ -290,11 +297,18 @@
|
|||
dependency.Target = DependencyTargetNameHelper.GetDependencyTargetName(parsedUrl);
|
||||
dependency.ResultCode = status;
|
||||
|
||||
if (!hasExplicitStatus)
|
||||
{
|
||||
if (int.TryParse(status, out var statusCode))
|
||||
{
|
||||
dependency.Success = (statusCode > 0) && (statusCode < 400);
|
||||
}
|
||||
}
|
||||
else if (failed)
|
||||
{
|
||||
dependency.Success = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetEventHubsProperties(Activity activity, OperationTelemetry telemetry)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче