Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI Integration: Adds cosmetic fixes #3576

Merged
merged 8 commits into from
Nov 26, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ private string ToStringHelper(
/// <param name="scope"></param>
internal static void RecordOtelAttributes(CosmosException exception, DiagnosticScope scope)
{
scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, exception.StatusCode);
scope.AddAttribute(OpenTelemetryAttributeKeys.SubStatusCode, exception.SubStatusCode);
scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, (int)exception.StatusCode);
scope.AddAttribute(OpenTelemetryAttributeKeys.SubStatusCode, (int)exception.SubStatusCode);
scope.AddAttribute(OpenTelemetryAttributeKeys.RequestCharge, exception.RequestCharge);
scope.AddAttribute(OpenTelemetryAttributeKeys.Region,
ClientTelemetryHelper.GetContactedRegions(exception.Diagnostics?.GetContactedRegions()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed class OpenTelemetryAttributeKeys

// Cosmos Db Specific
public const string ClientId = "db.cosmosdb.client_id";
public const string MachineId = "db.cosmosdb.hashed_machine_id";
public const string MachineId = "db.cosmosdb.machine_id";
public const string UserAgent = "db.cosmosdb.user_agent";
public const string ConnectionMode = "db.cosmosdb.connection_mode";
public const string OperationType = "db.cosmosdb.operation_type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
namespace Microsoft.Azure.Cosmos.Telemetry
{
using System.Net;
using Microsoft.Azure.Documents;

internal class OpenTelemetryAttributes
{
internal const string NotAvailable = "information not available";

/// <summary>
/// For testing purpose only, to make initialization of this class easy
/// </summary>
Expand All @@ -20,7 +17,7 @@ internal OpenTelemetryAttributes()

internal OpenTelemetryAttributes(RequestMessage requestMessage)
{
this.RequestContentLength = requestMessage?.Headers?.ContentLength ?? OpenTelemetryAttributes.NotAvailable;
this.RequestContentLength = requestMessage?.Headers?.ContentLength;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ namespace Microsoft.Azure.Cosmos.Telemetry
{
using System;
using System.Collections.Generic;
using Diagnostics;
using global::Azure;
using global::Azure.Core.Pipeline;
using HdrHistogram;

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

// Client Information
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ClientId, clientContext?.Client?.Id ?? OpenTelemetryAttributes.NotAvailable);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.UserAgent, clientContext.UserAgent ?? OpenTelemetryAttributes.NotAvailable);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ClientId, clientContext?.Client?.Id);
sourabh1007 marked this conversation as resolved.
Show resolved Hide resolved
this.scope.AddAttribute(OpenTelemetryAttributeKeys.UserAgent, clientContext.UserAgent);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ConnectionMode, clientContext.ClientOptions.ConnectionMode);
}
}
Expand All @@ -108,21 +105,16 @@ public void Record(OpenTelemetryAttributes response)
{
this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestContentLength, response.RequestContentLength);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ResponseContentLength, response.ResponseContentLength);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, response.StatusCode);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.SubStatusCode, response.SubStatusCode);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, (int)response.StatusCode);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.SubStatusCode, (int)response.SubStatusCode);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestCharge, response.RequestCharge);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ItemCount, response.ItemCount);

if (response.Diagnostics != null)
{
this.scope.AddAttribute(OpenTelemetryAttributeKeys.Region, ClientTelemetryHelper.GetContactedRegions(response.Diagnostics.GetContactedRegions()) ?? OpenTelemetryAttributes.NotAvailable);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.Region, ClientTelemetryHelper.GetContactedRegions(response.Diagnostics.GetContactedRegions()));
CosmosDbEventSource.RecordDiagnosticsForRequests(this.config, this.operationType, response);
}
else
{
this.scope.AddAttribute(OpenTelemetryAttributeKeys.Region, OpenTelemetryAttributes.NotAvailable);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestDiagnostics, OpenTelemetryAttributes.NotAvailable);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
isActivityEnabled: true);
DiagnosticScope scope = OpenTelemetryRecorderFactory
.ScopeFactory
.CreateScope($"{OpenTelemetryAttributeKeys.OperationPrefix}.{operationName}");
.CreateScope(name: $"{OpenTelemetryAttributeKeys.OperationPrefix}.{operationName}",
kind: clientContext.ClientOptions.ConnectionMode == ConnectionMode.Gateway ? DiagnosticScope.ActivityKind.Internal : DiagnosticScope.ActivityKind.Client);

if (scope.IsEnabled)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ private OpenTelemetryResponse(
{
this.StatusCode = statusCode;
this.RequestCharge = requestCharge;
this.ResponseContentLength = responseContentLength ?? OpenTelemetryAttributes.NotAvailable;
this.ResponseContentLength = responseContentLength;
this.Diagnostics = diagnostics;
this.ItemCount = itemCount ?? OpenTelemetryAttributes.NotAvailable;
this.ItemCount = itemCount;
this.SubStatusCode = subStatusCode;
}

Expand All @@ -60,7 +60,7 @@ private static string GetPayloadSize(ResponseMessage response)
{
return response.Content.Length.ToString();
}
return response?.Headers?.ContentLength ?? OpenTelemetryAttributes.NotAvailable;
return response?.Headers?.ContentLength;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ private OpenTelemetryResponse(
{
this.StatusCode = statusCode;
this.RequestCharge = requestCharge;
this.ResponseContentLength = responseContentLength ?? OpenTelemetryAttributes.NotAvailable;
this.ResponseContentLength = responseContentLength;
this.Diagnostics = diagnostics;
this.ItemCount = itemCount ?? OpenTelemetryAttributes.NotAvailable;
this.ItemCount = itemCount;
this.SubStatusCode = subStatusCode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,34 @@
</Input>
<Output>
<Text><![CDATA[.
└── ExecuteAsync(00000000-0000-0000-0000-000000000000) Transport-Component 12:00:00:000 0.00 milliseconds
└── ExecuteAsync(00000000-0000-0000-0000-000000000000) Transport-Component 00:00:00:000 0.00 milliseconds
│ (
│ [Client Configuration]
│ Redacted To Not Change The Baselines From Run To Run
│ )
└── Execute Next Batch(00000000-0000-0000-0000-000000000000) Batch-Component 12:00:00:000 0.00 milliseconds
├── Create Batch Request(00000000-0000-0000-0000-000000000000) Batch-Component 12:00:00:000 0.00 milliseconds
└── Execute Batch Request(00000000-0000-0000-0000-000000000000) Batch-Component 12:00:00:000 0.00 milliseconds
├── Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Cosmos.Handlers.DiagnosticsHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
└── Execute Next Batch(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
├── Create Batch Request(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
└── Execute Batch Request(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
├── Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Cosmos.Handlers.DiagnosticsHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
│ │ (
│ │ [System Info]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ )
│ └── Microsoft.Azure.Cosmos.Handlers.RetryHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Cosmos.Handlers.RouterHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Cosmos.Handlers.TransportHandler(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
│ └── Microsoft.Azure.Cosmos.Handlers.RetryHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Cosmos.Handlers.RouterHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Cosmos.Handlers.TransportHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component 00:00:00:000 0.00 milliseconds
│ (
│ [Client Side Request Stats]
│ Redacted To Not Change The Baselines From Run To Run
│ )
└── Create Trace(00000000-0000-0000-0000-000000000000) Batch-Component 12:00:00:000 0.00 milliseconds
└── Create Trace(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
]]></Text>
<Json><![CDATA[{
"Summary": {},
"name": "ExecuteAsync",
"start time": "12:00:00:000",
"start time": "00:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Configuration": "Redacted To Not Change The Baselines From Run To Run"
Expand Down Expand Up @@ -129,7 +129,7 @@
}
]
}]]></Json>
<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>
<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>
<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>
</OTelActivities>
</Output>
Expand Down
Loading