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

[Internal] AI Integration: Refactors to Operation prefix and add tests #3583

Merged
merged 9 commits into from
Dec 5, 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 @@ -8,10 +8,14 @@ namespace Microsoft.Azure.Cosmos.Telemetry
using global::Azure.Core.Diagnostics;
using Microsoft.Azure.Cosmos.Telemetry.Diagnostics;

/// <summary>
/// This class is used to generate events with Azure.Cosmos.Operation Source Name
/// </summary>
[EventSource(Name = EventSourceName)]
internal sealed class CosmosDbEventSource : AzureEventSource
{
private const string EventSourceName = OpenTelemetryAttributeKeys.DiagnosticNamespace;
internal const string EventSourceName = "Azure-Cosmos-Operation-Request-Diagnostics";

private static CosmosDbEventSource Singleton { get; } = new CosmosDbEventSource();

private CosmosDbEventSource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal sealed class OpenTelemetryAttributeKeys
// Azure defaults
public const string DiagnosticNamespace = "Azure.Cosmos";
public const string ResourceProviderNamespace = "Microsoft.DocumentDB";
public const string OperationPrefix = "Cosmos";
public const string OperationPrefix = "Operation";

// Common database attributes
public const string DbSystemName = "db.system";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace Microsoft.Azure.Cosmos.Telemetry
using System.Collections.Generic;
using global::Azure.Core.Pipeline;

/// <summary>
/// This class is used to add information in an Activity tags ref. https://github.com/Azure/azure-cosmos-dotnet-v3/issues/3058
/// </summary>
internal struct OpenTelemetryCoreRecorder : IDisposable
{
private const string CosmosDb = "cosmosdb";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ namespace Microsoft.Azure.Cosmos.Telemetry
{
using global::Azure.Core.Pipeline;

/// <summary>
/// This class is used to generate Activities with Azure.Cosmos.Operation Source Name
/// </summary>
internal static class OpenTelemetryRecorderFactory
{
/// <summary>
/// Singleton to make sure we only have one instance of the DiagnosticScopeFactory and pattern matching of listener happens only once
/// </summary>
private static DiagnosticScopeFactory ScopeFactory { get; set; }

public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
Expand All @@ -22,11 +28,14 @@ public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
ScopeFactory = new DiagnosticScopeFactory(clientNamespace: OpenTelemetryAttributeKeys.DiagnosticNamespace,
resourceProviderNamespace: OpenTelemetryAttributeKeys.ResourceProviderNamespace,
isActivityEnabled: true);

// If there is no source then it will return default otherwise a valid diagnostic scope
DiagnosticScope scope = OpenTelemetryRecorderFactory
.ScopeFactory
.CreateScope(name: $"{OpenTelemetryAttributeKeys.OperationPrefix}.{operationName}",
kind: clientContext.ClientOptions.ConnectionMode == ConnectionMode.Gateway ? DiagnosticScope.ActivityKind.Internal : DiagnosticScope.ActivityKind.Client);

// Record values only when we have a valid Diagnostic Scope
if (scope.IsEnabled)
{
return new OpenTelemetryCoreRecorder(
Expand Down
Original file line number Diff line number Diff line change
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.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>Operation.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>
sourabh1007 marked this conversation as resolved.
Show resolved Hide resolved
<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