Skip to content
Merged

aot #5340

Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions AOT-Sample/AOT-Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<!-- Additional AOT and trim settings -->
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<IsAotCompatible>true</IsAotCompatible>

<!-- More detailed trim warnings -->
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<TrimmerSingleWarn>true</TrimmerSingleWarn>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>

<!-- ILC flags for more detailed output -->
Expand All @@ -45,9 +45,8 @@
<IlcGenerateDgmlFile>true</IlcGenerateDgmlFile>
</PropertyGroup>

<ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.HybridRow" Version="1.1.0-preview3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4-beta1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Microsoft.Azure.Cosmos.Resource.CosmosExceptions
using System.Text.Json;
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Documents;
using Newtonsoft.Json.Linq;

internal static class CosmosExceptionFactory
{
Expand Down Expand Up @@ -166,21 +165,23 @@ internal static (Error, string) GetErrorFromStream(

try
{
JObject errorObj = JObject.Parse(errorContent);
Error error = JsonSerializer.Deserialize<Error>(errorContent, CosmosSerializerContext.Default.Error);
if (error != null)
{
StringBuilder message = new StringBuilder();
foreach (var err in errorObj)
{
message
.Append(Environment.NewLine)
.Append(err.Key)
.Append(" : ")
.Append(err.Value);
}
message.Append(Environment.NewLine);
// Error format is not consistent across modes
StringBuilder message = new StringBuilder();
using (JsonDocument errorDoc = JsonDocument.Parse(errorContent))
{
foreach (JsonProperty err in errorDoc.RootElement.EnumerateObject())
{
message
.Append(Environment.NewLine)
.Append(err.Name)
.Append(" : ")
.Append(err.Value.ToString());
}
}
message.Append(Environment.NewLine);
// Error format is not consistent across modes
return (error, message.ToString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Microsoft.Azure.Cosmos.Tracing.TraceData
using System.Globalization;
using Microsoft.Azure.Cosmos.Json;
using Microsoft.Azure.Cosmos.Telemetry;
using System.Text.Json;
using System.Buffers;

internal sealed class ClientConfigurationTraceDatum : TraceDatum
{
Expand All @@ -19,9 +21,9 @@ public ClientConfigurationTraceDatum(CosmosClientContext cosmosClientContext, Da
cosmosClientContext.ClientOptions.RequestTimeout,
cosmosClientContext.ClientOptions.WebProxy,
cosmosClientContext.ClientOptions.HttpClientFactory);

#if !COSMOS_GW_AOT
this.RntbdConnectionConfig = cosmosClientContext.DocumentClient.RecordTcpSettings(this);
this.RntbdConnectionConfig = cosmosClientContext.DocumentClient.RecordTcpSettings(this);
#endif

this.OtherConnectionConfig = new OtherConnectionConfig(cosmosClientContext.ClientOptions.LimitToEndpoint,
Expand All @@ -43,9 +45,9 @@ public ClientConfigurationTraceDatum(CosmosClientContext cosmosClientContext, Da
public DateTime ClientCreatedDateTimeUtc { get; }

public GatewayConnectionConfig GatewayConnectionConfig { get; }

#if !COSMOS_GW_AOT
public RntbdConnectionConfig RntbdConnectionConfig { get; }
public RntbdConnectionConfig RntbdConnectionConfig { get; }
#endif

public OtherConnectionConfig OtherConnectionConfig { get; }
Expand Down Expand Up @@ -96,51 +98,40 @@ internal override void Accept(ITraceDatumVisitor traceDatumVisitor)

private ReadOnlyMemory<byte> GetSerializedDatum()
{
IJsonWriter jsonTextWriter = JsonWriter.Create(JsonSerializationFormat.Text);
jsonTextWriter.WriteObjectStart();

jsonTextWriter.WriteFieldName("Client Created Time Utc");
jsonTextWriter.WriteStringValue(this.ClientCreatedDateTimeUtc.ToString("o", CultureInfo.InvariantCulture));
jsonTextWriter.WriteFieldName("MachineId");
jsonTextWriter.WriteStringValue(this.cachedMachineId);
if (this.cachedVMRegion != null)
var buffer = new ArrayBufferWriter<byte>();
using (var writer = new Utf8JsonWriter(buffer))
{
jsonTextWriter.WriteFieldName("VM Region");
jsonTextWriter.WriteStringValue(this.cachedVMRegion);
}
jsonTextWriter.WriteFieldName("NumberOfClientsCreated");
jsonTextWriter.WriteNumberValue(this.cachedNumberOfClientCreated);
jsonTextWriter.WriteFieldName("NumberOfActiveClients");
jsonTextWriter.WriteNumberValue(this.cachedNumberOfActiveClient);
jsonTextWriter.WriteFieldName("ConnectionMode");
jsonTextWriter.WriteStringValue(this.ConnectionMode.ToString());
jsonTextWriter.WriteFieldName("User Agent");
jsonTextWriter.WriteStringValue(this.cachedUserAgentString);

jsonTextWriter.WriteFieldName("ConnectionConfig");
jsonTextWriter.WriteObjectStart();

jsonTextWriter.WriteFieldName("gw");
jsonTextWriter.WriteStringValue(this.GatewayConnectionConfig.ToString());

#if !COSMOS_GW_AOT
jsonTextWriter.WriteFieldName("rntbd");
jsonTextWriter.WriteStringValue(this.RntbdConnectionConfig.ToString());
#endif
writer.WriteStartObject();

writer.WriteString("Client Created Time Utc", this.ClientCreatedDateTimeUtc.ToString("o", CultureInfo.InvariantCulture));
writer.WriteString("MachineId", this.cachedMachineId);
if (this.cachedVMRegion != null)
{
writer.WriteString("VM Region", this.cachedVMRegion);
}
writer.WriteNumber("NumberOfClientsCreated", this.cachedNumberOfClientCreated);
writer.WriteNumber("NumberOfActiveClients", this.cachedNumberOfActiveClient);
writer.WriteString("ConnectionMode", this.ConnectionMode.ToString());
writer.WriteString("User Agent", this.cachedUserAgentString);

writer.WritePropertyName("ConnectionConfig");
writer.WriteStartObject();

jsonTextWriter.WriteFieldName("other");
jsonTextWriter.WriteStringValue(this.OtherConnectionConfig.ToString());
writer.WriteString("gw", this.GatewayConnectionConfig.ToString());
#if !COSMOS_GW_AOT
writer.WriteString("rntbd", this.RntbdConnectionConfig.ToString());
#endif
writer.WriteString("other", this.OtherConnectionConfig.ToString());

jsonTextWriter.WriteObjectEnd();
writer.WriteEndObject();

jsonTextWriter.WriteFieldName("ConsistencyConfig");
jsonTextWriter.WriteStringValue(this.ConsistencyConfig.ToString());
jsonTextWriter.WriteFieldName("ProcessorCount");
jsonTextWriter.WriteNumberValue(this.ProcessorCount);
writer.WriteString("ConsistencyConfig", this.ConsistencyConfig.ToString());
writer.WriteNumber("ProcessorCount", this.ProcessorCount);

jsonTextWriter.WriteObjectEnd();
writer.WriteEndObject();
}

return jsonTextWriter.GetResult();
return buffer.WrittenMemory;
}
}
}
14 changes: 14 additions & 0 deletions Microsoft.Azure.Cosmos/src/direct/Azure.Core/DiagnosticScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ public DiagnosticActivity(string operationName) : base(operationName)
private class ActivityAdapter : IDisposable
{
private readonly ActivitySource? _activitySource;
#if !COSMOS_GW_AOT
private readonly DiagnosticSource _diagnosticSource;
#endif
private readonly string _activityName;
private readonly System.Diagnostics.ActivityKind _kind;
private readonly object? _diagnosticSourceArgs;
Expand All @@ -193,7 +195,9 @@ private class ActivityAdapter : IDisposable
public ActivityAdapter(ActivitySource? activitySource, DiagnosticSource diagnosticSource, string activityName, System.Diagnostics.ActivityKind kind, object? diagnosticSourceArgs)
{
_activitySource = activitySource;
#if !COSMOS_GW_AOT
_diagnosticSource = diagnosticSource;
#endif
_activityName = activityName;
_kind = kind;
_diagnosticSourceArgs = diagnosticSourceArgs;
Expand Down Expand Up @@ -283,6 +287,9 @@ public void AddLink(string traceparent, string? tracestate, IDictionary<string,
}
else
{
return null;

#if !COSMOS_GW_AOT
if (!_diagnosticSource.IsEnabled(_activityName, _diagnosticSourceArgs))
{
return null;
Expand Down Expand Up @@ -337,6 +344,7 @@ public void AddLink(string traceparent, string? tracestate, IDictionary<string,
}

_currentActivity.Start();
#endif
}

WriteStartEvent();
Expand All @@ -352,7 +360,9 @@ public void AddLink(string traceparent, string? tracestate, IDictionary<string,
// [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "The values being passed into Write have the commonly used properties being preserved with DynamicDependency on the ActivityAdapter.Start() method, or the responsibility is on the user of this struct since the struct constructor is marked with RequiresUnreferencedCode.")]
private void WriteStartEvent()
{
#if !COSMOS_GW_AOT
_diagnosticSource.Write(_activityName + ".Start", _diagnosticSourceArgs ?? _currentActivity);
#endif
}

public void SetDisplayName(string displayName)
Expand Down Expand Up @@ -386,7 +396,9 @@ public void SetStartTime(DateTime startTime)
{
if (exception != null)
{
#if !COSMOS_GW_AOT
_diagnosticSource?.Write(_activityName + ".Exception", exception);
#endif
}

if (errorCode == null && exception != null)
Expand Down Expand Up @@ -435,7 +447,9 @@ public void Dispose()
if (activity.Duration == TimeSpan.Zero)
activity.SetEndTime(DateTime.UtcNow);

#if !COSMOS_GW_AOT
_diagnosticSource.Write(_activityName + ".Stop", _diagnosticSourceArgs);
#endif

activity.Dispose();

Expand Down
4 changes: 4 additions & 0 deletions Microsoft.Azure.Cosmos/src/direct/Dispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,11 @@ await this.connection.WriteRequestAsync(
TransportErrorCode.TransportNegotiationTimeout,
args.CommonArguments.UserPayload)))
{
#if COSMOS_GW_AOT
Error error = new();
#else
Error error = Resource.LoadFrom<Error>(errorResponseStream, null);
#endif

DocumentClientException exception = new DocumentClientException(
string.Format(CultureInfo.CurrentUICulture,
Expand Down
60 changes: 10 additions & 50 deletions Microsoft.Azure.Cosmos/src/direct/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//------------------------------------------------------------
namespace Microsoft.Azure.Documents
{
using Newtonsoft.Json;
using System.Text.Json.Serialization;

/// <summary>
/// Encapsulates error related details in the Azure Cosmos DB service.
Expand All @@ -13,7 +13,7 @@ namespace Microsoft.Azure.Documents
#else
public
#endif
class Error : Resource
class Error : PlainResource
{
/// <summary>
/// Initializes a new instance of the <see cref="T:Microsoft.Azure.Documents.Error"/> class for the Azure Cosmos DB service.
Expand All @@ -27,60 +27,20 @@ public Error()
/// Gets or sets the textual description of error code in the Azure Cosmos DB service.
/// </summary>
/// <value>The textual description of error code.</value>
[JsonProperty(PropertyName = Constants.Properties.Code)]
public string Code
{
get
{
return base.GetValue<string>(Constants.Properties.Code);
}
set
{
base.SetValue(Constants.Properties.Code, value);
}
}
[JsonPropertyName(Constants.Properties.Code)]
public string Code { get; set; }

/// <summary>
/// Gets or sets the error message in the Azure Cosmos DB service.
/// </summary>
/// <value>The error message.</value>
[JsonProperty(PropertyName = Constants.Properties.Message)]
public string Message
{
get
{
return base.GetValue<string>(Constants.Properties.Message);
}
set
{
base.SetValue(Constants.Properties.Message, value);
}
}
[JsonPropertyName(Constants.Properties.Message)]
public string Message { get; set; }

[JsonProperty(PropertyName = Constants.Properties.ErrorDetails)]
internal string ErrorDetails //Debug Only.
{
get
{
return base.GetValue<string>(Constants.Properties.ErrorDetails);
}
set
{
base.SetValue(Constants.Properties.ErrorDetails, value);
}
}
[JsonPropertyName(Constants.Properties.ErrorDetails)]
internal string ErrorDetails { get; set; }

[JsonProperty(PropertyName = Constants.Properties.AdditionalErrorInfo)]
internal string AdditionalErrorInfo
{
get
{
return base.GetValue<string>(Constants.Properties.AdditionalErrorInfo);
}
set
{
base.SetValue(Constants.Properties.AdditionalErrorInfo, value);
}
}
[JsonPropertyName(Constants.Properties.AdditionalErrorInfo)]
internal string AdditionalErrorInfo { get; set; }
}
}