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 instrumentation + example apps #38

Merged
merged 38 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
914feda
WCF instrumentation + example apps.
CodeBlanch Sep 26, 2020
ee640a3
Merge branch 'master' into wcf-instrumentation
CodeBlanch Sep 26, 2020
e25beef
Added an event source to log errors in Wcf instrumentation.
CodeBlanch Sep 29, 2020
74d3c4c
Added content to the WCF instrumentation's README.
CodeBlanch Oct 6, 2020
3c67689
Added support for the .NET Core version of WCF clients.
CodeBlanch Oct 26, 2020
ffb5f08
Code review feedback.
CodeBlanch Oct 27, 2020
459befb
Merging latest from main.
CodeBlanch Feb 11, 2021
4dbc5b1
Updated code for 1.0 and changes done in main.
CodeBlanch Feb 11, 2021
fe0f5df
Lint errors.
CodeBlanch Feb 11, 2021
4bf55a1
Server tests and cleanup.
CodeBlanch Feb 11, 2021
47974fc
Added client tests.
CodeBlanch Feb 11, 2021
ec2d91a
Fixed some weirdness with SuppressDownstreamInstrumentation.
CodeBlanch Feb 11, 2021
ab34a65
Bug fixes.
CodeBlanch Feb 11, 2021
d07c9c3
Attempting to fix lint errors.
CodeBlanch Feb 11, 2021
5e01cac
Code review and clean up.
CodeBlanch Feb 14, 2021
405c010
Added "wcf-" MinVerTagPrefix in csproj.
CodeBlanch Feb 15, 2021
9c3fb42
Fun with copy-paste.
CodeBlanch Feb 21, 2021
7eb6622
Removed OpenTelemetry.Instrumentation.Http from wcf client examples.
CodeBlanch Feb 21, 2021
63aeb50
Updated link paths.
CodeBlanch Feb 21, 2021
6f6a671
Code review.
CodeBlanch Feb 21, 2021
da1bfc1
Added wcf examples readme.
CodeBlanch Feb 21, 2021
f34b0f6
Code review.
CodeBlanch Feb 21, 2021
0c42c6f
Typo.
CodeBlanch Feb 21, 2021
c53598e
Markdown lint.
CodeBlanch Feb 21, 2021
6814bd1
Code review.
CodeBlanch Feb 21, 2021
abee3cc
Code review.
CodeBlanch Feb 21, 2021
fa2c7bd
Code review.
CodeBlanch Feb 21, 2021
c97f97b
Code review.
CodeBlanch Feb 22, 2021
aca8284
Add support for To & Via properties.
CodeBlanch Feb 22, 2021
2460ad8
Code review.
CodeBlanch Feb 22, 2021
c81888d
Code review.
CodeBlanch Feb 22, 2021
7034b58
Example readme update.
CodeBlanch Feb 22, 2021
1cafa4a
Mirror fix from PR #73.
CodeBlanch Feb 25, 2021
cca68ad
Merging from main.
CodeBlanch Feb 27, 2021
7b28226
Nits.
CodeBlanch Feb 27, 2021
0d7afa3
Hashtable for cache.
CodeBlanch Feb 28, 2021
0d1ee70
Code review.
CodeBlanch Feb 28, 2021
d228314
Merge branch 'main' into wcf-instrumentation
CodeBlanch Mar 5, 2021
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
3 changes: 3 additions & 0 deletions examples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'opentelemetry-dotnet-contrib.sln'))\build\Common.nonprod.props" />
</Project>
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 32 additions & 0 deletions examples/wcf/client-core/Examples.Wcf.Client.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.ServiceModel.Http" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.9" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.0.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\OpenTelemetry.Contrib.Instrumentation.Wcf\OpenTelemetry.Contrib.Instrumentation.Wcf.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\shared\Examples.Wcf.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
84 changes: 84 additions & 0 deletions examples/wcf/client-core/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// <copyright file="Program.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.IO;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using OpenTelemetry;
using OpenTelemetry.Contrib.Instrumentation.Wcf;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

namespace Examples.Wcf.Client
{
internal static class Program
{
public static async Task Main()
{
IConfigurationRoot config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();

using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("Wcf-Client-Core"))
.AddWcfInstrumentation()
.AddHttpClientInstrumentation() // <- Added to test suppression of http spans.
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved
.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);

Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}

private static async Task CallService(Binding binding, EndpointAddress remoteAddress)
{
StatusServiceClient client = new StatusServiceClient(binding, remoteAddress);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you intentionally re-create client on each call? It is unlikely the best practice. If this is just for demo purposes, can you add a comment that this is not how the production code will look like

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more the nature of the example making a couple of calls and then closing. I'm adding this note:

            // Note: Best practice is to re-use your client/channel instances.
            // This code is not meant to illustrate best practices, only the
            // instrumentation.

Does that work for you?

@mconnew Keep me honest here. Fair to say best practice is to reuse the client?

client.Endpoint.EndpointBehaviors.Add(new TelemetryEndpointBehavior());
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved
try
{
var response = await client.Ping(
new StatusRequest
{
Status = Guid.NewGuid().ToString("N"),
}).ConfigureAwait(false);

Console.WriteLine($"Server returned: {response?.ServerTime}");
}
finally
{
if (client.State == CommunicationState.Faulted)
{
client.Abort();
}
else
{
client.Close();
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
38 changes: 38 additions & 0 deletions examples/wcf/client-core/StatusServiceClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// <copyright file="StatusServiceClient.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.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading.Tasks;

namespace Examples.Wcf.Client
{
public class StatusServiceClient : ClientBase<IStatusServiceContract>, IStatusServiceContract
{
public StatusServiceClient(string name)
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved
: base(name)
{
}

public StatusServiceClient(Binding binding, EndpointAddress remoteAddress)
: base(binding, remoteAddress)
{
}

public Task<StatusResponse> Ping(StatusRequest request)
=> this.Channel.Ping(request);
}
}
6 changes: 6 additions & 0 deletions examples/wcf/client-core/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Service": {
"HttpAddress": "http://localhost:9009/Telemetry",
"TcpAddress": "net.tcp://localhost:9090/Telemetry"
}
}
33 changes: 33 additions & 0 deletions examples/wcf/client-netframework/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="telemetryExtension" type="OpenTelemetry.Contrib.Instrumentation.Wcf.TelemetryBehaviourExtensionElement, OpenTelemetry.Contrib.Instrumentation.Wcf" />
</behaviorExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior name="telemetry">
<telemetryExtension />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpConfig">
<security mode="None" />
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="netTCPConfig">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<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" />
</client>
</system.serviceModel>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net46</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.0.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\OpenTelemetry.Contrib.Instrumentation.Wcf\OpenTelemetry.Contrib.Instrumentation.Wcf.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\shared\Examples.Wcf.Shared.csproj" />
</ItemGroup>

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

</Project>
72 changes: 72 additions & 0 deletions examples/wcf/client-netframework/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// <copyright file="Program.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.ServiceModel;
using System.Threading.Tasks;
using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

namespace Examples.Wcf.Client
{
internal static class Program
{
public static async Task Main()
{
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("Wcf-Client"))
.AddWcfInstrumentation()
.AddHttpClientInstrumentation() // <- Added to test suppression of http spans.
.AddZipkinExporter()
.Build();

await CallService("StatusService_Http").ConfigureAwait(false);
await CallService("StatusService_Tcp").ConfigureAwait(false);

Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}

private static async Task CallService(string name)
{
StatusServiceClient client = new StatusServiceClient(name);
try
{
client.Open();
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved

var response = await client.Ping(
new StatusRequest
{
Status = Guid.NewGuid().ToString("N"),
}).ConfigureAwait(false);

Console.WriteLine($"Server returned: {response?.ServerTime}");
}
finally
{
if (client.State == CommunicationState.Faulted)
{
client.Abort();
}
else
{
client.Close();
}
}
}
}
}
32 changes: 32 additions & 0 deletions examples/wcf/client-netframework/StatusServiceClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <copyright file="StatusServiceClient.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.ServiceModel;
using System.Threading.Tasks;

namespace Examples.Wcf.Client
{
public class StatusServiceClient : ClientBase<IStatusServiceContract>, IStatusServiceContract
{
public StatusServiceClient(string name)
: base(name)
{
}

public Task<StatusResponse> Ping(StatusRequest request)
=> this.Channel.Ping(request);
}
}
41 changes: 41 additions & 0 deletions examples/wcf/server-netframework/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="telemetryExtension" type="OpenTelemetry.Contrib.Instrumentation.Wcf.TelemetryBehaviourExtensionElement, OpenTelemetry.Contrib.Instrumentation.Wcf" />
</behaviorExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior name="telemetry">
<telemetryExtension />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpConfig">
<security mode="None" />
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="netTCPConfig">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="Examples.Wcf.Server.StatusService">
<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpConfig" behaviorConfiguration="telemetry" contract="Examples.Wcf.IStatusServiceContract" />
<endpoint binding="netTcpBinding" bindingConfiguration="netTCPConfig" behaviorConfiguration="telemetry" contract="Examples.Wcf.IStatusServiceContract" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:9009/Telemetry" />
<add baseAddress="net.tcp://localhost:9090/Telemetry" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Loading