-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,196 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Pack OpenTelemetry.Contrib.Instrumentation.Owin | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
logLevel: | ||
description: 'Log level' | ||
required: true | ||
default: 'warning' | ||
push: | ||
tags: | ||
- 'Instrumentation.Owin-*' | ||
|
||
jobs: | ||
build-test-pack: | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
PROJECT: OpenTelemetry.Contrib.Instrumentation.Owin | ||
|
||
strategy: | ||
matrix: | ||
os: [windows-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 # fetching all | ||
|
||
- name: Install dependencies | ||
run: dotnet restore | ||
|
||
- name: dotnet build ${{env.PROJECT}} | ||
run: dotnet build src/${{env.PROJECT}} --configuration Release --no-restore -p:Deterministic=true | ||
|
||
- name: dotnet test ${{env.PROJECT}} | ||
run: dotnet test test/${{env.PROJECT}}.Tests | ||
|
||
- name: dotnet pack ${{env.PROJECT}} | ||
run: dotnet pack src/${{env.PROJECT}} --configuration Release --no-build | ||
|
||
- name: Publish Artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: ${{env.PROJECT}}-packages | ||
path: '**/${{env.PROJECT}}/bin/**/*.*nupkg' | ||
|
||
- name: Publish Nuget | ||
run: | | ||
nuget push **/${{env.PROJECT}}/bin/**/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_TOKEN }} -SymbolApiKey ${{ secrets.NUGET_TOKEN }} |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// <copyright file="TestController.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.Web.Http; | ||
|
||
namespace Examples.Owin.Controllers | ||
{ | ||
public class TestController : ApiController | ||
{ | ||
// GET api/test/{id} | ||
public string Get(string id = null) | ||
{ | ||
return $"id:{id}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net461</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNet.WebApi.OwinSelfHost" Version="5.2.7" /> | ||
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Contrib.Instrumentation.Owin\OpenTelemetry.Contrib.Instrumentation.Owin.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// <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.Diagnostics; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Web.Http; | ||
using Microsoft.Owin.Hosting; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Resources; | ||
using OpenTelemetry.Trace; | ||
using Owin; | ||
|
||
namespace Examples.Owin | ||
{ | ||
internal static class Program | ||
{ | ||
public static void Main() | ||
{ | ||
using var host = WebApp.Start( | ||
"http://localhost:9000", | ||
appBuilder => | ||
{ | ||
// Add OpenTelemetry early in the pipeline to start timing | ||
// the request as soon as possible. | ||
appBuilder.UseOpenTelemetry(); | ||
|
||
HttpConfiguration config = new HttpConfiguration(); | ||
|
||
config.MessageHandlers.Add(new ActivityDisplayNameRouteEnrichingHandler()); | ||
|
||
config.Routes.MapHttpRoute( | ||
name: "DefaultApi", | ||
routeTemplate: "api/{controller}/{id}", | ||
defaults: new { id = RouteParameter.Optional }); | ||
|
||
appBuilder.UseWebApi(config); | ||
}); | ||
|
||
using var openTelemetry = Sdk.CreateTracerProviderBuilder() | ||
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("Owin-Example")) | ||
.AddOwinInstrumentation() | ||
.AddConsoleExporter() | ||
.Build(); | ||
|
||
Console.WriteLine("Service listening. Press enter to exit."); | ||
Console.ReadLine(); | ||
} | ||
|
||
private class ActivityDisplayNameRouteEnrichingHandler : DelegatingHandler | ||
{ | ||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false); | ||
} | ||
finally | ||
{ | ||
var activity = Activity.Current; | ||
if (activity != null) | ||
{ | ||
var routeData = request.GetRouteData(); | ||
if (routeData != null) | ||
{ | ||
activity.DisplayName = routeData.Route.RouteTemplate; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# OWIN Instrumentation for OpenTelemetry .NET - Example | ||
|
||
An example application that shows how to use | ||
`OpenTelemetry.Contrib.Instrumentation.Owin` to capture telemetry from a | ||
self-hosted WebAPI .NET Framework service. | ||
|
||
Span names are set to the route template resolved by WebAPI. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/OpenTelemetry.Contrib.Instrumentation.Owin/AppBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// <copyright file="AppBuilderExtensions.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.Diagnostics; | ||
using OpenTelemetry.Contrib.Instrumentation.Owin; | ||
|
||
namespace Owin | ||
{ | ||
/// <summary> | ||
/// Provides extension methods for the <see cref="IAppBuilder"/> class. | ||
/// </summary> | ||
public static class AppBuilderExtensions | ||
{ | ||
/// <summary>Adds a component to the OWIN pipeline for instrumenting | ||
/// incoming request with <see cref="Activity"/> and notifying listeners | ||
/// with <see cref="ActivitySource"/>.</summary> | ||
/// <param name="appBuilder"><see cref="IAppBuilder"/>.</param> | ||
/// <returns>Supplied <see cref="IAppBuilder"/> for chaining.</returns> | ||
public static IAppBuilder UseOpenTelemetry(this IAppBuilder appBuilder) | ||
=> appBuilder.Use<DiagnosticsMiddleware>(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/OpenTelemetry.Contrib.Instrumentation.Owin/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// <copyright file="AssemblyInfo.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.Runtime.CompilerServices; | ||
|
||
#if SIGNED | ||
[assembly: InternalsVisibleTo("OpenTelemetry.Contrib.Instrumentation.Owin.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] | ||
#else | ||
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.Owin.Tests")] | ||
#endif | ||
|
||
[assembly: CLSCompliant(false)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog | ||
|
||
## Unreleased | ||
|
||
* Initial release |
Oops, something went wrong.