Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ASP.NET classic example #97

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Elastic.OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.WorkerService", "ex
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppHost", "examples\AppHost\AppHost.csproj", "{206203BD-3EBA-4E9A-8881-1189D95AB037}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceDefaults", "examples\ServiceDefaults\ServiceDefaults.csproj", "{A3D1ED4D-863B-45D7-9829-305DD33B4CE5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceDefaults", "examples\ServiceDefaults\ServiceDefaults.csproj", "{A3D1ED4D-863B-45D7-9829-305DD33B4CE5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples.AspNetClassicWebApi", "examples\Examples.AspNetClassicWebApi\Examples.AspNetClassicWebApi.csproj", "{65D6E902-642D-41DE-BB40-3CDAD38DC640}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -95,6 +97,10 @@ Global
{A3D1ED4D-863B-45D7-9829-305DD33B4CE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3D1ED4D-863B-45D7-9829-305DD33B4CE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3D1ED4D-863B-45D7-9829-305DD33B4CE5}.Release|Any CPU.Build.0 = Release|Any CPU
{65D6E902-642D-41DE-BB40-3CDAD38DC640}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65D6E902-642D-41DE-BB40-3CDAD38DC640}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65D6E902-642D-41DE-BB40-3CDAD38DC640}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65D6E902-642D-41DE-BB40-3CDAD38DC640}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -109,6 +115,7 @@ Global
{863CAB86-5EB0-4E9F-B01D-F51687EC6597} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9}
{206203BD-3EBA-4E9A-8881-1189D95AB037} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9}
{A3D1ED4D-863B-45D7-9829-305DD33B4CE5} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9}
{65D6E902-642D-41DE-BB40-3CDAD38DC640} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {573B2B5F-8CBB-4D52-A55A-4E65E282AAFB}
Expand Down
13 changes: 13 additions & 0 deletions examples/Examples.AspNetClassicWebApi/App_Start/FilterConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Web.Mvc;

Check failure on line 5 in examples/Examples.AspNetClassicWebApi/App_Start/FilterConfig.cs

View workflow job for this annotation

GitHub Actions / test-windows

The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

namespace Examples.AspNetClassicWebApi;

public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters) =>

Check failure on line 11 in examples/Examples.AspNetClassicWebApi/App_Start/FilterConfig.cs

View workflow job for this annotation

GitHub Actions / test-windows

The type or namespace name 'GlobalFilterCollection' could not be found (are you missing a using directive or an assembly reference?)
filters.Add(new HandleErrorAttribute());
}
21 changes: 21 additions & 0 deletions examples/Examples.AspNetClassicWebApi/App_Start/WebApiConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Web.Http;

Check failure on line 5 in examples/Examples.AspNetClassicWebApi/App_Start/WebApiConfig.cs

View workflow job for this annotation

GitHub Actions / test-windows

The type or namespace name 'Http' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

namespace Examples.AspNetClassicWebApi;

public static class WebApiConfig
{
public static void Register(HttpConfiguration config)

Check failure on line 11 in examples/Examples.AspNetClassicWebApi/App_Start/WebApiConfig.cs

View workflow job for this annotation

GitHub Actions / test-windows

The type or namespace name 'HttpConfiguration' could not be found (are you missing a using directive or an assembly reference?)
{
config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { controller = "Home", id = RouteParameter.Optional }
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Collections.Generic;
using System.Diagnostics;
using System.Web.Http;

Check failure on line 7 in examples/Examples.AspNetClassicWebApi/Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / test-windows

The type or namespace name 'Http' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

namespace Examples.AspNetClassicWebApi.Controllers;

public class HomeController : ApiController
{
public IEnumerable<string> Get()
{
using var activity = WebApiApplication.ActivitySource.StartActivity("DoingStuff", ActivityKind.Internal);

activity?.SetTag("custom-tag", "TagValue");

return ["value1", "value2"];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != '' And Exists('$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets')" />
<Import Project="$(SolutionDir)\packages\MSBuild.Microsoft.VisualStudio.Web.targets.14.0.0\tools\VSToolsPath\WebApplications\Microsoft.WebApplication.targets" Condition="('$(VSToolsPath)' == '' Or !Exists('$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets')) And Exists('$(SolutionDir)\packages\MSBuild.Microsoft.VisualStudio.Web.targets.14.0.0\tools\VSToolsPath\WebApplications\Microsoft.WebApplication.targets')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{65D6E902-642D-41DE-BB40-3CDAD38DC640}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Examples.AspNetClassicWebApi</RootNamespace>
<AssemblyName>Examples.AspNetClassicWebApi</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>true</UseIISExpress>
<Use64BitIISExpress />
<IISExpressSSLPort>44308</IISExpressSSLPort>
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<MinVerSkip>true</MinVerSkip>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="Microsoft.Web.Infrastructure, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\Microsoft.Web.Infrastructure.2.0.1\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http">
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.9\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest">
</Reference>
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\Microsoft.AspNet.WebPages.3.2.9\lib\net45\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.9\lib\net45\System.Web.Http.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.WebHost, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.9\lib\net45\System.Web.Http.WebHost.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\Microsoft.AspNet.Mvc.5.2.9\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Optimization">
<HintPath>..\..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\Microsoft.AspNet.Razor.3.2.9\lib\net45\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\Microsoft.AspNet.WebPages.3.2.9\lib\net45\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\Microsoft.AspNet.WebPages.3.2.9\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\Microsoft.AspNet.WebPages.3.2.9\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
<Reference Include="WebGrease">
<Private>True</Private>
<HintPath>..\..\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
</Reference>
<Reference Include="Antlr3.Runtime">
<Private>True</Private>
<HintPath>..\..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform">
<HintPath>..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="favicon.ico" />
<Content Include="Global.asax" />
<Content Include="Web.config" />
<Content Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
<Content Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Antlr">
<Version>3.5.0.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.Mvc">
<Version>5.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.Razor">
<Version>3.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi">
<Version>5.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.Client">
<Version>6.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.Core">
<Version>5.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.HelpPage">
<Version>5.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.WebHost">
<Version>5.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebPages">
<Version>3.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform">
<Version>4.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Web.Infrastructure">
<Version>2.0.1</Version>
</PackageReference>
<PackageReference Include="MSBuild.Microsoft.VisualStudio.Web.targets">
<Version>14.0.0.3</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="OpenTelemetry">
<Version>1.8.1</Version>
</PackageReference>
<PackageReference Include="OpenTelemetry.Instrumentation.AspNet">
<Version>1.8.0-beta.2</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Elastic.OpenTelemetry\Elastic.OpenTelemetry.csproj">
<Project>{79c08f0e-7220-486c-ac0c-e3b287eb0b18}</Project>
<Name>Elastic.OpenTelemetry</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>51546</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>https://localhost:44308/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target> -->
</Project>
1 change: 1 addition & 0 deletions examples/Examples.AspNetClassicWebApi/Global.asax
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%@ Application Codebehind="Global.asax.cs" Inherits="Examples.AspNetClassicWebApi.WebApiApplication" Language="C#" %>
39 changes: 39 additions & 0 deletions examples/Examples.AspNetClassicWebApi/Global.asax.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Diagnostics;
using System.Web;
using System.Web.Http;

Check failure on line 7 in examples/Examples.AspNetClassicWebApi/Global.asax.cs

View workflow job for this annotation

GitHub Actions / test-windows

The type or namespace name 'Http' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
using System.Web.Mvc;

Check failure on line 8 in examples/Examples.AspNetClassicWebApi/Global.asax.cs

View workflow job for this annotation

GitHub Actions / test-windows

The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
using Elastic.OpenTelemetry;
using Elastic.OpenTelemetry.Extensions;
using OpenTelemetry;

Check failure on line 11 in examples/Examples.AspNetClassicWebApi/Global.asax.cs

View workflow job for this annotation

GitHub Actions / test-windows

The type or namespace name 'OpenTelemetry' could not be found (are you missing a using directive or an assembly reference?)
using OpenTelemetry.Resources;

Check failure on line 12 in examples/Examples.AspNetClassicWebApi/Global.asax.cs

View workflow job for this annotation

GitHub Actions / test-windows

The type or namespace name 'OpenTelemetry' could not be found (are you missing a using directive or an assembly reference?)
using OpenTelemetry.Trace;

Check failure on line 13 in examples/Examples.AspNetClassicWebApi/Global.asax.cs

View workflow job for this annotation

GitHub Actions / test-windows

The type or namespace name 'OpenTelemetry' could not be found (are you missing a using directive or an assembly reference?)

namespace Examples.AspNetClassicWebApi;

public class WebApiApplication : HttpApplication
{
private const string SourceName = "Example.AspNetClassic";

internal static readonly ActivitySource ActivitySource = new(SourceName);

private IInstrumentationLifetime _lifetime;

protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

_lifetime = new ElasticOpenTelemetryBuilder()
.ConfigureResource(r => r.AddService("aspnet-classic-webapi-example"))
.WithTracing(t => t
.AddAspNetInstrumentation()
.AddSource(SourceName))
.Build();
}

protected void Application_End() => _lifetime?.Dispose();
}
Loading
Loading