This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding client version telemetry while creating a new connection (#253)
Adding client version telemetry while creating a new connection for the service to keep a track.
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.Azure.ServiceBus.Primitives | ||
{ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.Versioning; | ||
|
||
internal static class ClientInfo | ||
{ | ||
internal static readonly string Product; | ||
internal static readonly string Version; | ||
internal static readonly string Framework; | ||
internal static readonly string Platform; | ||
|
||
static ClientInfo() | ||
{ | ||
try | ||
{ | ||
Assembly assembly = typeof(ClientInfo).GetTypeInfo().Assembly; | ||
Product = GetAssemblyAttributeValue<AssemblyProductAttribute>(assembly, p => p.Product); | ||
Version = GetAssemblyAttributeValue<AssemblyFileVersionAttribute>(assembly, v => v.Version); | ||
Framework = GetAssemblyAttributeValue<TargetFrameworkAttribute>(assembly, f => f.FrameworkName); | ||
#if NETSTANDARD1_3 | ||
Platform = System.Runtime.InteropServices.RuntimeInformation.OSDescription; | ||
#elif UAP10_0 | ||
Platform = "UAP"; | ||
#elif NET451 | ||
Platform = Environment.OSVersion.VersionString; | ||
#else | ||
Platform = "Unknown"; | ||
#endif | ||
} | ||
catch | ||
{ | ||
// ignored | ||
} | ||
} | ||
|
||
static string GetAssemblyAttributeValue<T>(Assembly assembly, Func<T, string> getter) where T : Attribute | ||
{ | ||
var attribute = assembly.GetCustomAttribute(typeof(T)) as T; | ||
return attribute == null ? null : getter(attribute); | ||
} | ||
} | ||
} |