Skip to content

Commit b3c43b1

Browse files
Niall LangleyNJLangley
authored andcommitted
Updated logging to push exceptions to Application Insights exceptions itemType. This means with sampling turned on requests and exceptions always get logged.
1 parent 26dba9e commit b3c43b1

File tree

4 files changed

+10
-25
lines changed

4 files changed

+10
-25
lines changed

DataPipelineTools.Functions/DataLake/DataLakeConfigFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public DataLakeGetItemsConfig GetItemsConfig (HttpRequest req)
6666
int.TryParse(req.Query[LimitParam] != StringValues.Empty ? (string)req.Query[LimitParam] : data?.orderByDesc, out limit);
6767

6868
string directory = req.Query[DirectoryParam] != StringValues.Empty || data?.directory == null ? (string)req.Query[DirectoryParam] : data?.directory;
69-
config.Directory = directory?.TrimStart('/');
69+
config.Directory = string.IsNullOrWhiteSpace(directory?.TrimStart('/')) ? "/" : directory?.TrimStart('/');
70+
7071
config.IgnoreDirectoryCase = ignoreDirectoryCase;
7172
config.Recursive = recursive;
7273
config.OrderByColumn = req.Query[OrderByColumnParam] != StringValues.Empty ? (string)req.Query[OrderByColumnParam] : data?.orderBy;

DataPipelineTools.Functions/DataLake/DataLakeFunctions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public async Task<IActionResult> DataLakeGetItems(
4343
if (string.IsNullOrWhiteSpace(dataLakeConfig.AccountUri))
4444
throw new ArgumentException($"Parameter 'accountUri' with value '{dataLakeConfig.AccountUri}' not found. Check the URI is correct.");
4545

46-
if (getItemsConfig.Directory == null)
47-
throw new ArgumentException($"Parameter 'directory' is required.");
46+
//if (getItemsConfig.Directory == null)
47+
// throw new ArgumentException($"Parameter 'directory' is required.");
4848

4949
var client = _clientFactory.GetDataLakeClient(dataLakeConfig);
5050
var controller = _serviceFactory.CreateDataLakeService(client);
@@ -63,7 +63,7 @@ public async Task<IActionResult> DataLakeGetItems(
6363
}
6464
catch (Exception ex)
6565
{
66-
_logger.LogError(ex.ToString());
66+
_logger.LogError(ex, ex.Message); // The simple message goes in the trace, but the full exception details are in the exception logging in Application Insights
6767
return new BadRequestObjectResult("An error occurred, see the Azure Function logs for more details");
6868
}
6969
}
@@ -111,7 +111,7 @@ public async Task<IActionResult> DataLakeCheckPathCase(
111111
}
112112
catch (Exception ex)
113113
{
114-
_logger.LogError(ex.ToString());
114+
_logger.LogError(ex, ex.Message); // The simple message goes in the trace, but the full exception details are in the exception logging in Application Insights
115115
return new BadRequestObjectResult("An error occurred, see the Azure Function logs for more details");
116116
}
117117
}

DataPipelineTools.Functions/host.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"logLevel": {
66
"default": "Error",
77
"Host.Results": "Information",
8-
"Function.DataLakeGetItems": "Information",
9-
"Function.DataLakeCheckPathCase": "Information"
8+
"Function": "Information",
9+
"SqlCollaborative.Azure.DataPipelineTools": "Information"
1010
},
1111
"applicationInsights": {
1212
"samplingSettings": {

DataPipelineTools/DataLake/DataLakeService.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,12 @@ public async Task<JObject> GetItemsAsync(DataLakeConfig dataLakeConfig, DataLake
106106
{
107107
// Check the directory exists. If multiple directories match (ie different casing), it will throw an error, as we don't know
108108
// which one we wanted the files from.
109-
/* TODO: When the path does not exist, this is throwing an exception:
110-
Azure.RequestFailedException: Service request failed.
111-
Status: 400 (The requested URI does not represent any resource on the server.)
112-
ErrorCode: InvalidUri
113-
114-
at Azure.Storage.Blobs.BlobRestClient.Blob.GetPropertiesAsync_CreateResponse(ClientDiagnostics clientDiagnostics, Response response)
115-
at Azure.Storage.Blobs.BlobRestClient.Blob.GetPropertiesAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri resourceUri, String version, String snapshot, String versionId, Nullable`1 timeout, String leaseId, String encryptionKey, String encryptionKeySha256, Nullable`1 encryptionAlgorithm, Nullable`1 ifModifiedSince, Nullable`1 ifUnmodifiedSince, Nullable`1 ifMatch, Nullable`1 ifNoneMatch, String ifTags, String requestId, Boolean async, String operationName, CancellationToken cancellationToken)
116-
at Azure.Storage.Blobs.Specialized.BlobBaseClient.GetPropertiesInternal(BlobRequestConditions conditions, Boolean async, CancellationToken cancellationToken, String operationName)
117-
at Azure.Storage.Blobs.Specialized.BlobBaseClient.ExistsInternal(Boolean async, CancellationToken cancellationToken)
118-
at Azure.Storage.Blobs.Specialized.BlobBaseClient.Exists(CancellationToken cancellationToken)
119-
at Azure.Storage.Files.DataLake.DataLakePathClient.Exists(CancellationToken cancellationToken)
120-
at SqlCollaborative.Azure.DataPipelineTools.DataLake.DataLakeService.GetItemsAsync(DataLakeConfig dataLakeConfig, DataLakeGetItemsConfig getItemsConfig)
121-
in /home/runner/work/AzureDataPipelineTools/AzureDataPipelineTools/DataPipelineTools/DataLake/DataLakeService.cs:line 109
122-
at SqlCollaborative.Azure.DataPipelineTools.Functions.DataLake.DataLakeFunctions.DataLakeGetItems(HttpRequest req)
123-
in /home/runner/work/AzureDataPipelineTools/AzureDataPipelineTools/DataPipelineTools.Functions/DataLake/DataLakeFunctions.cs:line 54
124-
*/
125109
var directory = getItemsConfig.IgnoreDirectoryCase ?
126110
await CheckPathAsync(getItemsConfig.Directory, true) :
127111
getItemsConfig.Directory;
128112

129-
130-
if (!_client.GetDirectoryClient(directory).Exists())
113+
// Only check the path if it is not the root. Checking is the root exists throws, and if the container is valid the root will always be valid
114+
if (directory != "/" && !await _client.GetDirectoryClient(directory).ExistsAsync() )
131115
throw new DirectoryNotFoundException($"Directory '{directory} could not be found'");
132116

133117
var paths = _client

0 commit comments

Comments
 (0)