Skip to content

Commit 8e82a1a

Browse files
authored
AI Integration: Adds cosmetic fixes (#3576)
* wip * status code int and internal and client kind activity * remove unused imports * update baselines * fix test * fixed baseline tests * fix tests * update base tetss Co-authored-by: Sourabh Jain <[email protected]>
1 parent 6632168 commit 8e82a1a

18 files changed

+1984
-1999
lines changed

Microsoft.Azure.Cosmos/src/Resource/CosmosExceptions/CosmosException.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ private string ToStringHelper(
289289
/// <param name="scope"></param>
290290
internal static void RecordOtelAttributes(CosmosException exception, DiagnosticScope scope)
291291
{
292-
scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, exception.StatusCode);
293-
scope.AddAttribute(OpenTelemetryAttributeKeys.SubStatusCode, exception.SubStatusCode);
292+
scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, (int)exception.StatusCode);
293+
scope.AddAttribute(OpenTelemetryAttributeKeys.SubStatusCode, (int)exception.SubStatusCode);
294294
scope.AddAttribute(OpenTelemetryAttributeKeys.RequestCharge, exception.RequestCharge);
295295
scope.AddAttribute(OpenTelemetryAttributeKeys.Region,
296296
ClientTelemetryHelper.GetContactedRegions(exception.Diagnostics?.GetContactedRegions()));

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryAttributeKeys.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal sealed class OpenTelemetryAttributeKeys
1919

2020
// Cosmos Db Specific
2121
public const string ClientId = "db.cosmosdb.client_id";
22-
public const string MachineId = "db.cosmosdb.hashed_machine_id";
22+
public const string MachineId = "db.cosmosdb.machine_id";
2323
public const string UserAgent = "db.cosmosdb.user_agent";
2424
public const string ConnectionMode = "db.cosmosdb.connection_mode";
2525
public const string OperationType = "db.cosmosdb.operation_type";

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryAttributes.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
namespace Microsoft.Azure.Cosmos.Telemetry
66
{
77
using System.Net;
8-
using Microsoft.Azure.Documents;
98

109
internal class OpenTelemetryAttributes
1110
{
12-
internal const string NotAvailable = "information not available";
13-
1411
/// <summary>
1512
/// For testing purpose only, to make initialization of this class easy
1613
/// </summary>
@@ -20,7 +17,7 @@ internal OpenTelemetryAttributes()
2017

2118
internal OpenTelemetryAttributes(RequestMessage requestMessage)
2219
{
23-
this.RequestContentLength = requestMessage?.Headers?.ContentLength ?? OpenTelemetryAttributes.NotAvailable;
20+
this.RequestContentLength = requestMessage?.Headers?.ContentLength;
2421
}
2522

2623
/// <summary>

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryCoreRecorder.cs

+5-13
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ namespace Microsoft.Azure.Cosmos.Telemetry
66
{
77
using System;
88
using System.Collections.Generic;
9-
using Diagnostics;
10-
using global::Azure;
119
using global::Azure.Core.Pipeline;
12-
using HdrHistogram;
1310

1411
internal struct OpenTelemetryCoreRecorder : IDisposable
1512
{
@@ -92,8 +89,8 @@ public void Record(
9289
this.scope.AddAttribute(OpenTelemetryAttributeKeys.NetPeerName, clientContext.Client?.Endpoint?.Host);
9390

9491
// Client Information
95-
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ClientId, clientContext?.Client?.Id ?? OpenTelemetryAttributes.NotAvailable);
96-
this.scope.AddAttribute(OpenTelemetryAttributeKeys.UserAgent, clientContext.UserAgent ?? OpenTelemetryAttributes.NotAvailable);
92+
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ClientId, clientContext?.Client?.Id);
93+
this.scope.AddAttribute(OpenTelemetryAttributeKeys.UserAgent, clientContext.UserAgent);
9794
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ConnectionMode, clientContext.ClientOptions.ConnectionMode);
9895
}
9996
}
@@ -108,21 +105,16 @@ public void Record(OpenTelemetryAttributes response)
108105
{
109106
this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestContentLength, response.RequestContentLength);
110107
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ResponseContentLength, response.ResponseContentLength);
111-
this.scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, response.StatusCode);
112-
this.scope.AddAttribute(OpenTelemetryAttributeKeys.SubStatusCode, response.SubStatusCode);
108+
this.scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, (int)response.StatusCode);
109+
this.scope.AddAttribute(OpenTelemetryAttributeKeys.SubStatusCode, (int)response.SubStatusCode);
113110
this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestCharge, response.RequestCharge);
114111
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ItemCount, response.ItemCount);
115112

116113
if (response.Diagnostics != null)
117114
{
118-
this.scope.AddAttribute(OpenTelemetryAttributeKeys.Region, ClientTelemetryHelper.GetContactedRegions(response.Diagnostics.GetContactedRegions()) ?? OpenTelemetryAttributes.NotAvailable);
115+
this.scope.AddAttribute(OpenTelemetryAttributeKeys.Region, ClientTelemetryHelper.GetContactedRegions(response.Diagnostics.GetContactedRegions()));
119116
CosmosDbEventSource.RecordDiagnosticsForRequests(this.config, this.operationType, response);
120117
}
121-
else
122-
{
123-
this.scope.AddAttribute(OpenTelemetryAttributeKeys.Region, OpenTelemetryAttributes.NotAvailable);
124-
this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestDiagnostics, OpenTelemetryAttributes.NotAvailable);
125-
}
126118
}
127119
}
128120

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryRecorderFactory.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
2424
isActivityEnabled: true);
2525
DiagnosticScope scope = OpenTelemetryRecorderFactory
2626
.ScopeFactory
27-
.CreateScope($"{OpenTelemetryAttributeKeys.OperationPrefix}.{operationName}");
27+
.CreateScope(name: $"{OpenTelemetryAttributeKeys.OperationPrefix}.{operationName}",
28+
kind: clientContext.ClientOptions.ConnectionMode == ConnectionMode.Gateway ? DiagnosticScope.ActivityKind.Internal : DiagnosticScope.ActivityKind.Client);
2829

2930
if (scope.IsEnabled)
3031
{

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryResponse.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ private OpenTelemetryResponse(
4646
{
4747
this.StatusCode = statusCode;
4848
this.RequestCharge = requestCharge;
49-
this.ResponseContentLength = responseContentLength ?? OpenTelemetryAttributes.NotAvailable;
49+
this.ResponseContentLength = responseContentLength;
5050
this.Diagnostics = diagnostics;
51-
this.ItemCount = itemCount ?? OpenTelemetryAttributes.NotAvailable;
51+
this.ItemCount = itemCount;
5252
this.SubStatusCode = subStatusCode;
5353
}
5454

@@ -60,7 +60,7 @@ private static string GetPayloadSize(ResponseMessage response)
6060
{
6161
return response.Content.Length.ToString();
6262
}
63-
return response?.Headers?.ContentLength ?? OpenTelemetryAttributes.NotAvailable;
63+
return response?.Headers?.ContentLength;
6464
}
6565
}
6666
}

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryResponse{T}.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ private OpenTelemetryResponse(
4545
{
4646
this.StatusCode = statusCode;
4747
this.RequestCharge = requestCharge;
48-
this.ResponseContentLength = responseContentLength ?? OpenTelemetryAttributes.NotAvailable;
48+
this.ResponseContentLength = responseContentLength;
4949
this.Diagnostics = diagnostics;
50-
this.ItemCount = itemCount ?? OpenTelemetryAttributes.NotAvailable;
50+
this.ItemCount = itemCount;
5151
this.SubStatusCode = subStatusCode;
5252
}
5353
}

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BatchOperationsAsync.xml

+13-13
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,34 @@
3434
</Input>
3535
<Output>
3636
<Text><![CDATA[.
37-
└── ExecuteAsync(00000000-0000-0000-0000-000000000000) Transport-Component 12:00:00:000 0.00 milliseconds
37+
└── ExecuteAsync(00000000-0000-0000-0000-000000000000) Transport-Component 00:00:00:000 0.00 milliseconds
3838
│ (
3939
│ [Client Configuration]
4040
│ Redacted To Not Change The Baselines From Run To Run
4141
│ )
42-
└── Execute Next Batch(00000000-0000-0000-0000-000000000000) Batch-Component 12:00:00:000 0.00 milliseconds
43-
├── Create Batch Request(00000000-0000-0000-0000-000000000000) Batch-Component 12:00:00:000 0.00 milliseconds
44-
└── Execute Batch Request(00000000-0000-0000-0000-000000000000) Batch-Component 12:00:00:000 0.00 milliseconds
45-
├── Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
46-
│ └── Microsoft.Azure.Cosmos.Handlers.DiagnosticsHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
42+
└── Execute Next Batch(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
43+
├── Create Batch Request(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
44+
└── Execute Batch Request(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
45+
├── Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
46+
│ └── Microsoft.Azure.Cosmos.Handlers.DiagnosticsHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
4747
│ │ (
4848
│ │ [System Info]
4949
│ │ Redacted To Not Change The Baselines From Run To Run
5050
│ │ )
51-
│ └── Microsoft.Azure.Cosmos.Handlers.RetryHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
52-
│ └── Microsoft.Azure.Cosmos.Handlers.RouterHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
53-
│ └── Microsoft.Azure.Cosmos.Handlers.TransportHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
54-
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component 12:00:00:000 0.00 milliseconds
51+
│ └── Microsoft.Azure.Cosmos.Handlers.RetryHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
52+
│ └── Microsoft.Azure.Cosmos.Handlers.RouterHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
53+
│ └── Microsoft.Azure.Cosmos.Handlers.TransportHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
54+
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component 00:00:00:000 0.00 milliseconds
5555
│ (
5656
│ [Client Side Request Stats]
5757
│ Redacted To Not Change The Baselines From Run To Run
5858
│ )
59-
└── Create Trace(00000000-0000-0000-0000-000000000000) Batch-Component 12:00:00:000 0.00 milliseconds
59+
└── Create Trace(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
6060
]]></Text>
6161
<Json><![CDATA[{
6262
"Summary": {},
6363
"name": "ExecuteAsync",
64-
"start time": "12:00:00:000",
64+
"start time": "00:00:00:000",
6565
"duration in milliseconds": 0,
6666
"data": {
6767
"Client Configuration": "Redacted To Not Change The Baselines From Run To Run"
@@ -129,7 +129,7 @@
129129
}
130130
]
131131
}]]></Json>
132-
<OTelActivities><ACTIVITY><OPERATION>Cosmos.ExecuteAsync</OPERATION><ATTRIBUTE-KEY>kind</ATTRIBUTE-KEY><ATTRIBUTE-KEY>az.namespace</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.operation</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.name</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.container</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.operation_type</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.system</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.hashed_machine_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>net.peer.name</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.client_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.user_agent</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.connection_mode</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.request_content_length_bytes</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.response_content_length_bytes</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.status_code</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.sub_status_code</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.request_charge</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.item_count</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.regions_contacted</ATTRIBUTE-KEY></ACTIVITY>
132+
<OTelActivities><ACTIVITY><OPERATION>Cosmos.ExecuteAsync</OPERATION><ATTRIBUTE-KEY>kind</ATTRIBUTE-KEY><ATTRIBUTE-KEY>az.namespace</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.operation</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.name</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.container</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.operation_type</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.system</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.machine_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>net.peer.name</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.client_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.user_agent</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.connection_mode</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.request_content_length_bytes</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.response_content_length_bytes</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.status_code</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.sub_status_code</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.request_charge</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.item_count</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.regions_contacted</ATTRIBUTE-KEY></ACTIVITY>
133133
<EVENT>Ideally, this should contain request diagnostics but request diagnostics is subject to change with each request as it contains few unique id. So just putting this tag with this static text to make sure event is getting generated for each test.</EVENT>
134134
</OTelActivities>
135135
</Output>

0 commit comments

Comments
 (0)