Skip to content

Commit

Permalink
Merge pull request #1 from stankovski/master
Browse files Browse the repository at this point in the history
Added ClientRuntime library; will address comments related to build task in a separate PR
  • Loading branch information
stankovski committed Feb 23, 2015
2 parents 13f0e4f + 15012b3 commit 0236e2c
Show file tree
Hide file tree
Showing 94 changed files with 7,427 additions and 0 deletions.
90 changes: 90 additions & 0 deletions ClientRuntime.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft.Rest", "Microsoft.Rest", "{868850B4-1073-41A1-ABA8-A3B465880148}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{7C044DD1-F76B-49A7-A8DF-A5DEEE748EBB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "git", "git", "{EAC2DE24-42C6-4B7F-ACAB-73C0E113FC40}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientRuntime", "Microsoft.Rest\ClientRuntime\ClientRuntime.csproj", "{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientRuntime.Etw", "Microsoft.Rest\ClientRuntime.Etw\ClientRuntime.Etw.csproj", "{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientRuntime.Log4Net", "Microsoft.Rest\ClientRuntime.Log4Net\ClientRuntime.Log4Net.csproj", "{2EFD6648-39B4-476A-B302-8BC236F5F1B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientRuntime.Tracing.Tests", "Microsoft.Rest\ClientRuntime.Tracing.Tests\ClientRuntime.Tracing.Tests.csproj", "{B2FAA0E6-2643-4011-8CFE-BA28BDFFC7E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientRuntime.Tests", "Microsoft.Rest\ClientRuntime.Tests\ClientRuntime.Tests.csproj", "{CB18ACEB-2825-4884-91FA-05C31AC779FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Net40-Debug|Any CPU = Net40-Debug|Any CPU
Net40-Release|Any CPU = Net40-Release|Any CPU
Net45-Debug|Any CPU = Net45-Debug|Any CPU
Net45-Release|Any CPU = Net45-Release|Any CPU
Portable-Debug|Any CPU = Portable-Debug|Any CPU
Portable-Release|Any CPU = Portable-Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Net40-Debug|Any CPU.Build.0 = Net40-Debug|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Net40-Release|Any CPU.Build.0 = Net40-Release|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU
{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{2EFD6648-39B4-476A-B302-8BC236F5F1B8}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{2EFD6648-39B4-476A-B302-8BC236F5F1B8}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
{2EFD6648-39B4-476A-B302-8BC236F5F1B8}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{2EFD6648-39B4-476A-B302-8BC236F5F1B8}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{2EFD6648-39B4-476A-B302-8BC236F5F1B8}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{2EFD6648-39B4-476A-B302-8BC236F5F1B8}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{2EFD6648-39B4-476A-B302-8BC236F5F1B8}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{2EFD6648-39B4-476A-B302-8BC236F5F1B8}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{B2FAA0E6-2643-4011-8CFE-BA28BDFFC7E7}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{B2FAA0E6-2643-4011-8CFE-BA28BDFFC7E7}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
{B2FAA0E6-2643-4011-8CFE-BA28BDFFC7E7}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{B2FAA0E6-2643-4011-8CFE-BA28BDFFC7E7}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{B2FAA0E6-2643-4011-8CFE-BA28BDFFC7E7}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{B2FAA0E6-2643-4011-8CFE-BA28BDFFC7E7}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{B2FAA0E6-2643-4011-8CFE-BA28BDFFC7E7}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{B2FAA0E6-2643-4011-8CFE-BA28BDFFC7E7}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{CB18ACEB-2825-4884-91FA-05C31AC779FE}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{CB18ACEB-2825-4884-91FA-05C31AC779FE}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
{CB18ACEB-2825-4884-91FA-05C31AC779FE}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{CB18ACEB-2825-4884-91FA-05C31AC779FE}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{CB18ACEB-2825-4884-91FA-05C31AC779FE}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{CB18ACEB-2825-4884-91FA-05C31AC779FE}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{CB18ACEB-2825-4884-91FA-05C31AC779FE}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{CB18ACEB-2825-4884-91FA-05C31AC779FE}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7F524559-93F9-4F3F-9E2C-AF41A0C2E6F4} = {868850B4-1073-41A1-ABA8-A3B465880148}
{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E} = {868850B4-1073-41A1-ABA8-A3B465880148}
{2EFD6648-39B4-476A-B302-8BC236F5F1B8} = {868850B4-1073-41A1-ABA8-A3B465880148}
{B2FAA0E6-2643-4011-8CFE-BA28BDFFC7E7} = {7C044DD1-F76B-49A7-A8DF-A5DEEE748EBB}
{CB18ACEB-2825-4884-91FA-05C31AC779FE} = {7C044DD1-F76B-49A7-A8DF-A5DEEE748EBB}
EndGlobalSection
EndGlobal
62 changes: 62 additions & 0 deletions Microsoft.Rest/ClientRuntime.Etw/ClientRuntime.Etw.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<LibraryFxTarget Condition="'$(LibraryFxTarget)' == ''">net45</LibraryFxTarget>
<ProjectGuid>{50B0A8CE-D290-4EB7-8C6C-16EAAB75225E}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Rest.Common.Tracing.Etw</RootNamespace>
<AssemblyName>Microsoft.Rest.ClientRuntime.Etw</AssemblyName>
<OutputType>Library</OutputType>
<RestorePackages>true</RestorePackages>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NuGetPackageImportStamp>644881db</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Net45-Debug'">
<DocumentationFile>bin\Net45-Debug\Microsoft.Rest.ClientRuntime.Etw.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Net45-Release'">
<DocumentationFile>bin\Net45-Release\Microsoft.Rest.ClientRuntime.Etw.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Net40-Debug'">
<DocumentationFile>bin\Net40-Debug\Microsoft.Rest.ClientRuntime.Etw.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Net40-Release'">
<DocumentationFile>bin\Net40-Release\Microsoft.Rest.ClientRuntime.Etw.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Portable-Debug'">
<DocumentationFile>bin\Portable-Debug\Microsoft.Rest.ClientRuntime.Etw.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Portable-Release'">
<DocumentationFile>bin\Portable-Release\Microsoft.Rest.ClientRuntime.Etw.xml</DocumentationFile>
</PropertyGroup>
<Import Project="$(SolutionDir)\tools\AutoRest.Settings.targets" />
<ItemGroup>
<Compile Include="HttpOperationEventSource.cs" />
<Compile Include="EtwTracingInterceptor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Microsoft.Rest.ClientRuntime.Etw.nuget.proj" />
<None Include="Microsoft.Rest.ClientRuntime.Etw.nuspec">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ClientRuntime\ClientRuntime.csproj">
<Project>{7f524559-93f9-4f3f-9e2c-af41a0c2e6f4}</Project>
<Name>ClientRuntime</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\..\tools\CustomDictionary.xml">
<Link>CustomDictionary.xml</Link>
</CodeAnalysisDictionary>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
112 changes: 112 additions & 0 deletions Microsoft.Rest/ClientRuntime.Etw/EtwTracingInterceptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Net.Http;

namespace Microsoft.Rest.Tracing.Etw
{
/// <summary>
/// Implementation for IServiceClientTracingInterceptor that raises ETW events.
/// </summary>
/// <remarks>
/// To use ETW with the Microsoft AutoRest generated client:
/// 1. Register the logger.
/// 2. Use tools such as PerfView to capture events under the
/// Microsoft.Rest provider.
/// </remarks>
/// <example>
/// This shows how to hook up the tracing interceptor.
/// <code>
/// TracingAdapter.AddTracingInterceptor(
/// new EtwTracingInterceptor());
/// </code>
/// </example>
public class EtwTracingInterceptor : IServiceClientTracingInterceptor
{
/// <summary>
/// Trace information.
/// </summary>
/// <param name="message">The information to trace.</param>
public void Information(string message)
{
HttpOperationEventSource.Log.Information(message);
}

/// <summary>
/// Probe configuration for the value of a setting.
/// </summary>
/// <param name="source">The configuration source.</param>
/// <param name="name">The name of the setting.</param>
/// <param name="value">The value of the setting in the source.</param>
public void Configuration(string source, string name, string value)
{
HttpOperationEventSource.Log.Configuration(source, name, value);
}

/// <summary>
/// Enter a method.
/// </summary>
/// <param name="invocationId">Method invocation identifier.</param>
/// <param name="instance">The instance with the method.</param>
/// <param name="method">Name of the method.</param>
/// <param name="parameters">Method parameters.</param>
public void Enter(string invocationId, object instance, string method, IDictionary<string, object> parameters)
{
string instanceAsString = instance == null ? string.Empty : instance.ToString();
string parametersAsString = parameters == null ? string.Empty : parameters.AsFormattedString();

HttpOperationEventSource.Log.Enter(invocationId, instanceAsString, method, parametersAsString);
}

/// <summary>
/// Send an HTTP request.
/// </summary>
/// <param name="invocationId">Method invocation identifier.</param>
/// <param name="request">The request about to be sent.</param>
public virtual void SendRequest(string invocationId, HttpRequestMessage request)
{
string requestAsString = request == null ? string.Empty : request.AsFormattedString();

HttpOperationEventSource.Log.SendRequest(invocationId, requestAsString);
}

/// <summary>
/// Receive an HTTP response.
/// </summary>
/// <param name="invocationId">Method invocation identifier.</param>
/// <param name="response">The response instance.</param>
public virtual void ReceiveResponse(string invocationId, HttpResponseMessage response)
{
string responseAsString = response == null ? string.Empty : response.AsFormattedString();

HttpOperationEventSource.Log.ReceiveResponse(invocationId, responseAsString);
}

/// <summary>
/// Raise an error.
/// </summary>
/// <param name="invocationId">Method invocation identifier.</param>
/// <param name="exception">The error.</param>
public void Error(string invocationId, Exception exception)
{
string exceptionAsString = exception == null ? string.Empty : exception.ToString();

HttpOperationEventSource.Log.Error(invocationId, exceptionAsString);
}

/// <summary>
/// Exit a method. Note: Exit will not be called in the event of an
/// error.
/// </summary>
/// <param name="invocationId">Method invocation identifier.</param>
/// <param name="returnValue">Method return value.</param>
public void Exit(string invocationId, object returnValue)
{
string returnValueAsString = returnValue == null ? string.Empty : returnValue.ToString();

HttpOperationEventSource.Log.Exit(invocationId, returnValueAsString);
}
}
}
112 changes: 112 additions & 0 deletions Microsoft.Rest/ClientRuntime.Etw/HttpOperationEventSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Diagnostics.Tracing;

namespace Microsoft.Rest.Tracing.Etw
{
/// <summary>
/// Class that inherits from EventSource and is used as a data model for ETW events.
/// </summary>
[EventSource(Name = "Microsoft.Rest")]
internal sealed class HttpOperationEventSource : EventSource
{
private static HttpOperationEventSource _log;

private HttpOperationEventSource() { }

/// <summary>
/// Gets an instance of the HttpOperationEventSource.
/// </summary>
public static HttpOperationEventSource Log
{
get
{
if (_log == null)
{
_log = new HttpOperationEventSource();
}
return _log;
}
}

/// <summary>
/// Logs information message.
/// </summary>
/// <param name="Message">Message</param>
[Event(1, Level = EventLevel.Informational)]
public void Information(string Message)
{
WriteEvent(1, Message);
}

/// <summary>
/// Logs a configuration event.
/// </summary>
/// <param name="Source">Event source.</param>
/// <param name="Name">Configuration name.</param>
/// <param name="Value">Configuration value.</param>
[Event(2, Level = EventLevel.Informational)]
public void Configuration(string Source, string Name, string Value)
{
WriteEvent(2, Source, Name, Value);
}

/// <summary>
/// Logs method start.
/// </summary>
/// <param name="InvocationId">Correlation ID for a series of events.</param>
/// <param name="Instance">Instance of the method.</param>
/// <param name="Method">Method name.</param>
/// <param name="Parameters">Method parameters passed to the method.</param>
[Event(3, Level = EventLevel.Informational)]
public void Enter(string InvocationId, string Instance, string Method, string Parameters)
{
WriteEvent(3, InvocationId, Instance, Method, Parameters);
}

/// <summary>
/// Logs sending an HTTP request.
/// </summary>
/// <param name="InvocationId">Correlation ID for a series of events.</param>
/// <param name="Request">The request about to be sent.</param>
[Event(4, Level = EventLevel.Informational)]
public void SendRequest(string InvocationId, string Request)
{
WriteEvent(4, InvocationId, Request);
}

/// <summary>
/// Logs receipt of an HTTP response.
/// </summary>
/// <param name="InvocationId">Correlation ID for a series of events.</param>
/// <param name="Response">The response instance.</param>
[Event(5, Level = EventLevel.Informational)]
public void ReceiveResponse(string InvocationId, string Response)
{
WriteEvent(5, InvocationId, Response);
}

/// <summary>
/// Logs an error.
/// </summary>
/// <param name="InvocationId">Correlation ID for a series of events.</param>
/// <param name="Exception">Exception.</param>
[Event(6, Level = EventLevel.Error)]
public void Error(string InvocationId, string Exception)
{
WriteEvent(6, InvocationId, Exception);
}

/// <summary>
/// Logs method exit.
/// </summary>
/// <param name="InvocationId">Correlation ID for a series of events.</param>
/// <param name="ReturnValue">Return value.</param>
[Event(7, Level = EventLevel.Informational)]
public void Exit(string InvocationId, string ReturnValue)
{
WriteEvent(7, InvocationId, ReturnValue);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<SdkNuGetPackage Include="Microsoft.Rest.ClientRuntime.Etw">
<PackageVersion>0.9.0</PackageVersion>
<Folder>$(MSBuildThisFileDirectory)</Folder>
</SdkNuGetPackage>
</ItemGroup>
</Project>
Loading

0 comments on commit 0236e2c

Please sign in to comment.