Skip to content

Commit 040c2f1

Browse files
committed
cosmetic changes
1 parent 740e6c0 commit 040c2f1

17 files changed

+808
-589
lines changed

Microsoft.Azure.Cosmos/src/Batch/BatchCore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ public override Task<TransactionalBatchResponse> ExecuteAsync(
235235
},
236236
openTelemetry: (response) => new OpenTelemetryResponse(
237237
responseMessage: response,
238-
operationFlag: this.isHomogenousOperations,
239-
operationName: this.lastItemBatchOperation.OperationType));
238+
isHomogenousOperations: this.isHomogenousOperations,
239+
batchOperation: this.lastItemBatchOperation.OperationType));
240240
}
241241

242242
/// <summary>

Microsoft.Azure.Cosmos/src/Batch/TransactionalBatchInternal.cs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,62 @@ namespace Microsoft.Azure.Cosmos
1111
using System.Threading.Tasks;
1212
using Microsoft.Azure.Documents;
1313

14+
/// <summary>
15+
/// Represents an internal abstract class for handling transactional batches of operations.
16+
/// </summary>
1417
internal abstract class TransactionalBatchInternal : TransactionalBatch
1518
{
19+
/// <summary>
20+
/// The list of operations in the batch.
21+
/// </summary>
1622
protected List<ItemBatchOperation> operations;
1723

18-
internal bool isHomogenousOperations = false;
24+
/// <summary>
25+
/// Indicates whether all operations in the batch are of the same type.
26+
/// </summary>
27+
internal bool isHomogenousOperations = true;
1928

29+
/// <summary>
30+
/// The last operation added to the batch.
31+
/// </summary>
2032
internal ItemBatchOperation lastItemBatchOperation = null;
2133

34+
/// <summary>
35+
/// Adds a new operation to the batch of operations and updates the homogeneity status of the operations.
36+
/// </summary>
37+
/// <param name="itemBatchOperation">The operation to be added to the batch.</param>
38+
/// <remarks>
39+
/// This method performs the following actions:
40+
/// <list type="number">
41+
/// <item>
42+
/// <description>Adds the given <paramref name="itemBatchOperation"/> to the operations list.</description>
43+
/// </item>
44+
/// <item>
45+
/// <description>If the added operation is the first operation in the batch, it sets this operation as the <see cref="lastItemBatchOperation"/>.</description>
46+
/// </item>
47+
/// <item>
48+
/// <description>If there are existing operations in the batch and the operations are currently homogeneous, it checks if the last added operation's type matches the new operation's type:
49+
/// <list type="bullet">
50+
/// <item><description>If they match, the batch remains homogeneous.</description></item>
51+
/// <item><description>If they do not match, the batch is no longer considered homogeneous.</description></item>
52+
/// </list>
53+
/// </description>
54+
/// </item>
55+
/// <item>
56+
/// <description>Updates the <see cref="lastItemBatchOperation"/> to the newly added operation.</description>
57+
/// </item>
58+
/// </list>
59+
/// </remarks>
2260
protected void AddOperation(ItemBatchOperation itemBatchOperation)
2361
{
2462
this.operations.Add(itemBatchOperation);
2563
if (this.operations.Count == 1)
2664
{
2765
this.lastItemBatchOperation = itemBatchOperation;
2866
}
29-
else
67+
else if (this.isHomogenousOperations)
3068
{
31-
this.isHomogenousOperations = this.isHomogenousOperations
32-
&& this.lastItemBatchOperation.OperationType == itemBatchOperation.OperationType;
69+
this.isHomogenousOperations = this.lastItemBatchOperation.OperationType == itemBatchOperation.OperationType;
3370
this.lastItemBatchOperation = itemBatchOperation;
3471
}
3572
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Microsoft.Azure.Cosmos.Telemetry
66
{
7+
/// <summary>
8+
/// https://opentelemetry.io/docs/specs/semconv/database/cosmosdb/
9+
/// </summary>
710
internal sealed class OpenTelemetryAttributeKeys
811
{
912
// Azure defaults
@@ -14,8 +17,8 @@ internal sealed class OpenTelemetryAttributeKeys
1417

1518
// Common database attributes
1619
public const string DbSystemName = "db.system";
17-
public const string DbName = "db.name";
18-
public const string DbOperation = "db.operation";
20+
public const string DbName = "db.namespace";
21+
public const string DbOperation = "db.operation.name";
1922
public const string ServerAddress = "server.address";
2023

2124
// Cosmos Db Specific
@@ -26,17 +29,17 @@ internal sealed class OpenTelemetryAttributeKeys
2629
public const string OperationType = "db.cosmosdb.operation_type";
2730

2831
// Request/Response Specifics
29-
public const string ContainerName = "db.cosmosdb.container";
30-
public const string RequestContentLength = "db.cosmosdb.request_content_length_bytes";
31-
public const string ResponseContentLength = "db.cosmosdb.response_content_length_bytes";
32+
public const string ContainerName = "db.collection.name";
33+
public const string RequestContentLength = "db.cosmosdb.request_content_length";
34+
public const string ResponseContentLength = "db.cosmosdb.response_content_length";
3235
public const string StatusCode = "db.cosmosdb.status_code";
3336
public const string SubStatusCode = "db.cosmosdb.sub_status_code";
3437
public const string RequestCharge = "db.cosmosdb.request_charge";
3538
public const string Region = "db.cosmosdb.regions_contacted";
3639
public const string ItemCount = "db.cosmosdb.item_count";
3740
public const string ActivityId = "db.cosmosdb.activity_id";
3841
public const string CorrelatedActivityId = "db.cosmosdb.correlated_activity_id";
39-
public const string BatchSize = "db.cosmosdb.batch_size";
42+
public const string BatchSize = "db.operation.batch.size";
4043

4144
// Exceptions
4245
public const string ExceptionType = "exception.type";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.Azure.Cosmos
1313

1414
internal sealed class OpenTelemetryResponse : OpenTelemetryAttributes
1515
{
16-
internal OpenTelemetryResponse(TransactionalBatchResponse responseMessage, bool operationFlag, OperationType? operationName)
16+
internal OpenTelemetryResponse(TransactionalBatchResponse responseMessage, bool isHomogenousOperations, OperationType? batchOperation)
1717
: this(
1818
statusCode: responseMessage.StatusCode,
1919
requestCharge: OpenTelemetryResponse.GetHeader(responseMessage)?.RequestCharge,
@@ -25,7 +25,7 @@ internal OpenTelemetryResponse(TransactionalBatchResponse responseMessage, bool
2525
activityId: OpenTelemetryResponse.GetHeader(responseMessage)?.ActivityId,
2626
correlationId: OpenTelemetryResponse.GetHeader(responseMessage)?.CorrelatedActivityId,
2727
batchSize: responseMessage.GetBatchSize(),
28-
batchOperationName: operationFlag ? operationName : null )
28+
batchOperationName: isHomogenousOperations ? batchOperation : null )
2929
{
3030
}
3131

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

Lines changed: 157 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,170 @@
142142
<ACTIVITY source="Azure.Cosmos.Operation" operationName="Operation.ExecuteAsync" displayName="ExecuteAsync containerName">
143143
<ATTRIBUTE key="az.namespace">Microsoft.DocumentDB</ATTRIBUTE>
144144
<ATTRIBUTE key="az.schema_url">https://opentelemetry.io/schemas/1.23.0</ATTRIBUTE>
145-
<ATTRIBUTE key="db.operation">ExecuteAsync</ATTRIBUTE>
146-
<ATTRIBUTE key="db.name">databaseName</ATTRIBUTE>
147-
<ATTRIBUTE key="db.cosmosdb.container">containerName</ATTRIBUTE>
145+
<ATTRIBUTE key="db.operation.name">ExecuteAsync</ATTRIBUTE>
146+
<ATTRIBUTE key="db.namespace">databaseName</ATTRIBUTE>
147+
<ATTRIBUTE key="db.collection.name">containerName</ATTRIBUTE>
148148
<ATTRIBUTE key="db.system">cosmosdb</ATTRIBUTE>
149149
<ATTRIBUTE key="db.cosmosdb.machine_id">Some Value</ATTRIBUTE>
150150
<ATTRIBUTE key="server.address">127.0.0.1</ATTRIBUTE>
151151
<ATTRIBUTE key="db.cosmosdb.client_id">Some Value</ATTRIBUTE>
152152
<ATTRIBUTE key="user_agent.original">Some Value</ATTRIBUTE>
153153
<ATTRIBUTE key="db.cosmosdb.connection_mode">Direct</ATTRIBUTE>
154154
<ATTRIBUTE key="db.cosmosdb.operation_type">Batch</ATTRIBUTE>
155-
<ATTRIBUTE key="db.cosmosdb.batch_size">90</ATTRIBUTE>
155+
<ATTRIBUTE key="db.operation.batch.size">90</ATTRIBUTE>
156+
<ATTRIBUTE key="db.cosmosdb.status_code">Some Value</ATTRIBUTE>
157+
<ATTRIBUTE key="db.cosmosdb.sub_status_code">Some Value</ATTRIBUTE>
158+
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
159+
<ATTRIBUTE key="db.cosmosdb.item_count">Some Value</ATTRIBUTE>
160+
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
161+
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
162+
<ATTRIBUTE key="error.type">400/1001</ATTRIBUTE>
163+
</ACTIVITY>
164+
<EVENT name="FailedRequest" />
165+
</OTelActivities></Output>
166+
</Result>
167+
<Result>
168+
<Input>
169+
<Description>Batch Homogenous Operation</Description>
170+
<Setup><![CDATA[
171+
string pkValue = "DiagnosticTestPk";
172+
TransactionalBatch batch = container.CreateTransactionalBatch(new PartitionKey(pkValue));
173+
List<ToDoActivity> createItems = new List<ToDoActivity>();
174+
for (int i = 0; i < 50; i++)
175+
{
176+
ToDoActivity item = ToDoActivity.CreateRandomToDoActivity(pk: pkValue);
177+
createItems.Add(item);
178+
batch.CreateItem<ToDoActivity>(item);
179+
}
180+
181+
TransactionalBatchRequestOptions requestOptions = null;
182+
TransactionalBatchResponse response = await batch.ExecuteAsync(requestOptions);
183+
184+
Assert.IsNotNull(response);
185+
ITrace trace = ((CosmosTraceDiagnostics)response.Diagnostics).Value;
186+
]]></Setup>
187+
</Input>
188+
<Output>
189+
<Text><![CDATA[.
190+
└── ExecuteAsync(00000000-0000-0000-0000-000000000000) Transport-Component 00:00:00:000 0.00 milliseconds
191+
│ (
192+
│ [Client Configuration]
193+
│ Redacted To Not Change The Baselines From Run To Run
194+
│ [DistributedTraceId]
195+
│ Redacted To Not Change The Baselines From Run To Run
196+
│ )
197+
└── Execute Next Batch(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
198+
├── Create Batch Request(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
199+
└── Execute Batch Request(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
200+
├── Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
201+
│ └── Microsoft.Azure.Cosmos.Handlers.DiagnosticsHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
202+
│ │ (
203+
│ │ [System Info]
204+
│ │ Redacted To Not Change The Baselines From Run To Run
205+
│ │ )
206+
│ └── Microsoft.Azure.Cosmos.Handlers.TelemetryHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
207+
│ └── Microsoft.Azure.Cosmos.Handlers.RetryHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
208+
│ └── Microsoft.Azure.Cosmos.Handlers.RouterHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
209+
│ └── Microsoft.Azure.Cosmos.Handlers.TransportHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
210+
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component 00:00:00:000 0.00 milliseconds
211+
│ (
212+
│ [Client Side Request Stats]
213+
│ Redacted To Not Change The Baselines From Run To Run
214+
│ )
215+
└── Create Trace(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
216+
]]></Text>
217+
<Json><![CDATA[{
218+
"Summary": {},
219+
"name": "ExecuteAsync",
220+
"start datetime": "0001-01-01T00:00:00Z",
221+
"duration in milliseconds": 0,
222+
"data": {
223+
"Client Configuration": "Redacted To Not Change The Baselines From Run To Run",
224+
"DistributedTraceId": "Redacted To Not Change The Baselines From Run To Run"
225+
},
226+
"children": [
227+
{
228+
"name": "Execute Next Batch",
229+
"duration in milliseconds": 0,
230+
"children": [
231+
{
232+
"name": "Create Batch Request",
233+
"duration in milliseconds": 0
234+
},
235+
{
236+
"name": "Execute Batch Request",
237+
"duration in milliseconds": 0,
238+
"children": [
239+
{
240+
"name": "Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler",
241+
"duration in milliseconds": 0,
242+
"children": [
243+
{
244+
"name": "Microsoft.Azure.Cosmos.Handlers.DiagnosticsHandler",
245+
"duration in milliseconds": 0,
246+
"data": {
247+
"System Info": "Redacted To Not Change The Baselines From Run To Run"
248+
},
249+
"children": [
250+
{
251+
"name": "Microsoft.Azure.Cosmos.Handlers.TelemetryHandler",
252+
"duration in milliseconds": 0,
253+
"children": [
254+
{
255+
"name": "Microsoft.Azure.Cosmos.Handlers.RetryHandler",
256+
"duration in milliseconds": 0,
257+
"children": [
258+
{
259+
"name": "Microsoft.Azure.Cosmos.Handlers.RouterHandler",
260+
"duration in milliseconds": 0,
261+
"children": [
262+
{
263+
"name": "Microsoft.Azure.Cosmos.Handlers.TransportHandler",
264+
"duration in milliseconds": 0,
265+
"children": [
266+
{
267+
"name": "Microsoft.Azure.Documents.ServerStoreModel Transport Request",
268+
"duration in milliseconds": 0,
269+
"data": {
270+
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run"
271+
}
272+
}
273+
]
274+
}
275+
]
276+
}
277+
]
278+
}
279+
]
280+
}
281+
]
282+
}
283+
]
284+
},
285+
{
286+
"name": "Create Trace",
287+
"duration in milliseconds": 0
288+
}
289+
]
290+
}
291+
]
292+
}
293+
]
294+
}]]></Json><OTelActivities>
295+
<ACTIVITY source="Azure.Cosmos.Operation" operationName="Operation.ExecuteAsync" displayName="ExecuteAsync containerName">
296+
<ATTRIBUTE key="az.namespace">Microsoft.DocumentDB</ATTRIBUTE>
297+
<ATTRIBUTE key="az.schema_url">https://opentelemetry.io/schemas/1.23.0</ATTRIBUTE>
298+
<ATTRIBUTE key="db.operation.name">ExecuteAsync</ATTRIBUTE>
299+
<ATTRIBUTE key="db.namespace">databaseName</ATTRIBUTE>
300+
<ATTRIBUTE key="db.collection.name">containerName</ATTRIBUTE>
301+
<ATTRIBUTE key="db.system">cosmosdb</ATTRIBUTE>
302+
<ATTRIBUTE key="db.cosmosdb.machine_id">Some Value</ATTRIBUTE>
303+
<ATTRIBUTE key="server.address">127.0.0.1</ATTRIBUTE>
304+
<ATTRIBUTE key="db.cosmosdb.client_id">Some Value</ATTRIBUTE>
305+
<ATTRIBUTE key="user_agent.original">Some Value</ATTRIBUTE>
306+
<ATTRIBUTE key="db.cosmosdb.connection_mode">Direct</ATTRIBUTE>
307+
<ATTRIBUTE key="db.cosmosdb.operation_type">Batch.Create</ATTRIBUTE>
308+
<ATTRIBUTE key="db.operation.batch.size">50</ATTRIBUTE>
156309
<ATTRIBUTE key="db.cosmosdb.status_code">Some Value</ATTRIBUTE>
157310
<ATTRIBUTE key="db.cosmosdb.sub_status_code">Some Value</ATTRIBUTE>
158311
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>

0 commit comments

Comments
 (0)