Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlClient Instrumentation to leverage native Activity Status. #3751

Merged
merged 11 commits into from
Oct 12, 2022
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

* Use `Activity.Status` and `Activity.StatusDescription` properties instead of
`OpenTelemetry.Trace.Status` and `OpenTelemetry.Trace.Status.Description`
respectively to set activity status.
([#3118](https://github.com/open-telemetry/opentelemetry-dotnet/issues/3118))
([#3751](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3751))

## 1.0.0-rc9.7

Released 2022-Sep-29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,7 @@ public override void OnEventWritten(string name, object payload)
return;
}

try
{
if (activity.IsAllDataRequested)
{
activity.SetStatus(Status.Unset);
}
}
finally
{
activity.Stop();
}
activity.Stop();
}

break;
Expand All @@ -180,7 +170,7 @@ public override void OnEventWritten(string name, object payload)
{
if (this.exceptionFetcher.TryFetch(payload, out Exception exception) && exception != null)
{
activity.SetStatus(Status.Error.WithDescription(exception.Message));
activity.SetStatus(ActivityStatusCode.Error, exception.Message);

if (this.options.RecordException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,14 @@ private void OnEndExecute(EventWrittenEventArgs eventData)
if (activity.IsAllDataRequested)
{
int compositeState = (int)eventData.Payload[1];
if ((compositeState & 0b001) == 0b001)
{
activity.SetStatus(Status.Unset);
}
else if ((compositeState & 0b010) == 0b010)
if ((compositeState & 0b010) == 0b010)
Yun-Ting marked this conversation as resolved.
Show resolved Hide resolved
{
var errorText = $"SqlExceptionNumber {eventData.Payload[2]} thrown.";
activity.SetStatus(Status.Error.WithDescription(errorText));
activity.SetStatus(ActivityStatusCode.Error, errorText);
}
else
{
activity.SetStatus(Status.Error.WithDescription("Unknown Sql failure."));
activity.SetStatus(ActivityStatusCode.Error, "Unknown Sql failure.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ private static void VerifyActivityData(

if (!isFailure)
{
Assert.Equal(Status.Unset, activity.GetStatus());
Assert.Equal(ActivityStatusCode.Unset, activity.Status);
}
else
{
var status = activity.GetStatus();
Assert.Equal(Status.Error.StatusCode, status.StatusCode);
Assert.NotNull(status.Description);
Assert.Equal(ActivityStatusCode.Error, activity.Status);
Assert.NotNull(activity.StatusDescription);

if (recordException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,12 @@ private static void VerifyActivityData(

if (!isFailure)
{
Assert.Equal(Status.Unset, activity.GetStatus());
Assert.Equal(ActivityStatusCode.Unset, activity.Status);
}
else
{
var status = activity.GetStatus();
Assert.Equal(Status.Error.StatusCode, status.StatusCode);
Assert.NotNull(status.Description);
Assert.Equal(ActivityStatusCode.Error, activity.Status);
Assert.NotNull(activity.StatusDescription);
}
}

Expand Down