Splitting Instrumentation Projects (#890)
updating README updating sql integration test updating yml updating dockerfile updating readme updating global.asax updating version and readme removing unused reference, adding properties folder to be similar to OT project adding zipkin docker in comments updating to standard2.1 removing unused usings updating aspnet/aspnetcore methods naming applying cijo's suggestions updating projects to compile semantic file, updating comments Splitting Instrumentation Projects updating README updating sql integration test updating yml updating dockerfile updating readme updating global.asax updating version and readme removing unused reference, adding properties folder to be similar to OT project adding zipkin docker in comments updating to standard2.1 removing unused usings applying cijo's suggestions
This commit is contained in:
parent
b6df53854a
commit
2dd8daa1e4
|
|
@ -23,4 +23,4 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Run sql docker-compose.integration
|
||||
run: docker-compose --file=test/OpenTelemetry.Instrumentation.Dependencies.Tests/docker-compose.integration.yml --project-directory=. up --exit-code-from=sql_integration_tests --build
|
||||
run: docker-compose --file=test/OpenTelemetry.Instrumentation.SqlClient.Tests/docker-compose.integration.yml --project-directory=. up --exit-code-from=sql_integration_tests --build
|
||||
|
|
@ -43,10 +43,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Api", "src\Op
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prometheus", "src\OpenTelemetry.Exporter.Prometheus\OpenTelemetry.Exporter.Prometheus.csproj", "{AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.Dependencies", "src\OpenTelemetry.Instrumentation.Dependencies\OpenTelemetry.Instrumentation.Dependencies.csproj", "{D3FFBC59-2486-4F8F-BFF1-FA95C84929E1}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.Dependencies.Tests", "test\OpenTelemetry.Instrumentation.Dependencies.Tests\OpenTelemetry.Instrumentation.Dependencies.Tests.csproj", "{56E2647A-B814-4BAC-B854-BEA0051B5F2E}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.AspNetCore", "src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj", "{752D2182-A351-41D8-99EE-DD363D7D5B43}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.AspNetCore.Tests", "test\OpenTelemetry.Instrumentation.AspNetCore.Tests\OpenTelemetry.Instrumentation.AspNetCore.Tests.csproj", "{2A47F6A8-63E5-4237-8046-94CAF321E797}"
|
||||
|
|
@ -143,6 +139,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.AspNetCore", "exam
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "test\Benchmarks\Benchmarks.csproj", "{DE9130A4-F30A-49D7-8834-41DE3021218B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.SqlClient.Tests", "test\OpenTelemetry.Instrumentation.SqlClient.Tests\OpenTelemetry.Instrumentation.SqlClient.Tests.csproj", "{0C606039-BE0A-4EE6-B8F7-F75B41E52CB8}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.SqlClient", "src\OpenTelemetry.Instrumentation.SqlClient\OpenTelemetry.Instrumentation.SqlClient.csproj", "{41C30DC1-8C57-4E14-A83A-7635A3C7960B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.Http.Tests", "test\OpenTelemetry.Instrumentation.Http.Tests\OpenTelemetry.Instrumentation.Http.Tests.csproj", "{DE9EB7D8-9CC5-4073-90B3-9FBF685B3305}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.Http", "src\OpenTelemetry.Instrumentation.Http\OpenTelemetry.Instrumentation.Http.csproj", "{412C64D1-43D6-4E4C-8AD8-E20E63B415BD}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.Grpc", "src\OpenTelemetry.Instrumentation.Grpc\OpenTelemetry.Instrumentation.Grpc.csproj", "{0246BFC4-8AAF-45E1-A127-DB43D6E345BB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -169,14 +175,6 @@ Global
|
|||
{AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D3FFBC59-2486-4F8F-BFF1-FA95C84929E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D3FFBC59-2486-4F8F-BFF1-FA95C84929E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D3FFBC59-2486-4F8F-BFF1-FA95C84929E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D3FFBC59-2486-4F8F-BFF1-FA95C84929E1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{56E2647A-B814-4BAC-B854-BEA0051B5F2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{56E2647A-B814-4BAC-B854-BEA0051B5F2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{56E2647A-B814-4BAC-B854-BEA0051B5F2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{56E2647A-B814-4BAC-B854-BEA0051B5F2E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{752D2182-A351-41D8-99EE-DD363D7D5B43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{752D2182-A351-41D8-99EE-DD363D7D5B43}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{752D2182-A351-41D8-99EE-DD363D7D5B43}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
|
@ -281,6 +279,26 @@ Global
|
|||
{DE9130A4-F30A-49D7-8834-41DE3021218B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DE9130A4-F30A-49D7-8834-41DE3021218B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DE9130A4-F30A-49D7-8834-41DE3021218B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0C606039-BE0A-4EE6-B8F7-F75B41E52CB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0C606039-BE0A-4EE6-B8F7-F75B41E52CB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0C606039-BE0A-4EE6-B8F7-F75B41E52CB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0C606039-BE0A-4EE6-B8F7-F75B41E52CB8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{41C30DC1-8C57-4E14-A83A-7635A3C7960B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{41C30DC1-8C57-4E14-A83A-7635A3C7960B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{41C30DC1-8C57-4E14-A83A-7635A3C7960B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{41C30DC1-8C57-4E14-A83A-7635A3C7960B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DE9EB7D8-9CC5-4073-90B3-9FBF685B3305}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DE9EB7D8-9CC5-4073-90B3-9FBF685B3305}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DE9EB7D8-9CC5-4073-90B3-9FBF685B3305}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DE9EB7D8-9CC5-4073-90B3-9FBF685B3305}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{412C64D1-43D6-4E4C-8AD8-E20E63B415BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{412C64D1-43D6-4E4C-8AD8-E20E63B415BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{412C64D1-43D6-4E4C-8AD8-E20E63B415BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{412C64D1-43D6-4E4C-8AD8-E20E63B415BD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0246BFC4-8AAF-45E1-A127-DB43D6E345BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0246BFC4-8AAF-45E1-A127-DB43D6E345BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0246BFC4-8AAF-45E1-A127-DB43D6E345BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0246BFC4-8AAF-45E1-A127-DB43D6E345BB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
|||
|
|
@ -31,12 +31,14 @@ libraries](https://github.com/open-telemetry/opentelemetry-specification/blob/ma
|
|||
* ASP.NET [:link:](https://docs.microsoft.com/aspnet/overview)
|
||||
* [OpenTelemetry.Instrumentation.AspNetCore](./src/OpenTelemetry.Instrumentation.AspNetCore/README.md)
|
||||
* ASP.NET Core [:link:](https://docs.microsoft.com/en-us/aspnet/core)
|
||||
* [OpenTelemetry.Instrumentation.Dependencies](./src/OpenTelemetry.Instrumentation.Dependencies/README.md)
|
||||
* [OpenTelemetry.Instrumentation.Grpc](./src/OpenTelemetry.Instrumentation.Grpc/README.md)
|
||||
* gRPC for .NET [:link:](https://github.com/grpc/grpc-dotnet)
|
||||
* Microsoft.Data.SqlClient [:link:](https://www.nuget.org/packages/Microsoft.Data.SqlClient)
|
||||
* System.Data.SqlClient [:link:](https://www.nuget.org/packages/System.Data.SqlClient)
|
||||
* [OpenTelemetry.Instrumentation.Http](./src/OpenTelemetry.Instrumentation.Http/README.md)
|
||||
* System.Net.Http.HttpClient [:link:](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient)
|
||||
* System.Net.HttpWebRequest [:link:](https://docs.microsoft.com/dotnet/api/system.net.httpwebrequest)
|
||||
* [OpenTelemetry.Instrumentation.SqlClient](./src/OpenTelemetry.Instrumentation.SqlClient/README.md)
|
||||
* Microsoft.Data.SqlClient [:link:](https://www.nuget.org/packages/Microsoft.Data.SqlClient)
|
||||
* System.Data.SqlClient [:link:](https://www.nuget.org/packages/System.Data.SqlClient)
|
||||
* [OpenTelemetry.Instrumentation.StackExchangeRedis](./src/OpenTelemetry.Instrumentation.StackExchangeRedis/README.md)
|
||||
* StackExchange.Redis [:link:](https://www.nuget.org/packages/StackExchange.Redis)
|
||||
|
||||
|
|
|
|||
|
|
@ -91,14 +91,14 @@
|
|||
<Project>{b9eeacdd-cafa-4b75-a18d-898e7de21b17}</Project>
|
||||
<Name>OpenTelemetry.Instrumentation.AspNet</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Dependencies\OpenTelemetry.Instrumentation.Dependencies.csproj">
|
||||
<Project>{d3ffbc59-2486-4f8f-bff1-fa95c84929e1}</Project>
|
||||
<Name>OpenTelemetry.Instrumentation.Dependencies</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Exporter.Jaeger\OpenTelemetry.Exporter.Jaeger.csproj">
|
||||
<Project>{8d47e3cf-9ae3-42fe-9084-feb72d9ad769}</Project>
|
||||
<Name>OpenTelemetry.Exporter.Jaeger</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Http\OpenTelemetry.Instrumentation.Http.csproj">
|
||||
<Project>{412c64d1-43d6-4e4c-8ad8-e20e63b415bd}</Project>
|
||||
<Name>OpenTelemetry.Instrumentation.Http</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry\OpenTelemetry.csproj">
|
||||
<Project>{ae3e3df5-4083-4c6e-a840-8271b0acde7e}</Project>
|
||||
<Name>OpenTelemetry</Name>
|
||||
|
|
|
|||
|
|
@ -14,8 +14,9 @@ namespace Examples.AspNet
|
|||
protected void Application_Start()
|
||||
{
|
||||
this.openTelemetry = OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddDependencyInstrumentation()
|
||||
.AddRequestInstrumentation()
|
||||
(builder) => builder
|
||||
.AddHttpInstrumentation()
|
||||
.AddAspNetInstrumentation()
|
||||
.UseJaegerExporter(c =>
|
||||
{
|
||||
c.AgentHost = "localhost";
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
<ProjectReference Include="..\..\src\OpenTelemetry.Exporter.Jaeger\OpenTelemetry.Exporter.Jaeger.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Exporter.Zipkin\OpenTelemetry.Exporter.Zipkin.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Dependencies\OpenTelemetry.Instrumentation.Dependencies.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Extensions.Hosting\OpenTelemetry.Extensions.Hosting.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Http\OpenTelemetry.Instrumentation.Http.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,9 @@ namespace Examples.AspNetCore
|
|||
// Switch between Zipkin/Jaeger by commenting out one of the following.
|
||||
|
||||
/*
|
||||
services.AddOpenTelemetry((builder) => builder.AddRequestInstrumentation().AddDependencyInstrumentation()
|
||||
services.AddOpenTelemetry((builder) => builder
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddHttpInstrumentation()
|
||||
.UseJaegerActivityExporter(o =>
|
||||
{
|
||||
o.ServiceName = this.Configuration.GetValue<string>("Jaeger:ServiceName");
|
||||
|
|
@ -49,7 +51,9 @@ namespace Examples.AspNetCore
|
|||
*/
|
||||
|
||||
/*
|
||||
services.AddOpenTelemetry((builder) => builder.AddRequestInstrumentation().AddDependencyInstrumentation()
|
||||
services.AddOpenTelemetry((builder) => builder
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddHttpInstrumentation()
|
||||
.UseZipkinExporter(o =>
|
||||
{
|
||||
o.ServiceName = this.Configuration.GetValue<string>("Zipkin:ServiceName");
|
||||
|
|
@ -57,7 +61,9 @@ namespace Examples.AspNetCore
|
|||
}));
|
||||
*/
|
||||
|
||||
services.AddOpenTelemetry((builder) => builder.AddRequestInstrumentation().AddDependencyInstrumentation()
|
||||
services.AddOpenTelemetry((builder) => builder
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddHttpInstrumentation()
|
||||
.UseConsoleExporter());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Dependencies\OpenTelemetry.Instrumentation.Dependencies.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Http\OpenTelemetry.Instrumentation.Http.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.StackExchangeRedis\OpenTelemetry.Instrumentation.StackExchangeRedis.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Exporter.Console\OpenTelemetry.Exporter.Console.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Exporter.OpenTelemetryProtocol\OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj" />
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Examples.Console
|
|||
System.Console.WriteLine("Hello World!");
|
||||
|
||||
using var openTelemetry = OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddHttpClientDependencyInstrumentation()
|
||||
(builder) => builder.AddHttpClientInstrumentation()
|
||||
.SetResource(Resources.CreateServiceResource("http-service-example"))
|
||||
.AddActivitySource("http-client-test")
|
||||
.UseConsoleExporter(opt => opt.DisplayAsJson = false));
|
||||
|
|
|
|||
|
|
@ -23,6 +23,13 @@ namespace Examples.Console
|
|||
{
|
||||
internal static object Run(string zipkinUri)
|
||||
{
|
||||
/*
|
||||
* Setup zipkin inside local docker.
|
||||
* docker run -d -p 9411:9411 openzipkin/zipkin
|
||||
*
|
||||
* In zipkinUri, use http://localhost:9411/api/v2/spans
|
||||
*/
|
||||
|
||||
// Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
|
||||
// and use the Zipkin exporter.
|
||||
using var openTelemetry = OpenTelemetrySdk.CreateTracerProvider(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace OpenTelemetry.Trace
|
|||
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
|
||||
/// <param name="configureAspNetInstrumentationOptions">ASP.NET Request configuration options.</param>
|
||||
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
|
||||
public static TracerProviderBuilder AddRequestInstrumentation(
|
||||
public static TracerProviderBuilder AddAspNetInstrumentation(
|
||||
this TracerProviderBuilder builder,
|
||||
Action<AspNetInstrumentationOptions> configureAspNetInstrumentationOptions = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ Configuration with ASP.NET (Full .NET Framework) running in IIS or IIS Express
|
|||
c.AgentHost = "localhost";
|
||||
c.AgentPort = 6831;
|
||||
})
|
||||
.AddRequestInstrumentation()
|
||||
.AddDependencyInstrumentation();
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddHttpInstrumentation();
|
||||
});
|
||||
}
|
||||
protected void Application_End()
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace OpenTelemetry.Trace
|
|||
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
|
||||
/// <param name="configureAspNetCoreInstrumentationOptions">ASP.NET Core Request configuration options.</param>
|
||||
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
|
||||
public static TracerProviderBuilder AddRequestInstrumentation(
|
||||
public static TracerProviderBuilder AddAspNetCoreInstrumentation(
|
||||
this TracerProviderBuilder builder,
|
||||
Action<AspNetCoreInstrumentationOptions> configureAspNetCoreInstrumentationOptions = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
# OpenTelemetry.Instrumentation.Dependencies
|
||||
|
||||
[](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Dependencies)
|
||||
[](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Dependencies)
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
dotnet add package OpenTelemetry.Instrumentation.Dependencies
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* [OpenTelemetry Project](https://opentelemetry.io/)
|
||||
|
|
@ -14,10 +14,10 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using OpenTelemetry.Instrumentation.Dependencies.Implementation;
|
||||
using OpenTelemetry.Instrumentation.Grpc.Implementation;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies
|
||||
namespace OpenTelemetry.Instrumentation.Grpc
|
||||
{
|
||||
/// <summary>
|
||||
/// GrpcClient instrumentation.
|
||||
|
|
@ -18,7 +18,7 @@ using System.Linq;
|
|||
using System.Text.RegularExpressions;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies
|
||||
namespace OpenTelemetry.Instrumentation.Grpc
|
||||
{
|
||||
internal static class GrpcTagHelper
|
||||
{
|
||||
|
|
@ -19,7 +19,7 @@ using System.Net.Http;
|
|||
using System.Reflection;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
||||
namespace OpenTelemetry.Instrumentation.Grpc.Implementation
|
||||
{
|
||||
internal class GrpcClientDiagnosticListener : ListenerHandler
|
||||
{
|
||||
|
|
@ -41,7 +41,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
if (!(this.startRequestFetcher.Fetch(payload) is HttpRequestMessage request))
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.NullPayload(nameof(GrpcClientDiagnosticListener), nameof(this.OnStartActivity));
|
||||
GrpcInstrumentationEventSource.Log.NullPayload(nameof(GrpcClientDiagnosticListener), nameof(this.OnStartActivity));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
// <copyright file="GrpcInstrumentationEventSource.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.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Grpc.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// EventSource events emitted from the project.
|
||||
/// </summary>
|
||||
[EventSource(Name = "OpenTelemetry-Instrumentation-Grpc")]
|
||||
internal class GrpcInstrumentationEventSource : EventSource
|
||||
{
|
||||
public static GrpcInstrumentationEventSource Log = new GrpcInstrumentationEventSource();
|
||||
|
||||
[Event(1, Message = "Payload is NULL in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(1, handlerName, eventName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a culture-independent string representation of the given <paramref name="exception"/> object,
|
||||
/// appropriate for diagnostics tracing.
|
||||
/// </summary>
|
||||
private static string ToInvariantString(Exception exception)
|
||||
{
|
||||
var originalUICulture = Thread.CurrentThread.CurrentUICulture;
|
||||
|
||||
try
|
||||
{
|
||||
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
|
||||
return exception.ToString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.CurrentThread.CurrentUICulture = originalUICulture;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
||||
namespace OpenTelemetry.Instrumentation.Grpc.Implementation
|
||||
{
|
||||
internal class PropertyFetcher
|
||||
{
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.1</TargetFrameworks>
|
||||
<Description>gRPC client instrumentation for OpenTelemetry .NET</Description>
|
||||
<PackageTags>$(PackageTags);distributed-tracing</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\OpenTelemetry.Api\Trace\SemanticConventions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenTelemetry\OpenTelemetry.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
// <copyright file="OpenTelemetryBuilderExtensions.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 OpenTelemetry.Instrumentation.Grpc;
|
||||
using OpenTelemetry.Instrumentation.Grpc.Implementation;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods to simplify registering of dependency instrumentation.
|
||||
/// </summary>
|
||||
public static class OpenTelemetryBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Enables gRPClient Instrumentation.
|
||||
/// </summary>
|
||||
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
|
||||
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
|
||||
public static TracerProviderBuilder AddGrpcClientInstrumentation(
|
||||
this TracerProviderBuilder builder)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
builder.AddInstrumentation((activitySource) => new GrpcClientInstrumentation(activitySource));
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
#if SIGNED
|
||||
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.Dependencies.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
|
||||
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.GrpcClient.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
|
||||
#else
|
||||
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.Dependencies.Tests")]
|
||||
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.GrpcClient.Tests")]
|
||||
#endif
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# OpenTelemetry.Instrumentation.Grpc
|
||||
|
||||
[](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Grpc)
|
||||
[](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Grpc)
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
dotnet add package OpenTelemetry.Instrumentation.Grpc
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* [OpenTelemetry Project](https://opentelemetry.io/)
|
||||
|
|
@ -14,10 +14,10 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using OpenTelemetry.Instrumentation.Dependencies.Implementation;
|
||||
using OpenTelemetry.Instrumentation.Http.Implementation;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies
|
||||
namespace OpenTelemetry.Instrumentation.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Dependencies instrumentation.
|
||||
|
|
@ -18,7 +18,7 @@ using System.Net.Http;
|
|||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies
|
||||
namespace OpenTelemetry.Instrumentation.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Options for dependencies instrumentation.
|
||||
|
|
@ -19,7 +19,7 @@ using System.Net;
|
|||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies
|
||||
namespace OpenTelemetry.Instrumentation.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Options for dependencies instrumentation.
|
||||
|
|
@ -25,7 +25,7 @@ using System.Threading.Tasks;
|
|||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
||||
namespace OpenTelemetry.Instrumentation.Http.Implementation
|
||||
{
|
||||
internal class HttpHandlerDiagnosticListener : ListenerHandler
|
||||
{
|
||||
|
|
@ -77,7 +77,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
if (!(this.startRequestFetcher.Fetch(payload) is HttpRequestMessage request))
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnStartActivity));
|
||||
HttpInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnStartActivity));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
if (!(this.stopExceptionFetcher.Fetch(payload) is Exception exc))
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnException));
|
||||
HttpInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnException));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
// <copyright file="HttpInstrumentationEventSource.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.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Http.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// EventSource events emitted from the project.
|
||||
/// </summary>
|
||||
[EventSource(Name = "OpenTelemetry-Instrumentation-Http")]
|
||||
internal class HttpInstrumentationEventSource : EventSource
|
||||
{
|
||||
public static HttpInstrumentationEventSource Log = new HttpInstrumentationEventSource();
|
||||
|
||||
[NonEvent]
|
||||
public void FailedProcessResult(Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.FailedProcessResult(ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void ExceptionInitializingInstrumentation(string instrumentationType, Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.ExceptionInitializingInstrumentation(instrumentationType, ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[Event(3, Message = "Payload is NULL in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(3, handlerName, eventName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a culture-independent string representation of the given <paramref name="exception"/> object,
|
||||
/// appropriate for diagnostics tracing.
|
||||
/// </summary>
|
||||
private static string ToInvariantString(Exception exception)
|
||||
{
|
||||
var originalUICulture = Thread.CurrentThread.CurrentUICulture;
|
||||
|
||||
try
|
||||
{
|
||||
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
|
||||
return exception.ToString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.CurrentThread.CurrentUICulture = originalUICulture;
|
||||
}
|
||||
}
|
||||
|
||||
[Event(1, Message = "Failed to process result: '{0}'", Level = EventLevel.Error)]
|
||||
private void FailedProcessResult(string ex)
|
||||
{
|
||||
this.WriteEvent(1, ex);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Error initializing instrumentation type {0}. Exception : {1}", Level = EventLevel.Error)]
|
||||
private void ExceptionInitializingInstrumentation(string instrumentationType, string ex)
|
||||
{
|
||||
this.WriteEvent(2, instrumentationType, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ using System.Collections.Concurrent;
|
|||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
||||
namespace OpenTelemetry.Instrumentation.Http.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of helper methods to be used when building Http spans.
|
||||
|
|
@ -25,7 +25,7 @@ using System.Runtime.CompilerServices;
|
|||
using System.Text;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
||||
namespace OpenTelemetry.Instrumentation.Http.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Hooks into the <see cref="HttpWebRequest"/> class reflectively and writes diagnostic events as requests are processed.
|
||||
|
|
@ -87,7 +87,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
catch (Exception ex)
|
||||
{
|
||||
// If anything went wrong, just no-op. Write an event so at least we can find out.
|
||||
DependenciesInstrumentationEventSource.Log.ExceptionInitializingInstrumentation(typeof(HttpWebRequestActivitySource).FullName, ex);
|
||||
HttpInstrumentationEventSource.Log.ExceptionInitializingInstrumentation(typeof(HttpWebRequestActivitySource).FullName, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -329,7 +329,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.FailedProcessResult(ex);
|
||||
HttpInstrumentationEventSource.Log.FailedProcessResult(ex);
|
||||
}
|
||||
|
||||
activity.Stop();
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
// <copyright file="PropertyFetcher.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.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Http.Implementation
|
||||
{
|
||||
internal class PropertyFetcher
|
||||
{
|
||||
private readonly string propertyName;
|
||||
private PropertyFetch innerFetcher;
|
||||
|
||||
public PropertyFetcher(string propertyName)
|
||||
{
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public object Fetch(object obj)
|
||||
{
|
||||
if (this.innerFetcher == null)
|
||||
{
|
||||
var type = obj.GetType().GetTypeInfo();
|
||||
var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, this.propertyName, StringComparison.InvariantCultureIgnoreCase));
|
||||
if (property == null)
|
||||
{
|
||||
property = type.GetProperty(this.propertyName);
|
||||
}
|
||||
|
||||
this.innerFetcher = PropertyFetch.FetcherForProperty(property);
|
||||
}
|
||||
|
||||
return this.innerFetcher?.Fetch(obj);
|
||||
}
|
||||
|
||||
// see https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
|
||||
private class PropertyFetch
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a property fetcher from a .NET Reflection PropertyInfo class that
|
||||
/// represents a property of a particular type.
|
||||
/// </summary>
|
||||
public static PropertyFetch FetcherForProperty(PropertyInfo propertyInfo)
|
||||
{
|
||||
if (propertyInfo == null)
|
||||
{
|
||||
// returns null on any fetch.
|
||||
return new PropertyFetch();
|
||||
}
|
||||
|
||||
var typedPropertyFetcher = typeof(TypedFetchProperty<,>);
|
||||
var instantiatedTypedPropertyFetcher = typedPropertyFetcher.GetTypeInfo().MakeGenericType(
|
||||
propertyInfo.DeclaringType, propertyInfo.PropertyType);
|
||||
return (PropertyFetch)Activator.CreateInstance(instantiatedTypedPropertyFetcher, propertyInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given an object, fetch the property that this propertyFetch represents.
|
||||
/// </summary>
|
||||
public virtual object Fetch(object obj)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private class TypedFetchProperty<TObject, TProperty> : PropertyFetch
|
||||
{
|
||||
private readonly Func<TObject, TProperty> propertyFetch;
|
||||
|
||||
public TypedFetchProperty(PropertyInfo property)
|
||||
{
|
||||
this.propertyFetch = (Func<TObject, TProperty>)property.GetMethod.CreateDelegate(typeof(Func<TObject, TProperty>));
|
||||
}
|
||||
|
||||
public override object Fetch(object obj)
|
||||
{
|
||||
if (obj is TObject o)
|
||||
{
|
||||
return this.propertyFetch(o);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net452;net461</TargetFrameworks>
|
||||
<Description>HTTP, SQL and gRPC client instrumentation for OpenTelemetry .NET</Description>
|
||||
<Description>Http instrumentation for OpenTelemetry .NET</Description>
|
||||
<PackageTags>$(PackageTags);distributed-tracing</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
@ -15,8 +15,8 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using OpenTelemetry.Instrumentation.Dependencies;
|
||||
using OpenTelemetry.Instrumentation.Dependencies.Implementation;
|
||||
using OpenTelemetry.Instrumentation.Http;
|
||||
using OpenTelemetry.Instrumentation.Http.Implementation;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
{
|
||||
|
|
@ -26,38 +26,34 @@ namespace OpenTelemetry.Trace
|
|||
public static class OpenTelemetryBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Enables the outgoing requests automatic data collection for all supported activity sources.
|
||||
/// Enables HttpClient and HttpWebRequest instrumentation.
|
||||
/// </summary>
|
||||
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
|
||||
/// <param name="configureHttpClientInstrumentationOptions">HttpClient configuration options.</param>
|
||||
/// <param name="configureSqlClientInstrumentationOptions">SqlClient configuration options.</param>
|
||||
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
|
||||
public static TracerProviderBuilder AddDependencyInstrumentation(
|
||||
public static TracerProviderBuilder AddHttpInstrumentation(
|
||||
this TracerProviderBuilder builder,
|
||||
Action<HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions = null,
|
||||
Action<SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions = null)
|
||||
Action<HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions = null)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
builder.AddHttpClientDependencyInstrumentation(configureHttpClientInstrumentationOptions);
|
||||
builder.AddSqlClientDependencyInstrumentation(configureSqlClientInstrumentationOptions);
|
||||
builder.AddGrpcClientDependencyInstrumentation();
|
||||
builder.AddHttpClientInstrumentation(configureHttpClientInstrumentationOptions);
|
||||
#if NETFRAMEWORK
|
||||
builder.AddHttpWebRequestDependencyInstrumentation();
|
||||
builder.AddHttpWebRequestInstrumentation();
|
||||
#endif
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the outgoing requests automatic data collection for HttpClient.
|
||||
/// Enables HttpClient instrumentation.
|
||||
/// </summary>
|
||||
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
|
||||
/// <param name="configureHttpClientInstrumentationOptions">HttpClient configuration options.</param>
|
||||
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
|
||||
public static TracerProviderBuilder AddHttpClientDependencyInstrumentation(
|
||||
public static TracerProviderBuilder AddHttpClientInstrumentation(
|
||||
this TracerProviderBuilder builder,
|
||||
Action<HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions = null)
|
||||
{
|
||||
|
|
@ -73,55 +69,14 @@ namespace OpenTelemetry.Trace
|
|||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the outgoing requests automatic data collection for SqlClient.
|
||||
/// </summary>
|
||||
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
|
||||
/// <param name="configureSqlClientInstrumentationOptions">SqlClient configuration options.</param>
|
||||
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
|
||||
public static TracerProviderBuilder AddSqlClientDependencyInstrumentation(
|
||||
this TracerProviderBuilder builder,
|
||||
Action<SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions = null)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
var sqlOptions = new SqlClientInstrumentationOptions();
|
||||
configureSqlClientInstrumentationOptions?.Invoke(sqlOptions);
|
||||
|
||||
builder.AddInstrumentation((activitySource) => new SqlClientInstrumentation(sqlOptions));
|
||||
builder.AddActivitySource(SqlClientDiagnosticListener.ActivitySourceName);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the outgoing requests automatic data collection for GrpcClient.
|
||||
/// </summary>
|
||||
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
|
||||
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
|
||||
public static TracerProviderBuilder AddGrpcClientDependencyInstrumentation(
|
||||
this TracerProviderBuilder builder)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
builder.AddInstrumentation((activitySource) => new GrpcClientInstrumentation(activitySource));
|
||||
return builder;
|
||||
}
|
||||
|
||||
#if NETFRAMEWORK
|
||||
/// <summary>
|
||||
/// Enables the outgoing requests automatic data collection for .NET Framework HttpWebRequest activity source.
|
||||
/// Enables HttpWebRequest instrumentation.
|
||||
/// </summary>
|
||||
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
|
||||
/// <param name="configureOptions">HttpWebRequest configuration options.</param>
|
||||
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
|
||||
public static TracerProviderBuilder AddHttpWebRequestDependencyInstrumentation(
|
||||
public static TracerProviderBuilder AddHttpWebRequestInstrumentation(
|
||||
this TracerProviderBuilder builder,
|
||||
Action<HttpWebRequestInstrumentationOptions> configureOptions = null)
|
||||
{
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
// <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.Runtime.CompilerServices;
|
||||
|
||||
#if SIGNED
|
||||
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.Http.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
|
||||
#else
|
||||
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.Http.Tests")]
|
||||
#endif
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# OpenTelemetry.Instrumentation.Http
|
||||
|
||||
[](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Http)
|
||||
[](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Http)
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
dotnet add package OpenTelemetry.Instrumentation.Http
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* [OpenTelemetry Project](https://opentelemetry.io/)
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
// <copyright file="PropertyFetcher.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.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.SqlClient.Implementation
|
||||
{
|
||||
internal class PropertyFetcher
|
||||
{
|
||||
private readonly string propertyName;
|
||||
private PropertyFetch innerFetcher;
|
||||
|
||||
public PropertyFetcher(string propertyName)
|
||||
{
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public object Fetch(object obj)
|
||||
{
|
||||
if (this.innerFetcher == null)
|
||||
{
|
||||
var type = obj.GetType().GetTypeInfo();
|
||||
var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, this.propertyName, StringComparison.InvariantCultureIgnoreCase));
|
||||
if (property == null)
|
||||
{
|
||||
property = type.GetProperty(this.propertyName);
|
||||
}
|
||||
|
||||
this.innerFetcher = PropertyFetch.FetcherForProperty(property);
|
||||
}
|
||||
|
||||
return this.innerFetcher?.Fetch(obj);
|
||||
}
|
||||
|
||||
// see https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
|
||||
private class PropertyFetch
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a property fetcher from a .NET Reflection PropertyInfo class that
|
||||
/// represents a property of a particular type.
|
||||
/// </summary>
|
||||
public static PropertyFetch FetcherForProperty(PropertyInfo propertyInfo)
|
||||
{
|
||||
if (propertyInfo == null)
|
||||
{
|
||||
// returns null on any fetch.
|
||||
return new PropertyFetch();
|
||||
}
|
||||
|
||||
var typedPropertyFetcher = typeof(TypedFetchProperty<,>);
|
||||
var instantiatedTypedPropertyFetcher = typedPropertyFetcher.GetTypeInfo().MakeGenericType(
|
||||
propertyInfo.DeclaringType, propertyInfo.PropertyType);
|
||||
return (PropertyFetch)Activator.CreateInstance(instantiatedTypedPropertyFetcher, propertyInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given an object, fetch the property that this propertyFetch represents.
|
||||
/// </summary>
|
||||
public virtual object Fetch(object obj)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private class TypedFetchProperty<TObject, TProperty> : PropertyFetch
|
||||
{
|
||||
private readonly Func<TObject, TProperty> propertyFetch;
|
||||
|
||||
public TypedFetchProperty(PropertyInfo property)
|
||||
{
|
||||
this.propertyFetch = (Func<TObject, TProperty>)property.GetMethod.CreateDelegate(typeof(Func<TObject, TProperty>));
|
||||
}
|
||||
|
||||
public override object Fetch(object obj)
|
||||
{
|
||||
if (obj is TObject o)
|
||||
{
|
||||
return this.propertyFetch(o);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ using System.Data;
|
|||
using System.Diagnostics;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
||||
namespace OpenTelemetry.Instrumentation.SqlClient.Implementation
|
||||
{
|
||||
internal class SqlClientDiagnosticListener : ListenerHandler
|
||||
{
|
||||
|
|
@ -76,7 +76,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
var command = this.commandFetcher.Fetch(payload);
|
||||
if (command == null)
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.NullPayload(nameof(SqlClientDiagnosticListener), name);
|
||||
SqlClientInstrumentationEventSource.Log.NullPayload(nameof(SqlClientDiagnosticListener), name);
|
||||
activity.Stop();
|
||||
return;
|
||||
}
|
||||
|
|
@ -132,7 +132,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
if (activity == null)
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.NullActivity(name);
|
||||
SqlClientInstrumentationEventSource.Log.NullActivity(name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
if (activity == null)
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.NullActivity(name);
|
||||
SqlClientInstrumentationEventSource.Log.NullActivity(name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
}
|
||||
else
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.NullPayload(nameof(SqlClientDiagnosticListener), name);
|
||||
SqlClientInstrumentationEventSource.Log.NullPayload(nameof(SqlClientDiagnosticListener), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="DependenciesInstrumentationEventSource.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="SqlClientInstrumentationEventSource.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -19,15 +19,15 @@ using System.Diagnostics.Tracing;
|
|||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
||||
namespace OpenTelemetry.Instrumentation.SqlClient.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// EventSource events emitted from the project.
|
||||
/// </summary>
|
||||
[EventSource(Name = "OpenTelemetry-Instrumentation-Dependencies")]
|
||||
internal class DependenciesInstrumentationEventSource : EventSource
|
||||
[EventSource(Name = "OpenTelemetry-Instrumentation-SqlClient")]
|
||||
internal class SqlClientInstrumentationEventSource : EventSource
|
||||
{
|
||||
public static DependenciesInstrumentationEventSource Log = new DependenciesInstrumentationEventSource();
|
||||
public static SqlClientInstrumentationEventSource Log = new SqlClientInstrumentationEventSource();
|
||||
|
||||
[NonEvent]
|
||||
public void UnknownErrorProcessingEvent(string handlerName, string eventName, Exception ex)
|
||||
|
|
@ -38,40 +38,22 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
}
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void FailedProcessResult(Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.FailedProcessResult(ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[NonEvent]
|
||||
public void ExceptionInitializingInstrumentation(string instrumentationType, Exception ex)
|
||||
{
|
||||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
|
||||
{
|
||||
this.ExceptionInitializingInstrumentation(instrumentationType, ToInvariantString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
[Event(4, Message = "Current Activity is NULL the '{0}' callback. Span will not be recorded.", Level = EventLevel.Warning)]
|
||||
[Event(2, Message = "Current Activity is NULL the '{0}' callback. Span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullActivity(string eventName)
|
||||
{
|
||||
this.WriteEvent(4, eventName);
|
||||
this.WriteEvent(2, eventName);
|
||||
}
|
||||
|
||||
[Event(5, Message = "Payload is NULL in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
[Event(3, Message = "Payload is NULL in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void NullPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(5, handlerName, eventName);
|
||||
this.WriteEvent(3, handlerName, eventName);
|
||||
}
|
||||
|
||||
[Event(6, Message = "Payload is invalid in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
[Event(4, Message = "Payload is invalid in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
|
||||
public void InvalidPayload(string handlerName, string eventName)
|
||||
{
|
||||
this.WriteEvent(6, handlerName, eventName);
|
||||
this.WriteEvent(4, handlerName, eventName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -98,17 +80,5 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
{
|
||||
this.WriteEvent(1, handlerName, eventName, ex);
|
||||
}
|
||||
|
||||
[Event(2, Message = "Failed to process result: '{0}'", Level = EventLevel.Error)]
|
||||
private void FailedProcessResult(string ex)
|
||||
{
|
||||
this.WriteEvent(2, ex);
|
||||
}
|
||||
|
||||
[Event(3, Message = "Error initializing instrumentation type {0}. Exception : {1}", Level = EventLevel.Error)]
|
||||
private void ExceptionInitializingInstrumentation(string instrumentationType, string ex)
|
||||
{
|
||||
this.WriteEvent(3, instrumentationType, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ using System.Diagnostics;
|
|||
using System.Diagnostics.Tracing;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
||||
namespace OpenTelemetry.Instrumentation.SqlClient.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// .NET Framework SqlClient doesn't emit DiagnosticSource events.
|
||||
|
|
@ -77,7 +77,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.UnknownErrorProcessingEvent(nameof(SqlEventSourceListener), nameof(this.OnEventWritten), exc);
|
||||
SqlClientInstrumentationEventSource.Log.UnknownErrorProcessingEvent(nameof(SqlEventSourceListener), nameof(this.OnEventWritten), exc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
|
||||
if ((eventData?.Payload?.Count ?? 0) < 4)
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.InvalidPayload(nameof(SqlEventSourceListener), nameof(this.OnBeginExecute));
|
||||
SqlClientInstrumentationEventSource.Log.InvalidPayload(nameof(SqlEventSourceListener), nameof(this.OnBeginExecute));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Implementation
|
|||
|
||||
if ((eventData?.Payload?.Count ?? 0) < 3)
|
||||
{
|
||||
DependenciesInstrumentationEventSource.Log.InvalidPayload(nameof(SqlEventSourceListener), nameof(this.OnEndExecute));
|
||||
SqlClientInstrumentationEventSource.Log.InvalidPayload(nameof(SqlEventSourceListener), nameof(this.OnEndExecute));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net452;net461</TargetFrameworks>
|
||||
<Description>SqlClient instrumentation for OpenTelemetry .NET</Description>
|
||||
<PackageTags>$(PackageTags);distributed-tracing</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\OpenTelemetry.Api\Trace\SemanticConventions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenTelemetry\OpenTelemetry.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
// <copyright file="OpenTelemetryBuilderExtensions.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 OpenTelemetry.Instrumentation.SqlClient;
|
||||
using OpenTelemetry.Instrumentation.SqlClient.Implementation;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods to simplify registering of dependency instrumentation.
|
||||
/// </summary>
|
||||
public static class OpenTelemetryBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Enables SqlClient instrumentation.
|
||||
/// </summary>
|
||||
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
|
||||
/// <param name="configureSqlClientInstrumentationOptions">SqlClient configuration options.</param>
|
||||
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
|
||||
public static TracerProviderBuilder AddSqlClientDependencyInstrumentation(
|
||||
this TracerProviderBuilder builder,
|
||||
Action<SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions = null)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
var sqlOptions = new SqlClientInstrumentationOptions();
|
||||
configureSqlClientInstrumentationOptions?.Invoke(sqlOptions);
|
||||
|
||||
builder.AddInstrumentation((activitySource) => new SqlClientInstrumentation(sqlOptions));
|
||||
builder.AddActivitySource(SqlClientDiagnosticListener.ActivitySourceName);
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
// <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.Runtime.CompilerServices;
|
||||
|
||||
#if SIGNED
|
||||
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.SqlClient.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
|
||||
#else
|
||||
[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.SqlClient.Tests")]
|
||||
#endif
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# OpenTelemetry.Instrumentation.SqlClient
|
||||
|
||||
[](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.SqlClient)
|
||||
[](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.SqlClient)
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
dotnet add package OpenTelemetry.Instrumentation.SqlClient
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* [OpenTelemetry Project](https://opentelemetry.io/)
|
||||
|
|
@ -14,9 +14,9 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using OpenTelemetry.Instrumentation.Dependencies.Implementation;
|
||||
using OpenTelemetry.Instrumentation.SqlClient.Implementation;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies
|
||||
namespace OpenTelemetry.Instrumentation.SqlClient
|
||||
{
|
||||
/// <summary>
|
||||
/// SqlClient instrumentation.
|
||||
|
|
@ -20,7 +20,7 @@ using System.Diagnostics;
|
|||
using System.Text.RegularExpressions;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies
|
||||
namespace OpenTelemetry.Instrumentation.SqlClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Options for <see cref="SqlClientInstrumentation"/>.
|
||||
|
|
@ -23,10 +23,10 @@ namespace OpenTelemetry.Instrumentation.AspNet.Tests
|
|||
public class BasicTests
|
||||
{
|
||||
[Fact]
|
||||
public void AddRequestInstrumentation_BadArgs()
|
||||
public void AddAspNetInstrumentation_BadArgs()
|
||||
{
|
||||
TracerProviderBuilder builder = null;
|
||||
Assert.Throws<ArgumentNullException>(() => builder.AddRequestInstrumentation());
|
||||
Assert.Throws<ArgumentNullException>(() => builder.AddAspNetInstrumentation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Tests
|
|||
activity.SetParentId(expectedTraceId, expectedSpanId, ActivityTraceFlags.Recorded);
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
using (openTelemetry = OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddRequestInstrumentation(
|
||||
(builder) => builder.AddAspNetInstrumentation(
|
||||
(options) =>
|
||||
{
|
||||
options.RequestFilter = httpContext =>
|
||||
|
|
|
|||
|
|
@ -51,10 +51,10 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void AddRequestInstrumentation_BadArgs()
|
||||
public void AddAspNetCoreInstrumentation_BadArgs()
|
||||
{
|
||||
TracerProviderBuilder builder = null;
|
||||
Assert.Throws<ArgumentNullException>(() => builder.AddRequestInstrumentation());
|
||||
Assert.Throws<ArgumentNullException>(() => builder.AddAspNetCoreInstrumentation());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -65,7 +65,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
void ConfigureTestServices(IServiceCollection services)
|
||||
{
|
||||
this.openTelemetrySdk = OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddRequestInstrumentation()
|
||||
(builder) => builder.AddAspNetCoreInstrumentation()
|
||||
.SetResource(expectedResource)
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object)));
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
.WithWebHostBuilder(builder =>
|
||||
builder.ConfigureTestServices(services =>
|
||||
{
|
||||
this.openTelemetrySdk = OpenTelemetrySdk.CreateTracerProvider((builder) => builder.AddRequestInstrumentation()
|
||||
this.openTelemetrySdk = OpenTelemetrySdk.CreateTracerProvider((builder) => builder.AddAspNetCoreInstrumentation()
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object)));
|
||||
})))
|
||||
{
|
||||
|
|
@ -154,7 +154,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
builder.ConfigureTestServices(services =>
|
||||
{
|
||||
this.openTelemetrySdk = OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddRequestInstrumentation((opt) => opt.TextFormat = textFormat.Object)
|
||||
(builder) => builder.AddAspNetCoreInstrumentation((opt) => opt.TextFormat = textFormat.Object)
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object)));
|
||||
})))
|
||||
{
|
||||
|
|
@ -187,7 +187,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
{
|
||||
this.openTelemetrySdk = OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) =>
|
||||
builder.AddRequestInstrumentation((opt) => opt.RequestFilter = (ctx) => ctx.Request.Path != "/api/values/2")
|
||||
builder.AddAspNetCoreInstrumentation((opt) => opt.RequestFilter = (ctx) => ctx.Request.Path != "/api/values/2")
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
builder.ConfigureTestServices((IServiceCollection services) =>
|
||||
{
|
||||
services.AddSingleton<CallbackMiddleware.CallbackMiddlewareImpl>(new TestCallbackMiddlewareImpl(statusCode, reasonPhrase));
|
||||
services.AddOpenTelemetry((builder) => builder.AddRequestInstrumentation()
|
||||
services.AddOpenTelemetry((builder) => builder.AddAspNetCoreInstrumentation()
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object)));
|
||||
}))
|
||||
.CreateClient())
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
# Create a container for running the OpenTelemetry dependency unit tests.
|
||||
# This should be run from the root of the repo:
|
||||
# opentelemetry>docker build -f test\OpenTelemetry.Instrumentation.Dependencies.Tests\dockerfile .
|
||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
|
||||
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /wait
|
||||
RUN chmod +x /wait
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build
|
||||
ARG PUBLISH_CONFIGURATION=Release
|
||||
ARG PUBLISH_FRAMEWORK=netcoreapp3.1
|
||||
WORKDIR /src
|
||||
COPY ["NuGet.config", ""] # Needed for the .NET 5 preview packages. Won't be needed in the future.
|
||||
COPY ["test/OpenTelemetry.Instrumentation.Dependencies.Tests/OpenTelemetry.Instrumentation.Dependencies.Tests.csproj", "test/OpenTelemetry.Instrumentation.Dependencies.Tests/"]
|
||||
COPY ["src/OpenTelemetry.Instrumentation.Dependencies/OpenTelemetry.Instrumentation.Dependencies.csproj", "src/OpenTelemetry.Instrumentation.Dependencies/"]
|
||||
COPY ["src/OpenTelemetry/OpenTelemetry.csproj", "src/OpenTelemetry/"]
|
||||
COPY ["src/OpenTelemetry.Api/OpenTelemetry.Api.csproj", "src/OpenTelemetry.Api/"]
|
||||
RUN dotnet restore "test/OpenTelemetry.Instrumentation.Dependencies.Tests/OpenTelemetry.Instrumentation.Dependencies.Tests.csproj" --configfile "NuGet.config"
|
||||
COPY . .
|
||||
WORKDIR "/src/test/OpenTelemetry.Instrumentation.Dependencies.Tests"
|
||||
RUN dotnet publish "OpenTelemetry.Instrumentation.Dependencies.Tests.csproj" -c "${PUBLISH_CONFIGURATION}" -f "${PUBLISH_FRAMEWORK}" -o /build -p:IntegrationBuild=true --no-restore
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /test
|
||||
COPY --from=build /build .
|
||||
ENTRYPOINT ["dotnet", "test", "OpenTelemetry.Instrumentation.Dependencies.Tests.dll"]
|
||||
|
|
@ -58,7 +58,7 @@ namespace OpenTelemetry.Instrumentation.GrpcClient.Tests
|
|||
|
||||
using (OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder
|
||||
.AddGrpcClientDependencyInstrumentation()
|
||||
.AddGrpcClientInstrumentation()
|
||||
.SetResource(expectedResource)
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))))
|
||||
{
|
||||
|
|
@ -109,7 +109,8 @@ namespace OpenTelemetry.Instrumentation.GrpcClient.Tests
|
|||
|
||||
using (OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder
|
||||
.AddDependencyInstrumentation() // AddDependencyInstrumentation applies both gRPC client and HttpClient instrumentation
|
||||
.AddHttpClientInstrumentation()
|
||||
.AddGrpcClientInstrumentation()
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))))
|
||||
{
|
||||
var channel = GrpcChannel.ForAddress(uri);
|
||||
|
|
|
|||
|
|
@ -14,10 +14,11 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry.Instrumentation.Grpc;
|
||||
using OpenTelemetry.Trace;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
namespace OpenTelemetry.Instrumentation.GrpcClient.Tests
|
||||
{
|
||||
public class GrpcTagHelperTests
|
||||
{
|
||||
|
|
@ -19,13 +19,14 @@
|
|||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||
|
||||
<PackageReference Include="Google.Protobuf" Version="3.12.3" />
|
||||
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.30.0-pre1" />
|
||||
<PackageReference Include="Grpc.Net.Client" Version="2.30.0-pre1" />
|
||||
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.30.0" />
|
||||
<PackageReference Include="Grpc.Net.Client" Version="2.30.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.25.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Dependencies\OpenTelemetry.Instrumentation.Dependencies.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Grpc\OpenTelemetry.Instrumentation.Grpc.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Http\OpenTelemetry.Instrumentation.Http.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry\OpenTelemetry.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ using OpenTelemetry.Trace;
|
|||
using OpenTelemetry.Trace.Export;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
namespace OpenTelemetry.Instrumentation.Http.Tests
|
||||
{
|
||||
public partial class HttpClientTests : IDisposable
|
||||
{
|
||||
|
|
@ -53,7 +53,8 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
public void AddDependencyInstrumentation_BadArgs()
|
||||
{
|
||||
TracerProviderBuilder builder = null;
|
||||
Assert.Throws<ArgumentNullException>(() => builder.AddDependencyInstrumentation());
|
||||
Assert.Throws<ArgumentNullException>(() => builder.AddHttpClientInstrumentation());
|
||||
Assert.Throws<ArgumentNullException>(() => builder.AddHttpInstrumentation());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -92,7 +93,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
});
|
||||
|
||||
using (OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddHttpClientDependencyInstrumentation(o => o.TextFormat = mockTextFormat.Object)
|
||||
(builder) => builder.AddHttpClientInstrumentation(o => o.TextFormat = mockTextFormat.Object)
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))))
|
||||
{
|
||||
using var c = new HttpClient();
|
||||
|
|
@ -145,7 +146,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
parent.ActivityTraceFlags = ActivityTraceFlags.Recorded;
|
||||
|
||||
using (OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddHttpClientDependencyInstrumentation((opt) => opt.TextFormat = textFormat.Object)
|
||||
(builder) => builder.AddHttpClientInstrumentation((opt) => opt.TextFormat = textFormat.Object)
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))))
|
||||
{
|
||||
using var c = new HttpClient();
|
||||
|
|
@ -175,7 +176,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
var spanProcessor = new Mock<ActivityProcessor>();
|
||||
|
||||
using (OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddHttpClientDependencyInstrumentation()
|
||||
(builder) => builder.AddHttpClientInstrumentation()
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))))
|
||||
{
|
||||
using var c = new HttpClient();
|
||||
|
|
@ -193,7 +194,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
var spanProcessor = new Mock<ActivityProcessor>();
|
||||
|
||||
using (OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddHttpClientDependencyInstrumentation()
|
||||
(builder) => builder.AddHttpClientInstrumentation()
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))))
|
||||
{
|
||||
using var c = new HttpClient();
|
||||
|
|
@ -219,7 +220,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
request.Headers.Add("traceparent", "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01");
|
||||
|
||||
using (OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddHttpClientDependencyInstrumentation()
|
||||
(builder) => builder.AddHttpClientInstrumentation()
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))))
|
||||
{
|
||||
using var c = new HttpClient();
|
||||
|
|
@ -236,7 +237,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
|
||||
using (OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) =>
|
||||
builder.AddHttpClientDependencyInstrumentation(
|
||||
builder.AddHttpClientInstrumentation(
|
||||
(opt) => opt.FilterFunc = (req) => !req.RequestUri.OriginalString.Contains(this.url))
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))))
|
||||
{
|
||||
|
|
@ -253,7 +254,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
var spanProcessor = new Mock<ActivityProcessor>();
|
||||
|
||||
using (OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddHttpClientDependencyInstrumentation()
|
||||
(builder) => builder.AddHttpClientInstrumentation()
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))))
|
||||
{
|
||||
using var c = new HttpClient();
|
||||
|
|
@ -30,7 +30,7 @@ using OpenTelemetry.Trace;
|
|||
using OpenTelemetry.Trace.Export;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
namespace OpenTelemetry.Instrumentation.Http.Tests
|
||||
{
|
||||
public partial class HttpClientTests
|
||||
{
|
||||
|
|
@ -56,7 +56,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
using (serverLifeTime)
|
||||
|
||||
using (OpenTelemetrySdk.CreateTracerProvider(
|
||||
(builder) => builder.AddHttpClientDependencyInstrumentation((opt) => opt.SetHttpFlavor = tc.SetHttpFlavor)
|
||||
(builder) => builder.AddHttpClientInstrumentation((opt) => opt.SetHttpFlavor = tc.SetHttpFlavor)
|
||||
.SetResource(expectedResource)
|
||||
.AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))))
|
||||
{
|
||||
|
|
@ -18,7 +18,7 @@ using System.IO;
|
|||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
namespace OpenTelemetry.Instrumentation.Http.Tests
|
||||
{
|
||||
public static class HttpTestData
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var serializer = new JsonSerializer();
|
||||
var input = serializer.Deserialize<HttpOutTestCase[]>(new JsonTextReader(new StreamReader(assembly.GetManifestResourceStream("OpenTelemetry.Instrumentation.Dependencies.Tests.http-out-test-cases.json"))));
|
||||
var input = serializer.Deserialize<HttpOutTestCase[]>(new JsonTextReader(new StreamReader(assembly.GetManifestResourceStream("OpenTelemetry.Instrumentation.Http.Tests.http-out-test-cases.json"))));
|
||||
|
||||
return GetArgumentsFromTestCaseObject(input);
|
||||
}
|
||||
|
|
@ -24,12 +24,12 @@ using System.Net;
|
|||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Instrumentation.Dependencies.Implementation;
|
||||
using OpenTelemetry.Instrumentation.Http.Implementation;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Trace;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
namespace OpenTelemetry.Instrumentation.Http.Tests
|
||||
{
|
||||
public class HttpWebRequestActivitySourceTests : IDisposable
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ using OpenTelemetry.Trace;
|
|||
using OpenTelemetry.Trace.Export;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
namespace OpenTelemetry.Instrumentation.Http.Tests
|
||||
{
|
||||
public partial class HttpWebRequestTests : IDisposable
|
||||
{
|
||||
|
|
@ -63,7 +63,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
using var shutdownSignal = OpenTelemetrySdk.CreateTracerProvider(b =>
|
||||
{
|
||||
b.AddProcessorPipeline(c => c.AddProcessor(ap => activityProcessor.Object));
|
||||
b.AddHttpWebRequestDependencyInstrumentation();
|
||||
b.AddHttpWebRequestInstrumentation();
|
||||
});
|
||||
|
||||
var request = (HttpWebRequest)WebRequest.Create(this.url);
|
||||
|
|
@ -110,7 +110,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
using var shutdownSignal = OpenTelemetrySdk.CreateTracerProvider(b =>
|
||||
{
|
||||
b.AddProcessorPipeline(c => c.AddProcessor(ap => activityProcessor.Object));
|
||||
b.AddHttpWebRequestDependencyInstrumentation(options => options.TextFormat = textFormat.Object);
|
||||
b.AddHttpWebRequestInstrumentation(options => options.TextFormat = textFormat.Object);
|
||||
});
|
||||
|
||||
var request = (HttpWebRequest)WebRequest.Create(this.url);
|
||||
|
|
@ -150,7 +150,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
using var shutdownSignal = OpenTelemetrySdk.CreateTracerProvider(b =>
|
||||
{
|
||||
b.AddProcessorPipeline(c => c.AddProcessor(ap => activityProcessor.Object));
|
||||
b.AddHttpWebRequestDependencyInstrumentation();
|
||||
b.AddHttpWebRequestInstrumentation();
|
||||
});
|
||||
|
||||
var request = new HttpRequestMessage
|
||||
|
|
@ -174,7 +174,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
using var shutdownSignal = OpenTelemetrySdk.CreateTracerProvider(b =>
|
||||
{
|
||||
b.AddProcessorPipeline(c => c.AddProcessor(ap => activityProcessor.Object));
|
||||
b.AddHttpWebRequestDependencyInstrumentation(
|
||||
b.AddHttpWebRequestInstrumentation(
|
||||
c => c.FilterFunc = (req) => !req.RequestUri.OriginalString.Contains(this.url));
|
||||
});
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ using OpenTelemetry.Trace;
|
|||
using OpenTelemetry.Trace.Export;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
namespace OpenTelemetry.Instrumentation.Http.Tests
|
||||
{
|
||||
public partial class HttpWebRequestTests
|
||||
{
|
||||
|
|
@ -52,7 +52,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
{
|
||||
b.SetResource(expectedResource);
|
||||
b.AddProcessorPipeline(c => c.AddProcessor(ap => activityProcessor.Object));
|
||||
b.AddHttpWebRequestDependencyInstrumentation(options => options.SetHttpFlavor = tc.SetHttpFlavor);
|
||||
b.AddHttpWebRequestInstrumentation(options => options.SetHttpFlavor = tc.SetHttpFlavor);
|
||||
});
|
||||
|
||||
tc.Url = HttpTestData.NormalizeValues(tc.Url, host, port);
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Dependencies\OpenTelemetry.Instrumentation.Dependencies.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Http\OpenTelemetry.Instrumentation.Http.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry\OpenTelemetry.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Description>Unit test project for OpenTelemetry SqlClient instrumentations</Description>
|
||||
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
|
||||
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);net452;net461</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="xunit.runner.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="xunit.runner.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\OpenTelemetry.Tests\Implementation\Internal\SkipUnlessEnvVarFoundTheoryAttribute.cs" Link="SkipUnlessEnvVarFoundTheoryAttribute.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.1.1" Condition="'$(TargetFramework)' != 'net452'" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="Moq" Version="4.14.5" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" Condition="'$(TargetFramework)' == 'net452'" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" Condition="'$(TargetFramework)' == 'net452'" />
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Data" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.SqlClient\OpenTelemetry.Instrumentation.SqlClient.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry\OpenTelemetry.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
namespace OpenTelemetry.Instrumentation.SqlClient.Tests
|
||||
{
|
||||
public class SqlClientInstrumentationOptionsTests
|
||||
{
|
||||
|
|
@ -25,13 +25,13 @@ using System.Data.SqlClient;
|
|||
using Microsoft.Data.SqlClient;
|
||||
#endif
|
||||
using Moq;
|
||||
using OpenTelemetry.Instrumentation.Dependencies.Implementation;
|
||||
using OpenTelemetry.Instrumentation.SqlClient.Implementation;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
namespace OpenTelemetry.Instrumentation.SqlClient.Tests
|
||||
{
|
||||
public class SqlClientTests : IDisposable
|
||||
{
|
||||
|
|
@ -22,13 +22,14 @@ using System.Diagnostics.Tracing;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using OpenTelemetry.Instrumentation.Dependencies.Implementation;
|
||||
using OpenTelemetry.Instrumentation.SqlClient;
|
||||
using OpenTelemetry.Instrumentation.SqlClient.Implementation;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
namespace OpenTelemetry.Instrumentation.SqlClient.Tests
|
||||
{
|
||||
public class SqlEventSourceTests
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Start a sql container and then run OpenTelemetry sql integration tests.
|
||||
# This should be run from the root of the repo:
|
||||
# opentelemetry>docker-compose --file=test/OpenTelemetry.Instrumentation.Dependencies.Tests/docker-compose.integration.yml --project-directory=. up --exit-code-from=sql_integration_tests --build
|
||||
# opentelemetry>docker-compose --file=test/OpenTelemetry.Instrumentation.SqlClient.Tests/docker-compose.integration.yml --project-directory=. up --exit-code-from=sql_integration_tests --build
|
||||
version: '3.1'
|
||||
|
||||
services:
|
||||
|
|
@ -16,8 +16,8 @@ services:
|
|||
sql_integration_tests:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./test/OpenTelemetry.Instrumentation.Dependencies.Tests/dockerfile
|
||||
entrypoint: ["bash", "-c", "/wait && dotnet test OpenTelemetry.Instrumentation.Dependencies.Tests.dll --filter CategoryName=SqlIntegrationTests"]
|
||||
dockerfile: ./test/OpenTelemetry.Instrumentation.SqlClient.Tests/dockerfile
|
||||
entrypoint: ["bash", "-c", "/wait && dotnet test OpenTelemetry.Instrumentation.SqlClient.Tests.dll --filter CategoryName=SqlIntegrationTests"]
|
||||
environment:
|
||||
- OTEL_SQLCONNECTIONSTRING=Data Source=sql; User ID=sa; Password=Pass@word18
|
||||
- WAIT_HOSTS=sql:1433
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
# Create a container for running the OpenTelemetry dependency unit tests.
|
||||
# This should be run from the root of the repo:
|
||||
# opentelemetry>docker build -f test\OpenTelemetry.Instrumentation.SqlClient.Tests\dockerfile .
|
||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
|
||||
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /wait
|
||||
RUN chmod +x /wait
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build
|
||||
ARG PUBLISH_CONFIGURATION=Release
|
||||
ARG PUBLISH_FRAMEWORK=netcoreapp3.1
|
||||
WORKDIR /src
|
||||
COPY ["NuGet.config", ""] # Needed for the .NET 5 preview packages. Won't be needed in the future.
|
||||
COPY ["test/OpenTelemetry.Instrumentation.SqlClient.Tests/OpenTelemetry.Instrumentation.SqlClient.Tests.csproj", "test/OpenTelemetry.Instrumentation.SqlClient.Tests/"]
|
||||
COPY ["src/OpenTelemetry.Instrumentation.SqlClient/OpenTelemetry.Instrumentation.SqlClient.csproj", "src/OpenTelemetry.Instrumentation.SqlClient/"]
|
||||
COPY ["src/OpenTelemetry/OpenTelemetry.csproj", "src/OpenTelemetry/"]
|
||||
COPY ["src/OpenTelemetry.Api/OpenTelemetry.Api.csproj", "src/OpenTelemetry.Api/"]
|
||||
RUN dotnet restore "test/OpenTelemetry.Instrumentation.SqlClient.Tests/OpenTelemetry.Instrumentation.SqlClient.Tests.csproj" --configfile "NuGet.config"
|
||||
COPY . .
|
||||
WORKDIR "/src/test/OpenTelemetry.Instrumentation.SqlClient.Tests"
|
||||
RUN dotnet publish "OpenTelemetry.Instrumentation.SqlClient.Tests.csproj" -c "${PUBLISH_CONFIGURATION}" -f "${PUBLISH_FRAMEWORK}" -o /build -p:IntegrationBuild=true --no-restore
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /test
|
||||
COPY --from=build /build .
|
||||
ENTRYPOINT ["dotnet", "test", "OpenTelemetry.Instrumentation.SqlClient.Tests.dll"]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"maxParallelThreads": 1,
|
||||
"parallelizeTestCollections": false
|
||||
}
|
||||
|
|
@ -19,7 +19,6 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Api\OpenTelemetry.Api.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Dependencies\OpenTelemetry.Instrumentation.Dependencies.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Extensions.Hosting\OpenTelemetry.Extensions.Hosting.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry\OpenTelemetry.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ using Microsoft.AspNetCore.Builder;
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace TestApp.AspNetCore._3._1
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Api\OpenTelemetry.Api.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.Dependencies\OpenTelemetry.Instrumentation.Dependencies.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.Extensions.Hosting\OpenTelemetry.Extensions.Hosting.csproj" />
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry\OpenTelemetry.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in New Issue