Files
Dan Moseley 042a9d2b2c Reorganize plugins into domain-specific groupings (#274)
* Reorganize plugins per agreed structure (#271)

Split the dotnet plugin into domain-specific plugins per discussion
in #271:

- dotnet: narrowed to common everyday C#/.NET coding tasks
- dotnet-diag: perf investigations, debugging, incident analysis
- dotnet-data: data access and Entity Framework
- dotnet-aspnet, dotnet-wpf, dotnet-winforms, dotnet-maui: scaffolded
  empty to convey intent for future framework-specific skills

Moved skills, tests, and CODEOWNERS entries accordingly.
No file content was changed; all skill/test moves are pure renames.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Improve dotnet-diag and dotnet-winforms descriptions

- dotnet-diag: add '.NET' qualifier to clarify scope
- dotnet-winforms: use official 'Windows Forms (WinForms)' name

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Add .NET qualifier to dotnet-data description

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Remove empty plugins; list them in CONTRIBUTING.md as future options

Remove the four empty placeholder plugins (dotnet-aspnet, dotnet-wpf,
dotnet-winforms, dotnet-maui) that had only plugin.json and no skills.

Add a 'Plugin organization' section to CONTRIBUTING.md that describes the
domain-specific plugin groupings introduced in this PR and lists the four
removed plugin names as reserved candidates for future contributions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Create dotnet-upgrade plugin with migration/upgrade skills

Move migrate-nullable-references, thread-abort-migration, and
dotnet-aot-compat from dotnet to the new dotnet-upgrade plugin.

Update CODEOWNERS paths (same owners), CONTRIBUTING.md plugin table,
and fix the thread-abort-migration SKILL.md link in CONTRIBUTING.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-06 21:01:52 -08:00

104 lines
4.4 KiB
C#

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
#nullable enable
namespace Azure.Core.Pipeline
{
#pragma warning disable CA1001 // Types that own disposable fields should be disposable
internal class DiagnosticScopeFactory
#pragma warning restore CA1001 // Types that own disposable fields should be disposable
{
private static Dictionary<string, DiagnosticListener>? _listeners;
private readonly string? _resourceProviderNamespace;
private readonly DiagnosticListener? _source;
private readonly bool _suppressNestedClientActivities;
private readonly bool _isStable;
private static readonly ConcurrentDictionary<string, ActivitySource?> ActivitySources = new();
/// <summary>
/// Creates diagnostic scope factory.
/// </summary>
/// <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>
/// <param name="resourceProviderNamespace">Azure resource provider namespace.</param>
/// <param name="isActivityEnabled">Flag indicating if distributed tracing is enabled.</param>
/// <param name="suppressNestedClientActivities">Flag indicating if nested Azure SDK activities describing public API calls should be suppressed.</param>
/// <param name="isStable">Whether instrumentation is considered stable. When false, experimental feature flag controls if tracing is enabled.</param>
public DiagnosticScopeFactory(string clientNamespace, string? resourceProviderNamespace, bool isActivityEnabled, bool suppressNestedClientActivities = true, bool isStable = false)
{
_resourceProviderNamespace = resourceProviderNamespace;
IsActivityEnabled = isActivityEnabled;
_suppressNestedClientActivities = suppressNestedClientActivities;
_isStable = isStable;
if (IsActivityEnabled)
{
var listeners = LazyInitializer.EnsureInitialized(ref _listeners);
lock (listeners!)
{
if (!listeners.TryGetValue(clientNamespace, out _source))
{
_source = new DiagnosticListener(clientNamespace);
listeners[clientNamespace] = _source;
}
}
}
}
public bool IsActivityEnabled { get; }
public DiagnosticScope CreateScope(string name, System.Diagnostics.ActivityKind kind = ActivityKind.Internal)
{
if (_source == null)
{
return default;
}
var scope = new DiagnosticScope(
scopeName: name,
source: _source,
diagnosticSourceArgs: null,
activitySource: GetActivitySource(_source.Name, name),
kind: kind,
suppressNestedClientActivities: _suppressNestedClientActivities);
if (_resourceProviderNamespace != null)
{
scope.AddAttribute("az.namespace", _resourceProviderNamespace);
}
return scope;
}
/// <summary>
/// This method combines client namespace and operation name into an ActivitySource name and creates the activity source.
/// For example:
/// ns: Azure.Storage.Blobs
/// name: BlobClient.DownloadTo
/// result Azure.Storage.Blobs.BlobClient
/// </summary>
private ActivitySource? GetActivitySource(string ns, string name)
{
bool enabled = _isStable;
enabled |= ActivityExtensions.SupportsActivitySource;
if (!enabled)
{
return null;
}
int indexOfDot = name.IndexOf(".", StringComparison.OrdinalIgnoreCase);
string clientName = ns + "." + ((indexOfDot < 0) ? name : name.Substring(0, indexOfDot));
return ActivitySources.GetOrAdd(clientName, static n => new ActivitySource(n));
}
}
}