Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Adding client version telemetry while creating a new connection (#253)
Browse files Browse the repository at this point in the history
Adding client version telemetry while creating a new connection for the service to keep a track.
  • Loading branch information
nemakam authored Aug 3, 2017
1 parent 7281112 commit d3305ce
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Microsoft.Azure.ServiceBus/Amqp/AmqpConnectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.Azure.ServiceBus.Amqp
using Microsoft.Azure.Amqp;
using Microsoft.Azure.Amqp.Sasl;
using Microsoft.Azure.Amqp.Transport;
using Microsoft.Azure.ServiceBus.Primitives;

internal class AmqpConnectionHelper
{
Expand Down Expand Up @@ -100,12 +101,17 @@ public static TransportSettings CreateTcpTransportSettings(

public static AmqpConnectionSettings CreateAmqpConnectionSettings(uint maxFrameSize, string containerId, string hostName)
{
AmqpConnectionSettings connectionSettings = new AmqpConnectionSettings
var connectionSettings = new AmqpConnectionSettings
{
MaxFrameSize = maxFrameSize,
ContainerId = containerId,
HostName = hostName
};

connectionSettings.AddProperty("product", ClientInfo.Product);
connectionSettings.AddProperty("version", ClientInfo.Version);
connectionSettings.AddProperty("framework", ClientInfo.Framework);
connectionSettings.AddProperty("platform", ClientInfo.Platform);
return connectionSettings;
}
}
Expand Down
47 changes: 47 additions & 0 deletions src/Microsoft.Azure.ServiceBus/Primitives/ClientInfo.cs
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);
}
}
}

0 comments on commit d3305ce

Please sign in to comment.