Skip to content

Commit

Permalink
added user agent (#2213)
Browse files Browse the repository at this point in the history
  • Loading branch information
bchong95 authored Feb 12, 2021
1 parent 648f2b0 commit f1074a2
Show file tree
Hide file tree
Showing 11 changed files with 562 additions and 17 deletions.
18 changes: 1 addition & 17 deletions Microsoft.Azure.Cosmos/src/Diagnostics/CosmosTraceDiagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ namespace Microsoft.Azure.Cosmos.Diagnostics

internal sealed class CosmosTraceDiagnostics : CosmosDiagnostics
{
private static readonly string userAgent = new UserAgentContainer().UserAgent;

public CosmosTraceDiagnostics(ITrace trace, string userAgent = null)
public CosmosTraceDiagnostics(ITrace trace)
{
if (trace == null)
{
throw new ArgumentNullException(nameof(trace));
}

this.UserAgent = userAgent ?? CosmosTraceDiagnostics.userAgent;

// Need to set to the root trace, since we don't know which layer of the stack the response message was returned from.
ITrace rootTrace = trace;
while (rootTrace.Parent != null)
Expand All @@ -34,8 +30,6 @@ public CosmosTraceDiagnostics(ITrace trace, string userAgent = null)

public ITrace Value { get; }

public string UserAgent { get; }

public override string ToString()
{
return this.ToJsonString();
Expand All @@ -55,17 +49,7 @@ private string ToJsonString()
private ReadOnlyMemory<byte> WriteTraceToJsonWriter(JsonSerializationFormat jsonSerializationFormat)
{
IJsonWriter jsonTextWriter = JsonWriter.Create(jsonSerializationFormat);

jsonTextWriter.WriteObjectStart();

jsonTextWriter.WriteFieldName("User Agent");
jsonTextWriter.WriteStringValue(this.UserAgent);

jsonTextWriter.WriteFieldName("Traces");
TraceWriter.WriteTrace(jsonTextWriter, this.Value);

jsonTextWriter.WriteObjectEnd();

return jsonTextWriter.GetResult();
}
}
Expand Down
3 changes: 3 additions & 0 deletions Microsoft.Azure.Cosmos/src/Handler/TransportHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ internal async Task<ResponseMessage> ProcessMessageAsync(
Tracing.TraceLevel.Info))
{
request.Trace = processMessageAsyncTrace;

processMessageAsyncTrace.AddDatum("User Agent", this.client.ClientContext.UserAgent);

DocumentServiceResponse response = request.OperationType == OperationType.Upsert
? await this.ProcessUpsertAsync(storeProxy, serviceRequest, cancellationToken)
: await storeProxy.ProcessMessageAsync(serviceRequest, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component 12:00:00:000 0.00 milliseconds
│ (
│ [User Agent]
│ Redacted To Not Change The Baselines From Run To Run
│ [Client Side Request Stats]
│ Redacted To Not Change The Baselines From Run To Run
│ )
Expand Down Expand Up @@ -139,6 +141,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"User Agent": "Redacted To Not Change The Baselines From Run To Run",
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run"
},
"children": []
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
└── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
└── Microsoft.Azure.Cosmos.GatewayStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component 12:00:00:000 0.00 milliseconds
(
[User Agent]
Redacted To Not Change The Baselines From Run To Run
[Client Side Request Stats]
Redacted To Not Change The Baselines From Run To Run
[PointOperationStatisticsTraceDatum]
Expand Down Expand Up @@ -101,6 +103,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"User Agent": "Redacted To Not Change The Baselines From Run To Run",
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"PointOperationStatisticsTraceDatum": "Redacted To Not Change The Baselines From Run To Run"
},
Expand Down Expand Up @@ -147,6 +150,8 @@
└── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
└── Microsoft.Azure.Cosmos.GatewayStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component 12:00:00:000 0.00 milliseconds
(
[User Agent]
Redacted To Not Change The Baselines From Run To Run
[Client Side Request Stats]
Redacted To Not Change The Baselines From Run To Run
[PointOperationStatisticsTraceDatum]
Expand Down Expand Up @@ -216,6 +221,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"User Agent": "Redacted To Not Change The Baselines From Run To Run",
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"PointOperationStatisticsTraceDatum": "Redacted To Not Change The Baselines From Run To Run"
},
Expand Down
Loading

0 comments on commit f1074a2

Please sign in to comment.