Skip to content

Commit

Permalink
copy error attrs from activity or generate for meter
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-hensley committed Nov 8, 2024
1 parent 7f0aba0 commit 765847a
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ internal sealed class SqlClientDiagnosticListener : ListenerHandler
SemanticConventions.AttributeDbSystem,
SemanticConventions.AttributeDbCollectionName,
SemanticConventions.AttributeDbNamespace,
SemanticConventions.AttributeDbResponseStatusCode,
SemanticConventions.AttributeDbOperationName,
SemanticConventions.AttributeErrorType,
SemanticConventions.AttributeServerPort,
SemanticConventions.AttributeServerAddress,
];
Expand Down Expand Up @@ -288,6 +290,19 @@ private void RecordDuration(Activity? activity, object? payload, bool hasError =
}
}
}

if (hasError)
{
if (this.exceptionFetcher.TryFetch(payload, out var exception) && exception != null)
{
tags.Add(SemanticConventions.AttributeErrorType, exception.GetType().FullName);

if (this.exceptionNumberFetcher.TryFetch(exception, out var exceptionNumber))
{
tags.Add(SemanticConventions.AttributeDbResponseStatusCode, exceptionNumber.ToString(CultureInfo.InvariantCulture));
}
}
}
}

var duration = activity?.Duration.TotalSeconds ?? this.CalculateDurationFromTimestamp();
Expand Down

0 comments on commit 765847a

Please sign in to comment.