in src/ServiceProfiler.EventPipe.Otel/Azure.Monitor.OpenTelemetry.Profiler.Core/TraceUploaderProxy.cs [43:126]
public async Task<UploadContextModel?> UploadAsync(
DateTimeOffset sessionId,
string traceFilePath,
string metadataFilePath,
string? sampleFilePath,
string? namedPipeName,
string roleName,
string triggerType,
CancellationToken cancellationToken,
string? uploaderFullPath = null)
{
if (string.IsNullOrEmpty(traceFilePath))
{
_logger.LogError("Trace file path is not specified.");
return null;
}
if (!_fileService.Exists(traceFilePath))
{
_logger.LogError("Trace file {0} can't be found.", traceFilePath);
return null;
}
if (string.IsNullOrEmpty(sampleFilePath) && string.IsNullOrEmpty(namedPipeName))
{
throw new InvalidOperationException($"'{nameof(sampleFilePath)}' and '{nameof(namedPipeName)}' cannot be null or empty at the same time");
}
if (_userConfiguration.UploadMode == UploadMode.Never)
{
_logger.LogInformation("Skip upload according to user configuration.");
return null;
}
// Locate uploader.
uploaderFullPath ??= _uploaderPathProvider.GetUploaderFullPath();
if (string.IsNullOrEmpty(uploaderFullPath))
{
_logger.LogError("Trace Uploader is not provided or located.");
return null;
}
_logger.LogInformation("Uploader to be used: {uploaderPath}", uploaderFullPath);
// Upload is ready to go.
UploadContextModel uploadContextModel = new()
{
AIInstrumentationKey = _context.AppInsightsInstrumentationKey,
HostUrl = _context.StampFrontendEndpointUrl,
StampId = string.Empty,
SessionId = sessionId,
TraceFilePath = traceFilePath,
MetadataFilePath = metadataFilePath,
PreserveTraceFile = _userConfiguration.PreserveTraceFile,
SkipEndpointCertificateValidation = _userConfiguration.SkipEndpointCertificateValidation,
UploadMode = _userConfiguration.UploadMode,
SerializedSampleFilePath = sampleFilePath,
PipeName = namedPipeName,
RoleName = roleName,
TriggerType = triggerType,
Environment = _userConfiguration.UploaderEnvironment,
TraceFileFormat = TraceFileFormat.Nettrace,
};
// Validation Failed
string? message = _uploadContextValidator.Validate(uploadContextModel);
if (!string.IsNullOrEmpty(message))
{
_logger.LogError(message);
return null;
}
int exitCode = await CallUploadAsync(uploaderFullPath, uploadContextModel.ToString(), cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
{
// Upload Failed
_logger.LogError("Trace upload failed. Exit code: {exitCode}", exitCode);
return null;
}
// Upload succeeded.
return uploadContextModel;
}