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

[wcf] Add AspNet parent span correction #1342

Merged
merged 12 commits into from
Sep 26, 2023
22 changes: 16 additions & 6 deletions examples/wcf/client-core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,22 @@ public static async Task Main()
.AddZipkinExporter()
.Build();

await CallService(
new BasicHttpBinding(BasicHttpSecurityMode.None),
new EndpointAddress(config.GetSection("Service").GetValue<string>("HttpAddress"))).ConfigureAwait(false);
await CallService(
new NetTcpBinding(SecurityMode.None),
new EndpointAddress(config.GetSection("Service").GetValue<string>("TcpAddress"))).ConfigureAwait(false);
switch (config.GetValue<string>("Server")!.ToUpperInvariant())
{
case "ASPNET":
await CallService(
new BasicHttpBinding(BasicHttpSecurityMode.None),
new EndpointAddress(config.GetSection("Service").GetValue<string>("AspNetAddress"))).ConfigureAwait(false);
break;
default:
await CallService(
new BasicHttpBinding(BasicHttpSecurityMode.None),
new EndpointAddress(config.GetSection("Service").GetValue<string>("HttpAddress"))).ConfigureAwait(false);
await CallService(
new NetTcpBinding(SecurityMode.None),
new EndpointAddress(config.GetSection("Service").GetValue<string>("TcpAddress"))).ConfigureAwait(false);
break;
}

Console.WriteLine("Press enter to exit.");
Console.ReadLine();
Expand Down
8 changes: 5 additions & 3 deletions examples/wcf/client-core/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
{
"Server": "self-hosted",
"Service": {
"HttpAddress": "http://localhost:9009/Telemetry",
"TcpAddress": "net.tcp://localhost:9090/Telemetry"
"TcpAddress": "net.tcp://localhost:9090/Telemetry",
"AspNetAddress": "http://localhost:61494/StatusService.svc"
}
}
}
6 changes: 5 additions & 1 deletion examples/wcf/client-netframework/App.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Server" value="self-hosted" />
</appSettings>
<system.serviceModel>
<extensions>
<behaviorExtensions>
Expand Down Expand Up @@ -33,6 +36,7 @@
<endpoint address="http://localhost:9009/Telemetry" binding="basicHttpBinding" bindingConfiguration="basicHttpConfig" behaviorConfiguration="telemetry" contract="Examples.Wcf.IStatusServiceContract" name="StatusService_Http" />
<endpoint address="net.tcp://localhost:9090/Telemetry" binding="netTcpBinding" bindingConfiguration="netTCPConfig" behaviorConfiguration="telemetry" contract="Examples.Wcf.IStatusServiceContract" name="StatusService_Tcp" />
<endpoint address="http://localhost:9009/Telemetry/rest" binding="webHttpBinding" behaviorConfiguration="webHttp" contract="Examples.Wcf.IStatusServiceContract" name="StatusService_Rest" />
<endpoint address="http://localhost:61494/StatusService.svc" binding="basicHttpBinding" bindingConfiguration="basicHttpConfig" behaviorConfiguration="telemetry" contract="Examples.Wcf.IStatusServiceContract" name="StatusService_AspNet" />
</client>
</system.serviceModel>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</ItemGroup>

<ItemGroup>
<Reference Include="System.Configuration" />
<Reference Include="System.ServiceModel" />
</ItemGroup>

Expand Down
15 changes: 12 additions & 3 deletions examples/wcf/client-netframework/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using System;
using System.Configuration;
using System.ServiceModel;
using System.Threading.Tasks;
using OpenTelemetry;
Expand All @@ -33,9 +34,17 @@ public static async Task Main()
.AddZipkinExporter()
.Build();

await CallService("StatusService_Http").ConfigureAwait(false);
await CallService("StatusService_Tcp").ConfigureAwait(false);
await CallService("StatusService_Rest").ConfigureAwait(false);
switch (ConfigurationManager.AppSettings["Server"].ToUpperInvariant())
{
case "ASPNET":
await CallService("StatusService_AspNet").ConfigureAwait(false);
break;
default:
await CallService("StatusService_Http").ConfigureAwait(false);
await CallService("StatusService_Tcp").ConfigureAwait(false);
await CallService("StatusService_Rest").ConfigureAwait(false);
break;
}

Console.WriteLine("Press enter to exit.");
Console.ReadLine();
Expand Down
Kielek marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<OutputType>Library</OutputType>
<OutputPath>bin\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<AppConfig>web.config</AppConfig>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<ProjectCapability Include="DotNetCoreWeb" />
<ProjectCapability Include="SupportsSystemWeb" />
<ProjectCapability Include="LegacyRazorEditor" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Configuration" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<Content Include="Global.asax" />
<Content Include="StatusService.svc" />
<Content Include="Web.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="StatusService.svc.cs">
<DependentUpon>StatusService.svc</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
<None Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="$(OpenTelemetryCoreLatestVersion)" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="$(OpenTelemetryCoreLatestVersion)" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="$(OpenTelemetryCoreLatestVersion)" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="$(OpenTelemetryCoreLatestVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNet\OpenTelemetry.Instrumentation.AspNet.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.Wcf\OpenTelemetry.Instrumentation.Wcf.csproj" />
<ProjectReference Include="$(RepoRoot)\examples\wcf\shared\Examples.Wcf.Shared.csproj" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="Exists('$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets')" />
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
<Target Name="SkipBuildWithoutVisualStudio">
<Message Text="Skipping build because Visual Studio is not available." Condition="!Exists('$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets')" />
<CallTarget Targets="$(BuildDependsOnOriginalValue)" Condition="Exists('$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets')" />
</Target>
<PropertyGroup>
<BuildDependsOnOriginalValue>$(BuildDependsOn)</BuildDependsOnOriginalValue>
<BuildDependsOn>SkipBuildWithoutVisualStudio</BuildDependsOn>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions examples/wcf/server-aspnetframework/Global.asax
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%@ Application Codebehind="Global.asax.cs" Inherits="Examples.Wcf.Server.AspNetFramework.WebApiApplication" Language="C#" %>
67 changes: 67 additions & 0 deletions examples/wcf/server-aspnetframework/Global.asax.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// <copyright file="Global.asax.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;
using System.Configuration;
using System.Web;
using OpenTelemetry;
using OpenTelemetry.Exporter;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

namespace Examples.Wcf.Server.AspNetFramework;

#pragma warning disable SA1649 // File name should match first type name
public class WebApiApplication : HttpApplication
#pragma warning restore SA1649 // File name should match first type name
{
private IDisposable? tracerProvider;

protected void Application_Start()
{
var builder = Sdk.CreateTracerProviderBuilder()
.ConfigureResource(resource => resource.AddService("Wcf-AspNetServer"))
.AddAspNetInstrumentation()
.AddWcfInstrumentation();

switch (ConfigurationManager.AppSettings["UseExporter"].ToUpperInvariant())
{
case "ZIPKIN":
builder.AddZipkinExporter(zipkinOptions =>
{
zipkinOptions.Endpoint = new Uri(ConfigurationManager.AppSettings["ZipkinEndpoint"]);
});
break;
case "OTLP":
builder.AddOtlpExporter(otlpOptions =>
{
otlpOptions.Endpoint = new Uri(ConfigurationManager.AppSettings["OtlpEndpoint"]);
});
break;
default:
builder.AddConsoleExporter(options => options.Targets = ConsoleExporterOutputTargets.Debug);
break;
}

this.tracerProvider = builder.Build();
}

protected void Application_End()
{
this.tracerProvider?.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:61494"
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
1 change: 1 addition & 0 deletions examples/wcf/server-aspnetframework/StatusService.svc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%@ ServiceHost Language="C#" Debug="true" Service="Examples.Wcf.Server.AspNetFramework.StatusService" CodeBehind="StatusService.svc.cs" %>
32 changes: 32 additions & 0 deletions examples/wcf/server-aspnetframework/StatusService.svc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <copyright file="StatusService.svc.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;
using System.Threading.Tasks;

namespace Examples.Wcf.Server.AspNetFramework;

public class StatusService : IStatusServiceContract
{
public Task<StatusResponse> PingAsync(StatusRequest request)
{
return Task.FromResult(
new StatusResponse
{
ServerTime = DateTimeOffset.UtcNow,
});
}
}
30 changes: 30 additions & 0 deletions examples/wcf/server-aspnetframework/Web.Debug.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".

<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.

<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
31 changes: 31 additions & 0 deletions examples/wcf/server-aspnetframework/Web.Release.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".

<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.

<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
Loading
Loading