@azure-typespec/http-client-csharp-mgmt 1.0.0-alpha.20250409.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/emitter/emitter.d.ts +4 -0
- package/dist/emitter/emitter.d.ts.map +1 -0
- package/dist/emitter/emitter.js +77 -0
- package/dist/emitter/emitter.js.map +1 -0
- package/dist/emitter/index.d.ts +2 -0
- package/dist/emitter/index.d.ts.map +1 -0
- package/dist/emitter/index.js +4 -0
- package/dist/emitter/index.js.map +1 -0
- package/dist/emitter/resource-type.d.ts +2 -0
- package/dist/emitter/resource-type.d.ts.map +1 -0
- package/dist/emitter/resource-type.js +31 -0
- package/dist/emitter/resource-type.js.map +1 -0
- package/dist/emitter/sdk-context-options.d.ts +3 -0
- package/dist/emitter/sdk-context-options.d.ts.map +1 -0
- package/dist/emitter/sdk-context-options.js +23 -0
- package/dist/emitter/sdk-context-options.js.map +1 -0
- package/dist/generator/Azure.Core.dll +0 -0
- package/dist/generator/Azure.Generator.Mgmt.deps.json +998 -0
- package/dist/generator/Azure.Generator.Mgmt.dll +0 -0
- package/dist/generator/Azure.Generator.Mgmt.pdb +0 -0
- package/dist/generator/Azure.Generator.Mgmt.xml +818 -0
- package/dist/generator/Azure.Generator.dll +0 -0
- package/dist/generator/Azure.Generator.pdb +0 -0
- package/dist/generator/Azure.Generator.xml +163 -0
- package/dist/generator/Azure.ResourceManager.dll +0 -0
- package/dist/generator/CommandLine.dll +0 -0
- package/dist/generator/Humanizer.dll +0 -0
- package/dist/generator/Microsoft.Bcl.AsyncInterfaces.dll +0 -0
- package/dist/generator/Microsoft.Build.Framework.dll +0 -0
- package/dist/generator/Microsoft.Build.dll +0 -0
- package/dist/generator/Microsoft.CodeAnalysis.CSharp.Workspaces.dll +0 -0
- package/dist/generator/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/dist/generator/Microsoft.CodeAnalysis.Workspaces.dll +0 -0
- package/dist/generator/Microsoft.CodeAnalysis.dll +0 -0
- package/dist/generator/Microsoft.Extensions.Logging.Abstractions.dll +0 -0
- package/dist/generator/Microsoft.NET.StringTools.dll +0 -0
- package/dist/generator/Microsoft.TypeSpec.Generator.ClientModel.dll +0 -0
- package/dist/generator/Microsoft.TypeSpec.Generator.Input.dll +0 -0
- package/dist/generator/Microsoft.TypeSpec.Generator.dll +0 -0
- package/dist/generator/Microsoft.TypeSpec.Generator.runtimeconfig.json +12 -0
- package/dist/generator/NuGet.Common.dll +0 -0
- package/dist/generator/NuGet.Configuration.dll +0 -0
- package/dist/generator/NuGet.Frameworks.dll +0 -0
- package/dist/generator/Shared/Core/AppContextSwitchHelper.cs +42 -0
- package/dist/generator/Shared/Core/AsyncLockWithValue.cs +260 -0
- package/dist/generator/Shared/Core/AzureKeyCredentialPolicy.cs +50 -0
- package/dist/generator/Shared/Core/ClientDiagnostics.cs +73 -0
- package/dist/generator/Shared/Core/DiagnosticScope.cs +473 -0
- package/dist/generator/Shared/Core/DiagnosticScopeFactory.cs +104 -0
- package/dist/generator/Shared/Core/FixedDelayWithNoJitterStrategy.cs +26 -0
- package/dist/generator/Shared/Core/HttpMessageSanitizer.cs +198 -0
- package/dist/generator/Shared/Core/IOperationSource.cs +14 -0
- package/dist/generator/Shared/Core/NextLinkOperationImplementation.cs +690 -0
- package/dist/generator/Shared/Core/OperationFinalStateVia.cs +16 -0
- package/dist/generator/Shared/Core/OperationInternal.cs +256 -0
- package/dist/generator/Shared/Core/OperationInternalBase.cs +234 -0
- package/dist/generator/Shared/Core/OperationInternalOfT.cs +422 -0
- package/dist/generator/Shared/Core/OperationPoller.cs +114 -0
- package/dist/generator/Shared/Core/RawRequestUriBuilder.cs +192 -0
- package/dist/generator/Shared/Core/SequentialDelayStrategy.cs +38 -0
- package/dist/generator/Shared/Core/TaskExtensions.cs +313 -0
- package/dist/generator/Shared/Core/VoidValue.cs +10 -0
- package/dist/generator/System.ClientModel.dll +0 -0
- package/dist/generator/System.ComponentModel.Composition.dll +0 -0
- package/dist/generator/System.Composition.AttributedModel.dll +0 -0
- package/dist/generator/System.Composition.Convention.dll +0 -0
- package/dist/generator/System.Composition.Hosting.dll +0 -0
- package/dist/generator/System.Composition.Runtime.dll +0 -0
- package/dist/generator/System.Composition.TypedParts.dll +0 -0
- package/dist/generator/System.Configuration.ConfigurationManager.dll +0 -0
- package/dist/generator/System.Diagnostics.EventLog.dll +0 -0
- package/dist/generator/System.IO.Pipelines.dll +0 -0
- package/dist/generator/System.Memory.Data.dll +0 -0
- package/dist/generator/System.Reflection.MetadataLoadContext.dll +0 -0
- package/dist/generator/System.Security.Cryptography.ProtectedData.dll +0 -0
- package/dist/generator/cs/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/cs/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/cs/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/cs/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/de/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/de/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/de/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/de/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/es/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/es/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/es/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/es/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/fr/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/fr/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/fr/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/fr/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/it/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/it/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/it/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/it/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/ja/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/ja/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/ja/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/ja/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/ko/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/ko/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/ko/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/ko/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/Azure.Core.dll +0 -0
- package/dist/generator/net8.0/Azure.Generator.Mgmt.deps.json +998 -0
- package/dist/generator/net8.0/Azure.Generator.Mgmt.dll +0 -0
- package/dist/generator/net8.0/Azure.Generator.Mgmt.pdb +0 -0
- package/dist/generator/net8.0/Azure.Generator.Mgmt.xml +818 -0
- package/dist/generator/net8.0/Azure.Generator.dll +0 -0
- package/dist/generator/net8.0/Azure.Generator.pdb +0 -0
- package/dist/generator/net8.0/Azure.Generator.xml +163 -0
- package/dist/generator/net8.0/Azure.ResourceManager.dll +0 -0
- package/dist/generator/net8.0/CommandLine.dll +0 -0
- package/dist/generator/net8.0/Humanizer.dll +0 -0
- package/dist/generator/net8.0/Microsoft.Bcl.AsyncInterfaces.dll +0 -0
- package/dist/generator/net8.0/Microsoft.Build.Framework.dll +0 -0
- package/dist/generator/net8.0/Microsoft.Build.dll +0 -0
- package/dist/generator/net8.0/Microsoft.CodeAnalysis.CSharp.Workspaces.dll +0 -0
- package/dist/generator/net8.0/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/dist/generator/net8.0/Microsoft.CodeAnalysis.Workspaces.dll +0 -0
- package/dist/generator/net8.0/Microsoft.CodeAnalysis.dll +0 -0
- package/dist/generator/net8.0/Microsoft.Extensions.Logging.Abstractions.dll +0 -0
- package/dist/generator/net8.0/Microsoft.NET.StringTools.dll +0 -0
- package/dist/generator/net8.0/Microsoft.TypeSpec.Generator.ClientModel.dll +0 -0
- package/dist/generator/net8.0/Microsoft.TypeSpec.Generator.Input.dll +0 -0
- package/dist/generator/net8.0/Microsoft.TypeSpec.Generator.dll +0 -0
- package/dist/generator/net8.0/NuGet.Common.dll +0 -0
- package/dist/generator/net8.0/NuGet.Configuration.dll +0 -0
- package/dist/generator/net8.0/NuGet.Frameworks.dll +0 -0
- package/dist/generator/net8.0/Shared/Core/AppContextSwitchHelper.cs +42 -0
- package/dist/generator/net8.0/Shared/Core/AsyncLockWithValue.cs +260 -0
- package/dist/generator/net8.0/Shared/Core/AzureKeyCredentialPolicy.cs +50 -0
- package/dist/generator/net8.0/Shared/Core/ClientDiagnostics.cs +73 -0
- package/dist/generator/net8.0/Shared/Core/DiagnosticScope.cs +473 -0
- package/dist/generator/net8.0/Shared/Core/DiagnosticScopeFactory.cs +104 -0
- package/dist/generator/net8.0/Shared/Core/FixedDelayWithNoJitterStrategy.cs +26 -0
- package/dist/generator/net8.0/Shared/Core/HttpMessageSanitizer.cs +198 -0
- package/dist/generator/net8.0/Shared/Core/IOperationSource.cs +14 -0
- package/dist/generator/net8.0/Shared/Core/NextLinkOperationImplementation.cs +690 -0
- package/dist/generator/net8.0/Shared/Core/OperationFinalStateVia.cs +16 -0
- package/dist/generator/net8.0/Shared/Core/OperationInternal.cs +256 -0
- package/dist/generator/net8.0/Shared/Core/OperationInternalBase.cs +234 -0
- package/dist/generator/net8.0/Shared/Core/OperationInternalOfT.cs +422 -0
- package/dist/generator/net8.0/Shared/Core/OperationPoller.cs +114 -0
- package/dist/generator/net8.0/Shared/Core/RawRequestUriBuilder.cs +192 -0
- package/dist/generator/net8.0/Shared/Core/SequentialDelayStrategy.cs +38 -0
- package/dist/generator/net8.0/Shared/Core/TaskExtensions.cs +313 -0
- package/dist/generator/net8.0/Shared/Core/VoidValue.cs +10 -0
- package/dist/generator/net8.0/System.ClientModel.dll +0 -0
- package/dist/generator/net8.0/System.ComponentModel.Composition.dll +0 -0
- package/dist/generator/net8.0/System.Composition.AttributedModel.dll +0 -0
- package/dist/generator/net8.0/System.Composition.Convention.dll +0 -0
- package/dist/generator/net8.0/System.Composition.Hosting.dll +0 -0
- package/dist/generator/net8.0/System.Composition.Runtime.dll +0 -0
- package/dist/generator/net8.0/System.Composition.TypedParts.dll +0 -0
- package/dist/generator/net8.0/System.Configuration.ConfigurationManager.dll +0 -0
- package/dist/generator/net8.0/System.Diagnostics.EventLog.dll +0 -0
- package/dist/generator/net8.0/System.IO.Pipelines.dll +0 -0
- package/dist/generator/net8.0/System.Memory.Data.dll +0 -0
- package/dist/generator/net8.0/System.Reflection.MetadataLoadContext.dll +0 -0
- package/dist/generator/net8.0/System.Security.Cryptography.ProtectedData.dll +0 -0
- package/dist/generator/net8.0/cs/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/cs/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/cs/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/cs/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/de/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/de/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/de/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/de/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/es/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/es/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/es/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/es/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/fr/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/fr/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/fr/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/fr/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/it/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/it/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/it/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/it/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/ja/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/ja/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/ja/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/ja/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/ko/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/ko/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/ko/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/ko/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/pl/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/pl/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/pl/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/pl/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/pt-BR/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/pt-BR/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/pt-BR/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/pt-BR/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/ru/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/ru/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/ru/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/ru/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/runtimes/win/lib/net8.0/System.Diagnostics.EventLog.Messages.dll +0 -0
- package/dist/generator/net8.0/runtimes/win/lib/net8.0/System.Diagnostics.EventLog.dll +0 -0
- package/dist/generator/net8.0/tr/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/tr/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/tr/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/tr/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/zh-Hans/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/zh-Hans/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/zh-Hans/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/zh-Hans/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/net8.0/zh-Hant/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/zh-Hant/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/net8.0/zh-Hant/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/net8.0/zh-Hant/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/pl/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/pl/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/pl/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/pl/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/pt-BR/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/pt-BR/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/pt-BR/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/pt-BR/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/ru/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/ru/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/ru/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/ru/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/runtimes/win/lib/net8.0/System.Diagnostics.EventLog.Messages.dll +0 -0
- package/dist/generator/runtimes/win/lib/net8.0/System.Diagnostics.EventLog.dll +0 -0
- package/dist/generator/tr/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/tr/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/tr/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/tr/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/zh-Hans/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/zh-Hans/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/zh-Hans/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/zh-Hans/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/generator/zh-Hant/Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll +0 -0
- package/dist/generator/zh-Hant/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/dist/generator/zh-Hant/Microsoft.CodeAnalysis.Workspaces.resources.dll +0 -0
- package/dist/generator/zh-Hant/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/package.json +67 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
#nullable enable
|
|
5
|
+
|
|
6
|
+
using System;
|
|
7
|
+
using System.Collections;
|
|
8
|
+
using System.Collections.Generic;
|
|
9
|
+
using System.Diagnostics;
|
|
10
|
+
using System.Diagnostics.CodeAnalysis;
|
|
11
|
+
using System.Globalization;
|
|
12
|
+
using System.Linq.Expressions;
|
|
13
|
+
using System.Net.Http;
|
|
14
|
+
using System.Reflection;
|
|
15
|
+
|
|
16
|
+
namespace Azure.Core.Pipeline
|
|
17
|
+
{
|
|
18
|
+
internal readonly struct DiagnosticScope : IDisposable
|
|
19
|
+
{
|
|
20
|
+
private const string AzureSdkScopeLabel = "az.sdk.scope";
|
|
21
|
+
internal const string OpenTelemetrySchemaAttribute = "az.schema_url";
|
|
22
|
+
|
|
23
|
+
// we follow OpenTelemtery Semantic Conventions 1.23.0
|
|
24
|
+
// https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0
|
|
25
|
+
internal const string OpenTelemetrySchemaVersion = "https://opentelemetry.io/schemas/1.23.0";
|
|
26
|
+
private static readonly object AzureSdkScopeValue = bool.TrueString;
|
|
27
|
+
private readonly ActivityAdapter? _activityAdapter;
|
|
28
|
+
private readonly bool _suppressNestedClientActivities;
|
|
29
|
+
|
|
30
|
+
[RequiresUnreferencedCode("The diagnosticSourceArgs are used in a call to DiagnosticSource.Write, all necessary properties need to be preserved on the type being passed in using DynamicDependency attributes.")]
|
|
31
|
+
internal DiagnosticScope(string scopeName, DiagnosticListener source, object? diagnosticSourceArgs, ActivitySource? activitySource, System.Diagnostics.ActivityKind kind, bool suppressNestedClientActivities)
|
|
32
|
+
{
|
|
33
|
+
// ActivityKind.Internal and Client both can represent public API calls depending on the SDK
|
|
34
|
+
_suppressNestedClientActivities = (kind == ActivityKind.Client || kind == System.Diagnostics.ActivityKind.Internal) ? suppressNestedClientActivities : false;
|
|
35
|
+
|
|
36
|
+
// outer scope presence is enough to suppress any inner scope, regardless of inner scope configuation.
|
|
37
|
+
bool hasListeners;
|
|
38
|
+
hasListeners = activitySource?.HasListeners() ?? false;
|
|
39
|
+
IsEnabled = source.IsEnabled() || hasListeners;
|
|
40
|
+
|
|
41
|
+
if (_suppressNestedClientActivities)
|
|
42
|
+
{
|
|
43
|
+
IsEnabled &= !AzureSdkScopeValue.Equals(Activity.Current?.GetCustomProperty(AzureSdkScopeLabel));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_activityAdapter = IsEnabled ? new ActivityAdapter(
|
|
47
|
+
activitySource: activitySource,
|
|
48
|
+
diagnosticSource: source,
|
|
49
|
+
activityName: scopeName,
|
|
50
|
+
kind: kind,
|
|
51
|
+
diagnosticSourceArgs: diagnosticSourceArgs) : null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public bool IsEnabled { get; }
|
|
55
|
+
|
|
56
|
+
public void AddAttribute(string name, string? value)
|
|
57
|
+
{
|
|
58
|
+
if (value != null)
|
|
59
|
+
{
|
|
60
|
+
_activityAdapter?.AddTag(name, value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public void AddIntegerAttribute(string name, int value)
|
|
65
|
+
{
|
|
66
|
+
_activityAdapter?.AddTag(name, value);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public void AddLongAttribute(string name, long value)
|
|
70
|
+
{
|
|
71
|
+
_activityAdapter?.AddTag(name, value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public void AddAttribute<T>(string name, T value, Func<T, string> format)
|
|
75
|
+
{
|
|
76
|
+
if (_activityAdapter != null && value != null)
|
|
77
|
+
{
|
|
78
|
+
var formattedValue = format(value);
|
|
79
|
+
_activityAdapter.AddTag(name, formattedValue);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/// <summary>
|
|
84
|
+
/// Adds a link to the scope. This must be called before <see cref="Start"/> has been called for the DiagnosticScope.
|
|
85
|
+
/// </summary>
|
|
86
|
+
/// <param name="traceparent">The traceparent for the link.</param>
|
|
87
|
+
/// <param name="tracestate">The tracestate for the link.</param>
|
|
88
|
+
/// <param name="attributes">Optional attributes to associate with the link.</param>
|
|
89
|
+
public void AddLink(string traceparent, string? tracestate, IDictionary<string, object?>? attributes = null)
|
|
90
|
+
{
|
|
91
|
+
_activityAdapter?.AddLink(traceparent, tracestate, attributes);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public void Start()
|
|
95
|
+
{
|
|
96
|
+
Activity? started = _activityAdapter?.Start();
|
|
97
|
+
if (_suppressNestedClientActivities)
|
|
98
|
+
{
|
|
99
|
+
started?.SetCustomProperty(AzureSdkScopeLabel, AzureSdkScopeValue);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public void SetDisplayName(string displayName)
|
|
104
|
+
{
|
|
105
|
+
_activityAdapter?.SetDisplayName(displayName);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public void SetStartTime(DateTime dateTime)
|
|
109
|
+
{
|
|
110
|
+
_activityAdapter?.SetStartTime(dateTime);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// <summary>
|
|
114
|
+
/// Sets the trace context for the current scope.
|
|
115
|
+
/// </summary>
|
|
116
|
+
/// <param name="traceparent">The trace parent to set for the current scope.</param>
|
|
117
|
+
/// <param name="tracestate">The trace state to set for the current scope.</param>
|
|
118
|
+
public void SetTraceContext(string traceparent, string? tracestate = default)
|
|
119
|
+
{
|
|
120
|
+
_activityAdapter?.SetTraceContext(traceparent, tracestate);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public void Dispose()
|
|
124
|
+
{
|
|
125
|
+
// Reverse the Start order
|
|
126
|
+
_activityAdapter?.Dispose();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// <summary>
|
|
130
|
+
/// Marks the scope as failed.
|
|
131
|
+
/// </summary>
|
|
132
|
+
/// <param name="exception">The exception to associate with the failed scope.</param>
|
|
133
|
+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "The Exception being passed into this method has public properties preserved on the inner method MarkFailed." +
|
|
134
|
+
"The public property System.Exception.TargetSite.get is not compatible with trimming and produces a warning when preserving all public properties. Since we do not use this property, and" +
|
|
135
|
+
"neither does Application Insights, we can suppress the warning coming from the inner method.")]
|
|
136
|
+
public void Failed(Exception exception)
|
|
137
|
+
{
|
|
138
|
+
if (exception is RequestFailedException requestFailedException)
|
|
139
|
+
{
|
|
140
|
+
// TODO (limolkova) when we start targeting .NET 8 we should put
|
|
141
|
+
// requestFailedException.InnerException.HttpRequestError into error.type
|
|
142
|
+
|
|
143
|
+
string? errorCode = string.IsNullOrEmpty(requestFailedException.ErrorCode) ? null : requestFailedException.ErrorCode;
|
|
144
|
+
_activityAdapter?.MarkFailed(exception, errorCode);
|
|
145
|
+
}
|
|
146
|
+
else
|
|
147
|
+
{
|
|
148
|
+
_activityAdapter?.MarkFailed(exception, null);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// <summary>
|
|
153
|
+
/// Marks the scope as failed with low-cardinality error.type attribute.
|
|
154
|
+
/// </summary>
|
|
155
|
+
/// <param name="errorCode">Error code to associate with the failed scope.</param>
|
|
156
|
+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "The public property System.Exception.TargetSite.get is not compatible with trimming and produces a warning when " +
|
|
157
|
+
"preserving all public properties. Since we do not use this property, and neither does Application Insights, we can suppress the warning coming from the inner method.")]
|
|
158
|
+
public void Failed(string errorCode)
|
|
159
|
+
{
|
|
160
|
+
_activityAdapter?.MarkFailed((Exception?)null, errorCode);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private class DiagnosticActivity : Activity
|
|
164
|
+
{
|
|
165
|
+
#pragma warning disable 109 // extra new modifier
|
|
166
|
+
public new IEnumerable<Activity> Links { get; set; } = Array.Empty<Activity>();
|
|
167
|
+
#pragma warning restore 109
|
|
168
|
+
|
|
169
|
+
public DiagnosticActivity(string operationName) : base(operationName)
|
|
170
|
+
{
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private class ActivityAdapter : IDisposable
|
|
175
|
+
{
|
|
176
|
+
private readonly ActivitySource? _activitySource;
|
|
177
|
+
private readonly DiagnosticSource _diagnosticSource;
|
|
178
|
+
private readonly string _activityName;
|
|
179
|
+
private readonly System.Diagnostics.ActivityKind _kind;
|
|
180
|
+
private readonly object? _diagnosticSourceArgs;
|
|
181
|
+
|
|
182
|
+
private Activity? _currentActivity;
|
|
183
|
+
private Activity? _sampleOutActivity;
|
|
184
|
+
|
|
185
|
+
private ActivityTagsCollection? _tagCollection;
|
|
186
|
+
private DateTimeOffset _startTime;
|
|
187
|
+
private List<ActivityLink>? _links;
|
|
188
|
+
private string? _traceparent;
|
|
189
|
+
private string? _tracestate;
|
|
190
|
+
private string? _displayName;
|
|
191
|
+
|
|
192
|
+
public ActivityAdapter(ActivitySource? activitySource, DiagnosticSource diagnosticSource, string activityName, System.Diagnostics.ActivityKind kind, object? diagnosticSourceArgs)
|
|
193
|
+
{
|
|
194
|
+
_activitySource = activitySource;
|
|
195
|
+
_diagnosticSource = diagnosticSource;
|
|
196
|
+
_activityName = activityName;
|
|
197
|
+
_kind = kind;
|
|
198
|
+
_diagnosticSourceArgs = diagnosticSourceArgs;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public void AddTag(string name, object value)
|
|
202
|
+
{
|
|
203
|
+
if (_sampleOutActivity == null)
|
|
204
|
+
{
|
|
205
|
+
if (_currentActivity == null)
|
|
206
|
+
{
|
|
207
|
+
// Activity is not started yet, add the value to the collection
|
|
208
|
+
// that is going to be passed to StartActivity
|
|
209
|
+
_tagCollection ??= new ActivityTagsCollection();
|
|
210
|
+
_tagCollection[name] = value!;
|
|
211
|
+
}
|
|
212
|
+
else
|
|
213
|
+
{
|
|
214
|
+
AddObjectTag(name, value);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private IReadOnlyList<Activity> GetDiagnosticSourceLinkCollection()
|
|
220
|
+
{
|
|
221
|
+
if (_links == null)
|
|
222
|
+
{
|
|
223
|
+
return Array.Empty<Activity>();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
var linkCollection = new List<Activity>();
|
|
227
|
+
|
|
228
|
+
foreach (var link in _links)
|
|
229
|
+
{
|
|
230
|
+
var activity = new Activity("LinkedActivity");
|
|
231
|
+
activity.SetIdFormat(ActivityIdFormat.W3C);
|
|
232
|
+
if (link.Context != default)
|
|
233
|
+
{
|
|
234
|
+
activity.SetParentId(ActivityContextToTraceParent(link.Context));
|
|
235
|
+
activity.TraceStateString = link.Context.TraceState;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (link.Tags != null)
|
|
239
|
+
{
|
|
240
|
+
foreach (var tag in link.Tags)
|
|
241
|
+
{
|
|
242
|
+
if (tag.Value != null)
|
|
243
|
+
{
|
|
244
|
+
// old code path, only string attributes are supported
|
|
245
|
+
activity.AddTag(tag.Key, tag.Value.ToString());
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
linkCollection.Add(activity);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return linkCollection;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private static string ActivityContextToTraceParent(ActivityContext context)
|
|
256
|
+
{
|
|
257
|
+
string flags = (context.TraceFlags == ActivityTraceFlags.None) ? "00" : "01";
|
|
258
|
+
return "00-" + context.TraceId + "-" + context.SpanId + "-" + flags;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
public void AddLink(string traceparent, string? tracestate, IDictionary<string, object?>? attributes)
|
|
262
|
+
{
|
|
263
|
+
// if context is invalid, we should still add a link since it contains attributes
|
|
264
|
+
// so we let ActivityLink deal with the default context.
|
|
265
|
+
// This is otel spec requirement and default context is allowed on links.
|
|
266
|
+
ActivityContext.TryParse(traceparent, tracestate, out var context);
|
|
267
|
+
var linkedActivity = new ActivityLink(context, attributes == null ? null : new ActivityTagsCollection(attributes));
|
|
268
|
+
_links ??= new List<ActivityLink>();
|
|
269
|
+
_links.Add(linkedActivity);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicMethods, typeof(Activity))]
|
|
273
|
+
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicMethods, typeof(DiagnosticActivity))]
|
|
274
|
+
public Activity? Start()
|
|
275
|
+
{
|
|
276
|
+
_currentActivity = StartActivitySourceActivity();
|
|
277
|
+
if (_currentActivity != null)
|
|
278
|
+
{
|
|
279
|
+
if (!_currentActivity.IsAllDataRequested)
|
|
280
|
+
{
|
|
281
|
+
_sampleOutActivity = _currentActivity;
|
|
282
|
+
_currentActivity = null;
|
|
283
|
+
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
_currentActivity.SetTag(OpenTelemetrySchemaAttribute, OpenTelemetrySchemaVersion);
|
|
288
|
+
}
|
|
289
|
+
else
|
|
290
|
+
{
|
|
291
|
+
if (!_diagnosticSource.IsEnabled(_activityName, _diagnosticSourceArgs))
|
|
292
|
+
{
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
switch (_kind)
|
|
297
|
+
{
|
|
298
|
+
case ActivityKind.Internal:
|
|
299
|
+
AddTag("kind", "internal");
|
|
300
|
+
break;
|
|
301
|
+
case ActivityKind.Server:
|
|
302
|
+
AddTag("kind", "server");
|
|
303
|
+
break;
|
|
304
|
+
case ActivityKind.Client:
|
|
305
|
+
AddTag("kind", "client");
|
|
306
|
+
break;
|
|
307
|
+
case ActivityKind.Producer:
|
|
308
|
+
AddTag("kind", "producer");
|
|
309
|
+
break;
|
|
310
|
+
case ActivityKind.Consumer:
|
|
311
|
+
AddTag("kind", "consumer");
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
_currentActivity = new DiagnosticActivity(_activityName)
|
|
316
|
+
{
|
|
317
|
+
Links = GetDiagnosticSourceLinkCollection(),
|
|
318
|
+
};
|
|
319
|
+
_currentActivity.SetIdFormat(ActivityIdFormat.W3C);
|
|
320
|
+
|
|
321
|
+
if (_startTime != default)
|
|
322
|
+
{
|
|
323
|
+
_currentActivity.SetStartTime(_startTime.UtcDateTime);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (_tagCollection != null)
|
|
327
|
+
{
|
|
328
|
+
foreach (var tag in _tagCollection)
|
|
329
|
+
{
|
|
330
|
+
AddObjectTag(tag.Key, tag.Value!);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (_traceparent != null)
|
|
335
|
+
{
|
|
336
|
+
_currentActivity.SetParentId(_traceparent);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (_tracestate != null)
|
|
340
|
+
{
|
|
341
|
+
_currentActivity.TraceStateString = _tracestate;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
_currentActivity.Start();
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
WriteStartEvent();
|
|
348
|
+
|
|
349
|
+
if (_displayName != null)
|
|
350
|
+
{
|
|
351
|
+
_currentActivity.DisplayName = _displayName;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return _currentActivity;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "The values being passed into Write have the commonly used properties being preserved with DynamicDependency on the ActivityAdapter.Start() method, or the responsibility is on the user of this struct since the struct constructor is marked with RequiresUnreferencedCode.")]
|
|
358
|
+
private void WriteStartEvent()
|
|
359
|
+
{
|
|
360
|
+
_diagnosticSource.Write(_activityName + ".Start", _diagnosticSourceArgs ?? _currentActivity);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
public void SetDisplayName(string displayName)
|
|
364
|
+
{
|
|
365
|
+
_displayName = displayName;
|
|
366
|
+
if (_currentActivity != null)
|
|
367
|
+
{
|
|
368
|
+
_currentActivity.DisplayName = _displayName;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
private Activity? StartActivitySourceActivity()
|
|
373
|
+
{
|
|
374
|
+
if (_activitySource == null)
|
|
375
|
+
{
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
// TODO(limolkova) set isRemote to true once we switch to DiagnosticSource 7.0
|
|
379
|
+
ActivityContext.TryParse(_traceparent, _tracestate, out ActivityContext context);
|
|
380
|
+
return _activitySource.StartActivity(_activityName, _kind, context, _tagCollection, _links, _startTime);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
public void SetStartTime(DateTime startTime)
|
|
384
|
+
{
|
|
385
|
+
_startTime = startTime;
|
|
386
|
+
_currentActivity?.SetStartTime(startTime);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "The Exception being passed into this method has the commonly used properties being preserved with DynamicallyAccessedMemberTypes.")]
|
|
390
|
+
public void MarkFailed<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(T? exception, string? errorCode)
|
|
391
|
+
{
|
|
392
|
+
if (exception != null)
|
|
393
|
+
{
|
|
394
|
+
_diagnosticSource?.Write(_activityName + ".Exception", exception);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (errorCode == null && exception != null)
|
|
398
|
+
{
|
|
399
|
+
errorCode = exception.GetType().FullName;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
errorCode ??= "_OTHER";
|
|
403
|
+
|
|
404
|
+
// SetStatus is only defined in NET 6 or greater
|
|
405
|
+
_currentActivity?.SetTag("error.type", errorCode);
|
|
406
|
+
_currentActivity?.SetStatus(ActivityStatusCode.Error, exception?.ToString());
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
public void SetTraceContext(string traceparent, string? tracestate)
|
|
410
|
+
{
|
|
411
|
+
if (_currentActivity != null)
|
|
412
|
+
{
|
|
413
|
+
throw new InvalidOperationException("Traceparent can not be set after the activity is started.");
|
|
414
|
+
}
|
|
415
|
+
_traceparent = traceparent;
|
|
416
|
+
_tracestate = tracestate;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private void AddObjectTag(string name, object value)
|
|
420
|
+
{
|
|
421
|
+
if (_activitySource?.HasListeners() == true)
|
|
422
|
+
{
|
|
423
|
+
_currentActivity?.SetTag(name, value);
|
|
424
|
+
}
|
|
425
|
+
else
|
|
426
|
+
{
|
|
427
|
+
_currentActivity?.AddTag(name, value.ToString());
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The class constructor is marked with RequiresUnreferencedCode.")]
|
|
432
|
+
public void Dispose()
|
|
433
|
+
{
|
|
434
|
+
var activity = _currentActivity ?? _sampleOutActivity;
|
|
435
|
+
if (activity == null)
|
|
436
|
+
{
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (activity.Duration == TimeSpan.Zero)
|
|
441
|
+
activity.SetEndTime(DateTime.UtcNow);
|
|
442
|
+
|
|
443
|
+
_diagnosticSource.Write(_activityName + ".Stop", _diagnosticSourceArgs);
|
|
444
|
+
|
|
445
|
+
activity.Dispose();
|
|
446
|
+
|
|
447
|
+
_currentActivity = null;
|
|
448
|
+
_sampleOutActivity = null;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
#pragma warning disable SA1507 // File can not contain multiple types
|
|
454
|
+
/// <summary>
|
|
455
|
+
/// Until Activity Source is no longer considered experimental.
|
|
456
|
+
/// </summary>
|
|
457
|
+
internal static class ActivityExtensions
|
|
458
|
+
{
|
|
459
|
+
static ActivityExtensions()
|
|
460
|
+
{
|
|
461
|
+
ResetFeatureSwitch();
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
public static bool SupportsActivitySource { get; private set; }
|
|
465
|
+
|
|
466
|
+
public static void ResetFeatureSwitch()
|
|
467
|
+
{
|
|
468
|
+
SupportsActivitySource = AppContextSwitchHelper.GetConfigValue(
|
|
469
|
+
"Azure.Experimental.EnableActivitySource",
|
|
470
|
+
"AZURE_EXPERIMENTAL_ENABLE_ACTIVITY_SOURCE");
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
using System;
|
|
5
|
+
using System.Collections.Concurrent;
|
|
6
|
+
using System.Collections.Generic;
|
|
7
|
+
using System.Diagnostics;
|
|
8
|
+
using System.Diagnostics.CodeAnalysis;
|
|
9
|
+
using System.Threading;
|
|
10
|
+
|
|
11
|
+
#nullable enable
|
|
12
|
+
|
|
13
|
+
namespace Azure.Core.Pipeline
|
|
14
|
+
{
|
|
15
|
+
#pragma warning disable CA1001 // Types that own disposable fields should be disposable
|
|
16
|
+
internal class DiagnosticScopeFactory
|
|
17
|
+
#pragma warning restore CA1001 // Types that own disposable fields should be disposable
|
|
18
|
+
{
|
|
19
|
+
private static Dictionary<string, DiagnosticListener>? _listeners;
|
|
20
|
+
private readonly string? _resourceProviderNamespace;
|
|
21
|
+
private readonly DiagnosticListener? _source;
|
|
22
|
+
private readonly bool _suppressNestedClientActivities;
|
|
23
|
+
private readonly bool _isStable;
|
|
24
|
+
private static readonly ConcurrentDictionary<string, ActivitySource?> ActivitySources = new();
|
|
25
|
+
|
|
26
|
+
/// <summary>
|
|
27
|
+
/// Creates diagnostic scope factory.
|
|
28
|
+
/// </summary>
|
|
29
|
+
/// <param name="clientNamespace">The namespace which is used as a prefix for all ActivitySources created by the factory and the name of DiagnosticSource (when used).</param>
|
|
30
|
+
/// <param name="resourceProviderNamespace">Azure resource provider namespace.</param>
|
|
31
|
+
/// <param name="isActivityEnabled">Flag indicating if distributed tracing is enabled.</param>
|
|
32
|
+
/// <param name="suppressNestedClientActivities">Flag indicating if nested Azure SDK activities describing public API calls should be suppressed.</param>
|
|
33
|
+
/// <param name="isStable">Whether instrumentation is considered stable. When false, experimental feature flag controls if tracing is enabled.</param>
|
|
34
|
+
public DiagnosticScopeFactory(string clientNamespace, string? resourceProviderNamespace, bool isActivityEnabled, bool suppressNestedClientActivities = true, bool isStable = false)
|
|
35
|
+
{
|
|
36
|
+
_resourceProviderNamespace = resourceProviderNamespace;
|
|
37
|
+
IsActivityEnabled = isActivityEnabled;
|
|
38
|
+
_suppressNestedClientActivities = suppressNestedClientActivities;
|
|
39
|
+
_isStable = isStable;
|
|
40
|
+
|
|
41
|
+
if (IsActivityEnabled)
|
|
42
|
+
{
|
|
43
|
+
var listeners = LazyInitializer.EnsureInitialized(ref _listeners);
|
|
44
|
+
|
|
45
|
+
lock (listeners!)
|
|
46
|
+
{
|
|
47
|
+
if (!listeners.TryGetValue(clientNamespace, out _source))
|
|
48
|
+
{
|
|
49
|
+
_source = new DiagnosticListener(clientNamespace);
|
|
50
|
+
listeners[clientNamespace] = _source;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public bool IsActivityEnabled { get; }
|
|
57
|
+
|
|
58
|
+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The DiagnosticScope constructor is marked as RequiresUnreferencedCode because of the usage of the diagnosticSourceArgs parameter. Since we are passing in null here we can suppress this warning.")]
|
|
59
|
+
public DiagnosticScope CreateScope(string name, System.Diagnostics.ActivityKind kind = ActivityKind.Internal)
|
|
60
|
+
{
|
|
61
|
+
if (_source == null)
|
|
62
|
+
{
|
|
63
|
+
return default;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var scope = new DiagnosticScope(
|
|
67
|
+
scopeName: name,
|
|
68
|
+
source: _source,
|
|
69
|
+
diagnosticSourceArgs: null,
|
|
70
|
+
activitySource: GetActivitySource(_source.Name, name),
|
|
71
|
+
kind: kind,
|
|
72
|
+
suppressNestedClientActivities: _suppressNestedClientActivities);
|
|
73
|
+
|
|
74
|
+
if (_resourceProviderNamespace != null)
|
|
75
|
+
{
|
|
76
|
+
scope.AddAttribute("az.namespace", _resourceProviderNamespace);
|
|
77
|
+
}
|
|
78
|
+
return scope;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// <summary>
|
|
82
|
+
/// This method combines client namespace and operation name into an ActivitySource name and creates the activity source.
|
|
83
|
+
/// For example:
|
|
84
|
+
/// ns: Azure.Storage.Blobs
|
|
85
|
+
/// name: BlobClient.DownloadTo
|
|
86
|
+
/// result Azure.Storage.Blobs.BlobClient
|
|
87
|
+
/// </summary>
|
|
88
|
+
private ActivitySource? GetActivitySource(string ns, string name)
|
|
89
|
+
{
|
|
90
|
+
bool enabled = _isStable;
|
|
91
|
+
enabled |= ActivityExtensions.SupportsActivitySource;
|
|
92
|
+
|
|
93
|
+
if (!enabled)
|
|
94
|
+
{
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
int indexOfDot = name.IndexOf(".", StringComparison.OrdinalIgnoreCase);
|
|
99
|
+
string clientName = ns + "." + ((indexOfDot < 0) ? name : name.Substring(0, indexOfDot));
|
|
100
|
+
|
|
101
|
+
return ActivitySources.GetOrAdd(clientName, static n => new ActivitySource(n));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
using System;
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Azure.Core
|
|
9
|
+
{
|
|
10
|
+
/// <summary>
|
|
11
|
+
/// A delay strategy that uses a fixed delay with no jitter applied. This is used by data plane LROs.
|
|
12
|
+
/// </summary>
|
|
13
|
+
internal class FixedDelayWithNoJitterStrategy : DelayStrategy
|
|
14
|
+
{
|
|
15
|
+
private static readonly TimeSpan DefaultDelay = TimeSpan.FromSeconds(1);
|
|
16
|
+
private readonly TimeSpan _delay;
|
|
17
|
+
|
|
18
|
+
public FixedDelayWithNoJitterStrategy(TimeSpan? suggestedDelay = default) : base(suggestedDelay.HasValue ? Max(suggestedDelay.Value, DefaultDelay) : DefaultDelay, 0)
|
|
19
|
+
{
|
|
20
|
+
_delay = suggestedDelay.HasValue ? Max(suggestedDelay.Value, DefaultDelay) : DefaultDelay;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected override TimeSpan GetNextDelayCore(Response? response, int retryNumber) =>
|
|
24
|
+
_delay;
|
|
25
|
+
}
|
|
26
|
+
}
|