OTLP over http/protobuf as default exporter (#351)
This commit is contained in:
parent
d741e31e8d
commit
c65a787d7f
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.28803.452
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.32112.339
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenTelemetry.ClrProfiler.Native", "src\OpenTelemetry.ClrProfiler.Native\OpenTelemetry.ClrProfiler.Native.vcxproj", "{91B6272F-5780-4C94-8071-DBBA7B4F67F3}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
|
@ -129,7 +129,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTests.StartupHoo
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.StartupHook", "test\test-applications\integrations\Samples.StartupHook\Samples.StartupHook.csproj", "{FF665CC4-6643-4614-A1A0-FA182E3AF37C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Instrumentation.AdditionalDeps", "src\OpenTelemetry.Instrumentation.AdditionalDeps\OpenTelemetry.Instrumentation.AdditionalDeps.csproj", "{E026D9FA-FBD5-4066-AF6A-FB63DE28521F}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.AdditionalDeps", "src\OpenTelemetry.Instrumentation.AdditionalDeps\OpenTelemetry.Instrumentation.AdditionalDeps.csproj", "{E026D9FA-FBD5-4066-AF6A-FB63DE28521F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.ClrProfiler.Managed.Tests", "test\OpenTelemetry.ClrProfiler.Managed.Tests\OpenTelemetry.ClrProfiler.Managed.Tests.csproj", "{065FEB4E-A99E-4A59-8112-1CB30CF794F9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -499,6 +501,18 @@ Global
|
|||
{E026D9FA-FBD5-4066-AF6A-FB63DE28521F}.Release|x64.Build.0 = Release|Any CPU
|
||||
{E026D9FA-FBD5-4066-AF6A-FB63DE28521F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E026D9FA-FBD5-4066-AF6A-FB63DE28521F}.Release|x86.Build.0 = Release|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Release|x64.Build.0 = Release|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -542,6 +556,7 @@ Global
|
|||
{0584ADC1-956E-49B0-A46F-8405AA2AD207} = {357C3F25-98CA-41C6-BA2C-20968695D026}
|
||||
{FF665CC4-6643-4614-A1A0-FA182E3AF37C} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
|
||||
{E026D9FA-FBD5-4066-AF6A-FB63DE28521F} = {9E5F0022-0A50-40BF-AC6A-C3078585ECAB}
|
||||
{065FEB4E-A99E-4A59-8112-1CB30CF794F9} = {5C915382-C886-457D-8641-9E766D8E5A17}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F}
|
||||
|
|
|
@ -125,6 +125,11 @@ partial class Build
|
|||
.SetConfiguration(BuildConfiguration)
|
||||
.SetNoRestore(true));
|
||||
|
||||
DotNetBuild(x => x
|
||||
.SetProjectFile(Solution.GetProject(Projects.Tests.ClrProfilerManagedTests))
|
||||
.SetConfiguration(BuildConfiguration)
|
||||
.SetNoRestore(true));
|
||||
|
||||
DotNetMSBuild(x => x
|
||||
.SetTargetPath(MsBuildProject)
|
||||
.SetTargetPlatform(Platform)
|
||||
|
@ -265,7 +270,8 @@ partial class Build
|
|||
|
||||
var unitTestProjects = new[]
|
||||
{
|
||||
Solution.GetProject(Projects.Tests.ClrProfilerManagedLoaderTests)
|
||||
Solution.GetProject(Projects.Tests.ClrProfilerManagedLoaderTests),
|
||||
Solution.GetProject(Projects.Tests.ClrProfilerManagedTests)
|
||||
};
|
||||
|
||||
DotNetTest(config => config
|
||||
|
|
|
@ -12,6 +12,7 @@ public static class Projects
|
|||
public const string ClrProfilerNativeTests = "OpenTelemetry.ClrProfiler.Native.Tests";
|
||||
public const string ClrProfilerManagedLoaderTests = "OpenTelemetry.ClrProfiler.Managed.Loader.Tests";
|
||||
public const string ClrProfilerManagedBootstrappingTests = "OpenTelemetry.ClrProfiler.Managed.Bootstrapping.Tests";
|
||||
public const string ClrProfilerManagedTests = "OpenTelemetry.ClrProfiler.Managed.Tests";
|
||||
|
||||
public const string IntegrationTestsHelpers = "IntegrationTests.Helpers";
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ services:
|
|||
- "8888:8888" # Prometheus metrics exposed by the collector
|
||||
- "8889:8889" # Prometheus exporter metrics
|
||||
- "13133:13133" # health_check extension
|
||||
- "4317:4317" # OTLP gRPC receiver
|
||||
- "4318:4318" # OTLP http/protobuf receiver
|
||||
- "55679:55679" # zpages extension
|
||||
- "9411:9411" # zipkin receiver
|
||||
depends_on:
|
||||
|
|
|
@ -59,7 +59,6 @@ export DOTNET_STARTUP_HOOKS="${CURDIR}/bin/tracer-home/netcoreapp3.1/OpenTelemet
|
|||
export OTEL_DOTNET_TRACER_HOME="${CURDIR}/bin/tracer-home"
|
||||
export OTEL_INTEGRATIONS="${CURDIR}/bin/tracer-home/integrations.json"
|
||||
export OTEL_TRACE_DEBUG="1"
|
||||
export OTEL_EXPORTER="zipkin"
|
||||
export OTEL_DUMP_ILREWRITE_ENABLED="0"
|
||||
export OTEL_CLR_ENABLE_INLINING="1"
|
||||
export OTEL_PROFILER_EXCLUDE_PROCESSES="dotnet.exe,dotnet"
|
||||
|
|
|
@ -65,13 +65,13 @@ The exporter is used to output the telemetry.
|
|||
|
||||
| Environment variable | Description | Default |
|
||||
|-|-|-|
|
||||
| `OTEL_EXPORTER` | The exporter to be used. The Tracer uses it to encode and dispatch traces. Available values are: `zipkin`, `jeager`, `otlp`. | |
|
||||
| `OTEL_EXPORTER` | The exporter to be used. The Tracer uses it to encode and dispatch traces. Available values are: `zipkin`, `jeager`, `otlp`. | `otlp` |
|
||||
| `OTEL_EXPORTER_JAEGER_AGENT_HOST` | Hostname for the Jaeger agent. | `localhost` |
|
||||
| `OTEL_EXPORTER_JAEGER_AGENT_PORT` | Port for the Jaeger agent. | `6831` |
|
||||
| `OTEL_EXPORTER_OTLP_ENDPOINT` | Target endpoint for OTLP exporter. More details [here](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md). | `http://localhost:4318` |
|
||||
| `OTEL_EXPORTER_OTLP_ENDPOINT` | Target endpoint for OTLP exporter. More details [here](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md). | `http://localhost:4318` for `http/protobuf` protocol, `http://localhost:4317` for `grpc` protocol |
|
||||
| `OTEL_EXPORTER_OTLP_HEADERS` | Key-value pairs to be used as headers associated with gRPC or HTTP requests. More details [here](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md). | |
|
||||
| `OTEL_EXPORTER_OTLP_TIMEOUT` | Maximum time the OTLP exporter will wait for each batch export. | `1000` (ms) |
|
||||
| `OTEL_EXPORTER_OTLP_PROTOCOL` | The OTLP expoter transport protocol. Supported values: `grpc`, `http/protobuf`. [1] | `grpc` |
|
||||
| `OTEL_EXPORTER_OTLP_PROTOCOL` | The OTLP expoter transport protocol. Supported values: `grpc`, `http/protobuf`. [1] | `http/protobuf` |
|
||||
| `OTEL_EXPORTER_ZIPKIN_ENDPOINT` | Zipkin URL. | `http://localhost:8126` |
|
||||
|
||||
**[1]**: `OTEL_EXPORTER_OTLP_PROTOCOL` remarks:
|
||||
|
|
|
@ -22,10 +22,21 @@ namespace OpenTelemetry.ClrProfiler.Managed.Configuration
|
|||
/// <summary>
|
||||
/// Configuration key for the exporter to be used. The Tracer uses it to encode and
|
||||
/// dispatch traces.
|
||||
/// Default is <c>"Zipkin"</c>.
|
||||
/// Default is <c>"otlp"</c>.
|
||||
/// </summary>
|
||||
public const string Exporter = "OTEL_EXPORTER";
|
||||
|
||||
/// <summary>
|
||||
/// Configuration key for the otlp protocol to be used.
|
||||
/// Default is <c>"http/protobuf"</c>.
|
||||
/// </summary>
|
||||
public const string ExporterOtlpProtocol = "OTEL_EXPORTER_OTLP_PROTOCOL";
|
||||
|
||||
/// <summary>
|
||||
/// Configuration key for the otlp exporter endpoint to be used.
|
||||
/// </summary>
|
||||
public const string ExporterOtlpEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT";
|
||||
|
||||
/// <summary>
|
||||
/// Configuration key for whether the console exporter is enabled.
|
||||
/// </summary>
|
||||
|
@ -42,7 +53,7 @@ namespace OpenTelemetry.ClrProfiler.Managed.Configuration
|
|||
public const string DisabledInstrumentations = "OTEL_DOTNET_TRACER_DISABLED_INSTRUMENTATIONS";
|
||||
|
||||
/// <summary>
|
||||
/// Configuration key for colon (:) separated list of plugins repesented by <see cref="System.Type.AssemblyQualifiedName"/>.
|
||||
/// Configuration key for colon (:) separated list of plugins represented by <see cref="System.Type.AssemblyQualifiedName"/>.
|
||||
/// </summary>
|
||||
public const string ProviderPlugins = "OTEL_DOTNET_TRACER_INSTRUMENTATION_PLUGINS";
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
#if NETCOREAPP3_1
|
||||
using OpenTelemetry.Exporter;
|
||||
#endif
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
|
@ -70,21 +71,32 @@ namespace OpenTelemetry.ClrProfiler.Managed.Configuration
|
|||
break;
|
||||
case "otlp":
|
||||
#if NETCOREAPP3_1
|
||||
// Adding the OtlpExporter creates a GrpcChannel.
|
||||
// This switch must be set before creating a GrpcChannel/HttpClient when calling an insecure gRPC service.
|
||||
// See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
if (!settings.OtlpExportProtocol.HasValue || settings.OtlpExportProtocol != OtlpExportProtocol.HttpProtobuf)
|
||||
{
|
||||
// Adding the OtlpExporter creates a GrpcChannel.
|
||||
// This switch must be set before creating a GrpcChannel/HttpClient when calling an insecure gRPC service.
|
||||
// See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
}
|
||||
#endif
|
||||
builder.AddOtlpExporter(options =>
|
||||
{
|
||||
options.ExportProcessorType = ExportProcessorType.Simple; // workaround for https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/issues/290
|
||||
if (settings.OtlpExportProtocol.HasValue)
|
||||
{
|
||||
options.Protocol = settings.OtlpExportProtocol.Value;
|
||||
}
|
||||
|
||||
if (settings.OtlpExportEndpoint != null)
|
||||
{
|
||||
options.Endpoint = settings.OtlpExportEndpoint;
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "":
|
||||
case null:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("The exporter name is not recognised");
|
||||
throw new FormatException($"The exporter name '{settings.Exporter}' is not recognized");
|
||||
}
|
||||
|
||||
return builder;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Exporter;
|
||||
|
||||
namespace OpenTelemetry.ClrProfiler.Managed.Configuration
|
||||
{
|
||||
|
@ -23,7 +24,10 @@ namespace OpenTelemetry.ClrProfiler.Managed.Configuration
|
|||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
Exporter = source.GetString(ConfigurationKeys.Exporter);
|
||||
Exporter = source.GetString(ConfigurationKeys.Exporter) ?? "otlp";
|
||||
OtlpExportProtocol = GetExporterOtlpProtocol(source);
|
||||
OtlpExportEndpoint = GetExporterOtlpEndpoint(source, OtlpExportProtocol);
|
||||
|
||||
LoadTracerAtStartup = source.GetBool(ConfigurationKeys.LoadTracerAtStartup) ?? true;
|
||||
ConsoleExporterEnabled = source.GetBool(ConfigurationKeys.ConsoleExporterEnabled) ?? true;
|
||||
|
||||
|
@ -89,16 +93,11 @@ namespace OpenTelemetry.ClrProfiler.Managed.Configuration
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether tracing is enabled.
|
||||
/// Gets a value indicating whether tracing is enabled.
|
||||
/// Default is <c>true</c>.
|
||||
/// </summary>
|
||||
/// <seealso cref="ConfigurationKeys.TraceEnabled"/>
|
||||
public bool TraceEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version of the service
|
||||
/// </summary>
|
||||
public string ServiceVersion { get; }
|
||||
public bool TraceEnabled { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the tracer should be loaded by the profiler. Default is true.
|
||||
|
@ -111,14 +110,16 @@ namespace OpenTelemetry.ClrProfiler.Managed.Configuration
|
|||
public string Exporter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets jaeger exporter agent host.
|
||||
/// Gets the the OTLP transport protocol. Supported values: Grpc and HttpProtobuf.
|
||||
/// </summary>
|
||||
public string JaegerExporterAgentHost { get; }
|
||||
public OtlpExportProtocol? OtlpExportProtocol { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets jaeger exporter agent port.
|
||||
/// Gets the the OTLP exporter endpoint.
|
||||
/// Will be removed when https://github.com/open-telemetry/opentelemetry-dotnet/pull/2868 is released.
|
||||
/// </summary>
|
||||
public int JaegerExporterAgentPort { get; }
|
||||
// TODO: To be removed when https://github.com/open-telemetry/opentelemetry-dotnet/pull/2868 is released.
|
||||
public Uri OtlpExportEndpoint { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the console exporter is enabled.
|
||||
|
@ -131,12 +132,12 @@ namespace OpenTelemetry.ClrProfiler.Managed.Configuration
|
|||
public IList<Instrumentation> EnabledInstrumentations { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of plugins repesented by <see cref="Type.AssemblyQualifiedName"/>.
|
||||
/// Gets the list of plugins represented by <see cref="Type.AssemblyQualifiedName"/>.
|
||||
/// </summary>
|
||||
public IList<string> TracerPlugins { get; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of activitysources to be added to the tracer at the startup.
|
||||
/// Gets the list of activity sources to be added to the tracer at the startup.
|
||||
/// </summary>
|
||||
public IList<string> ActivitySources { get; } = new List<string> { "OpenTelemetry.ClrProfiler.*" };
|
||||
|
||||
|
@ -164,5 +165,35 @@ namespace OpenTelemetry.ClrProfiler.Managed.Configuration
|
|||
|
||||
return new Settings(configurationSource);
|
||||
}
|
||||
|
||||
private static OtlpExportProtocol? GetExporterOtlpProtocol(IConfigurationSource source)
|
||||
{
|
||||
// the defualt in SDK is grpc. http/protobuf should be default for our purposes
|
||||
var exporterOtlpProtocol = source.GetString(ConfigurationKeys.ExporterOtlpProtocol);
|
||||
|
||||
if (string.IsNullOrEmpty(exporterOtlpProtocol) || exporterOtlpProtocol == "http/protobuf")
|
||||
{
|
||||
// override settings only for http/protobuf
|
||||
// the second part of the condition is needed to override default endpoint as long as https://github.com/open-telemetry/opentelemetry-dotnet/pull/2868 is not fixed
|
||||
return OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf;
|
||||
}
|
||||
|
||||
// null value here means that it will be handled by OTEL .NET SDK
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Uri GetExporterOtlpEndpoint(IConfigurationSource source, OtlpExportProtocol? otlpExportProtocol)
|
||||
{
|
||||
var exporterOtlpEndpoint = source.GetString(ConfigurationKeys.ExporterOtlpEndpoint);
|
||||
|
||||
if (otlpExportProtocol == OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf && string.IsNullOrWhiteSpace(exporterOtlpEndpoint))
|
||||
{
|
||||
// override endpoint only for otlp over http/protobuf
|
||||
return new Uri("http://localhost:4318/v1/traces");
|
||||
}
|
||||
|
||||
// null value here means that it will be handled by OTEL .NET SDK
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("OpenTelemetry.ClrProfiler.Managed.Tests")]
|
|
@ -15,7 +15,14 @@
|
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- StyleCop -->
|
||||
|
|
|
@ -1,18 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.ClrProfiler.Managed\OpenTelemetry.ClrProfiler.Managed.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,18 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.ClrProfiler.Managed.Loader\OpenTelemetry.ClrProfiler.Managed.Loader.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using FluentAssertions.Execution;
|
||||
using OpenTelemetry.ClrProfiler.Managed.Configuration;
|
||||
using OpenTelemetry.Exporter;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.ClrProfiler.Managed.Tests.Configuration
|
||||
{
|
||||
public class SettingsTests : IDisposable
|
||||
{
|
||||
public SettingsTests()
|
||||
{
|
||||
ClearEnvVars();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ClearEnvVars();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromDefaultSources_DefaultValues()
|
||||
{
|
||||
var settings = Settings.FromDefaultSources();
|
||||
|
||||
using (new AssertionScope())
|
||||
{
|
||||
settings.TraceEnabled.Should().BeTrue();
|
||||
settings.LoadTracerAtStartup.Should().BeTrue();
|
||||
settings.Exporter.Should().Be("otlp");
|
||||
settings.OtlpExportProtocol.Should().Be(OtlpExportProtocol.HttpProtobuf);
|
||||
settings.OtlpExportEndpoint.Should().Be(new Uri("http://localhost:4318/v1/traces"));
|
||||
settings.ConsoleExporterEnabled.Should().BeTrue();
|
||||
settings.EnabledInstrumentations.Should().BeEmpty();
|
||||
settings.TracerPlugins.Should().BeEmpty();
|
||||
settings.ActivitySources.Should().BeEquivalentTo(new List<string> { "OpenTelemetry.ClrProfiler.*" });
|
||||
settings.LegacySources.Should().BeEmpty();
|
||||
settings.Integrations.Should().NotBeNull();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", OtlpExportProtocol.HttpProtobuf, "http://localhost:4318/v1/traces")]
|
||||
[InlineData(null, OtlpExportProtocol.HttpProtobuf, "http://localhost:4318/v1/traces")]
|
||||
[InlineData("http/protobuf", OtlpExportProtocol.HttpProtobuf, "http://localhost:4318/v1/traces")]
|
||||
[InlineData("grpc", null, null)]
|
||||
[InlineData("nonExistingProtocol", null, null)]
|
||||
|
||||
public void FromDefaultSources_OtlpExporterPropertiesDependsOnCorrespondingEnvVariables(string otlpProtocol, OtlpExportProtocol? expectedOtlpExportProtocol, string expectedOtlpExportEndpoint)
|
||||
{
|
||||
Environment.SetEnvironmentVariable(ConfigurationKeys.ExporterOtlpProtocol, otlpProtocol);
|
||||
|
||||
var settings = Settings.FromDefaultSources();
|
||||
|
||||
using (new AssertionScope())
|
||||
{
|
||||
// null values for expected data will be handled by OTel .NET SDK
|
||||
settings.OtlpExportProtocol.Should().Be(expectedOtlpExportProtocol);
|
||||
settings.OtlpExportEndpoint.Should().Be(expectedOtlpExportEndpoint != null ? new Uri(expectedOtlpExportEndpoint) : null);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
[InlineData("http/protobuf")]
|
||||
[InlineData("grpc")]
|
||||
[InlineData("nonExistingProtocol")]
|
||||
public void FromDefaultSources_OtlpExportEndpointIsNullWhenCorrespondingEnvVarIsSet(string otlpProtocol)
|
||||
{
|
||||
Environment.SetEnvironmentVariable(ConfigurationKeys.ExporterOtlpProtocol, otlpProtocol);
|
||||
Environment.SetEnvironmentVariable(ConfigurationKeys.ExporterOtlpEndpoint, "http://customurl:1234");
|
||||
|
||||
var settings = Settings.FromDefaultSources();
|
||||
|
||||
settings.OtlpExportEndpoint.Should().BeNull("leaving as null as SDK will handle it");
|
||||
}
|
||||
|
||||
private static void ClearEnvVars()
|
||||
{
|
||||
Environment.SetEnvironmentVariable(ConfigurationKeys.ExporterOtlpProtocol, null);
|
||||
Environment.SetEnvironmentVariable(ConfigurationKeys.ExporterOtlpEndpoint, null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OpenTelemetry.ClrProfiler.Managed\OpenTelemetry.ClrProfiler.Managed.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -1,17 +1,5 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\IntegrationTests.Helpers\IntegrationTests.Helpers.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
|
||||
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
|
||||
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -2,15 +2,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNet.Testcontainers" Version="1.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -6,15 +6,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNet.Testcontainers" Version="1.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in New Issue