Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Telemetry/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.Configuration;
using System.Globalization;
using Microsoft.Data.SqlClient;

namespace Microsoft.Azure.WebJobs.Extensions.Sql.Telemetry
{
Expand Down Expand Up @@ -120,6 +122,7 @@ public void TrackException(TelemetryErrorName errorName, Exception exception, ID
this._logger.LogInformation($"Sending exception event: {exception.Message}");
properties ??= new Dictionary<string, string>();
properties.Add(TelemetryPropertyName.ErrorName.ToString(), errorName.ToString());
properties.Add(TelemetryPropertyName.ErrorCode.ToString(), ExtractErrorCode(exception));
//continue task in existing parallel thread
this._trackEventTask = this._trackEventTask.ContinueWith(
x => this.TrackExceptionTask(exception, properties, measurements)
Expand Down Expand Up @@ -276,6 +279,18 @@ private Dictionary<string, string> GetEventProperties(IDictionary<string, string
return this._commonProperties;
}
}

/// <summary>
/// Extract error code from known exception types
/// </summary>
private static string ExtractErrorCode(Exception ex)
{
if (ex != null && ex is SqlException)
{
return (ex as SqlException).Number.ToString(CultureInfo.InvariantCulture);
}
return string.Empty;
}
}

/// <summary>
Expand Down Expand Up @@ -330,7 +345,8 @@ public enum TelemetryPropertyName
HasIdentityColumn,
QueryType,
ServerVersion,
Type
Type,
ErrorCode
}

/// <summary>
Expand Down