Skip to content

Commit

Permalink
OTLP over http/protobuf as default exporter (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Feb 10, 2022
1 parent d741e31 commit c65a787
Show file tree
Hide file tree
Showing 19 changed files with 213 additions and 93 deletions.
21 changes: 18 additions & 3 deletions OpenTelemetry.ClrProfiler.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
8 changes: 7 additions & 1 deletion build/nuke/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions build/nuke/Projects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static class Tests
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";
}
Expand Down
2 changes: 1 addition & 1 deletion dev/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion dev/envvars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ public class ConfigurationKeys
/// <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>
Expand All @@ -42,7 +53,7 @@ public class ConfigurationKeys
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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -70,21 +71,32 @@ private static TracerProviderBuilder SetExporter(this TracerProviderBuilder buil
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;
Expand Down
59 changes: 45 additions & 14 deletions src/OpenTelemetry.ClrProfiler.Managed/Configuration/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenTelemetry.Exporter;

namespace OpenTelemetry.ClrProfiler.Managed.Configuration
{
Expand All @@ -23,7 +24,10 @@ private Settings(IConfigurationSource source)
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;

Expand Down Expand Up @@ -89,16 +93,11 @@ private Settings(IConfigurationSource source)
}

/// <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.
Expand All @@ -111,14 +110,16 @@ private Settings(IConfigurationSource source)
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.
Expand All @@ -131,12 +132,12 @@ private Settings(IConfigurationSource source)
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.*" };

Expand Down Expand Up @@ -164,5 +165,35 @@ internal static Settings FromDefaultSources()

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;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("OpenTelemetry.ClrProfiler.Managed.Tests")]
9 changes: 8 additions & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
Loading

0 comments on commit c65a787

Please sign in to comment.