File: Telemetry\TelemetryFeatureName.cs
Web Access
Project: src\src\roslyn\src\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj (Microsoft.CodeAnalysis.Workspaces)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Microsoft.CodeAnalysis.Telemetry;

/// <summary>
/// Feature name used in telemetry.
/// </summary>
internal readonly struct TelemetryFeatureName
{
    private const string LocalKind = "Local";
    private const string RemoteKind = "Remote";
    private const string ExtensionKind = "Extension";

    // Local services:

    public static readonly TelemetryFeatureName CodeFixProvider = GetClientFeatureName(nameof(CodeFixProvider));
    public static readonly TelemetryFeatureName InlineRename = GetClientFeatureName(nameof(InlineRename));
    public static readonly TelemetryFeatureName LegacySuppressionFix = GetClientFeatureName("TelemetryFeatureName");
    public static readonly TelemetryFeatureName VirtualMemoryNotification = GetClientFeatureName(nameof(VirtualMemoryNotification));
    public static readonly TelemetryFeatureName Workspace = GetClientFeatureName(nameof(Workspace));

    private readonly string _name;
    private readonly string _kind;

    private TelemetryFeatureName(string name, string kind)
    {
        _name = name;
        _kind = kind;
    }

    private static TelemetryFeatureName GetClientFeatureName(string name)
        => new(name, LocalKind);

    public static TelemetryFeatureName GetRemoteFeatureName(string componentName, string serviceName)
        => new(componentName + ":" + serviceName, RemoteKind);

    public static TelemetryFeatureName GetExtensionName(Type type)
        => new(type.Assembly.FullName?.StartsWith("Microsoft.", StringComparison.Ordinal) == true ? type.FullName! : "External",
               ExtensionKind);

    public override string ToString()
        => _kind + ":" + _name;
}