| | 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 | |
|
| 1584 | 19 | | public DiagnosticScopeFactory(string clientNamespace, string? resourceProviderNamespace, bool isActivityEnabled) |
| | 20 | | { |
| 1584 | 21 | | _resourceProviderNamespace = resourceProviderNamespace; |
| 1584 | 22 | | IsActivityEnabled = isActivityEnabled; |
| 1584 | 23 | | if (IsActivityEnabled) |
| | 24 | | { |
| 1584 | 25 | | _source = new DiagnosticListener(clientNamespace); |
| | 26 | | } |
| 1584 | 27 | | } |
| | 28 | |
|
| 1584 | 29 | | public bool IsActivityEnabled { get; } |
| | 30 | |
|
| | 31 | | public DiagnosticScope CreateScope(string name) |
| | 32 | | { |
| 211208 | 33 | | if (_source == null) |
| | 34 | | { |
| 0 | 35 | | return default; |
| | 36 | | } |
| 211208 | 37 | | var scope = new DiagnosticScope(name, _source); |
| | 38 | |
|
| 211208 | 39 | | if (_resourceProviderNamespace != null) |
| | 40 | | { |
| 211208 | 41 | | scope.AddAttribute("az.namespace", _resourceProviderNamespace); |
| | 42 | | } |
| 211208 | 43 | | return scope; |
| | 44 | | } |
| | 45 | | } |
| | 46 | | } |