| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Diagnostics; |
| | 6 | | using System.Reflection; |
| | 7 | |
|
| | 8 | | #nullable enable |
| | 9 | |
|
| | 10 | | namespace Azure.Core.Pipeline |
| | 11 | | { |
| | 12 | | #pragma warning disable CA1001 // Types that own disposable fields should be disposable |
| | 13 | | internal class DiagnosticScopeFactory |
| | 14 | | #pragma warning restore CA1001 // Types that own disposable fields should be disposable |
| | 15 | | { |
| | 16 | | private readonly string? _resourceProviderNamespace; |
| | 17 | | private readonly DiagnosticListener? _source; |
| | 18 | |
|
| 480 | 19 | | public DiagnosticScopeFactory(string clientNamespace, string? resourceProviderNamespace, bool isActivityEnabled) |
| | 20 | | { |
| 480 | 21 | | _resourceProviderNamespace = resourceProviderNamespace; |
| 480 | 22 | | IsActivityEnabled = isActivityEnabled; |
| 480 | 23 | | if (IsActivityEnabled) |
| | 24 | | { |
| 480 | 25 | | _source = new DiagnosticListener(clientNamespace); |
| | 26 | | } |
| 480 | 27 | | } |
| | 28 | |
|
| 480 | 29 | | public bool IsActivityEnabled { get; } |
| | 30 | |
|
| | 31 | | public DiagnosticScope CreateScope(string name) |
| | 32 | | { |
| 7852 | 33 | | if (_source == null) |
| | 34 | | { |
| 0 | 35 | | return default; |
| | 36 | | } |
| 7852 | 37 | | var scope = new DiagnosticScope(name, _source); |
| | 38 | |
|
| 7852 | 39 | | if (_resourceProviderNamespace != null) |
| | 40 | | { |
| 7852 | 41 | | scope.AddAttribute("az.namespace", _resourceProviderNamespace); |
| | 42 | | } |
| 7852 | 43 | | return scope; |
| | 44 | | } |
| | 45 | | } |
| | 46 | | } |