Skip to content

Commit

Permalink
Merge branch 'main' into jamesnk/prometheus-exporter-unit
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch authored Aug 16, 2023
2 parents 4797cea + 031ed48 commit d51688e
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 21 deletions.
4 changes: 4 additions & 0 deletions build/Common.nonprod.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<CodeAnalysisRuleSet>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenTelemetry.sln'))\build\OpenTelemetry.test.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<PropertyGroup>
<DefaultTargetFrameworkForExampleApps>net7.0</DefaultTargetFrameworkForExampleApps>
</PropertyGroup>

<PropertyGroup Condition="$(MSBuildProjectName.EndsWith('.Tests'))">
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion build/test-aot-compatibility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ foreach ($line in $($publishOutput -split "`r`n"))
if ($line -like "*analysis warning IL*")
{
Write-Host $line

$actualWarningCount += 1
}
}
Expand All @@ -28,7 +29,7 @@ if ($LastExitCode -ne 0)
popd

Write-Host "Actual warning count is:", $actualWarningCount
$expectedWarningCount = 33
$expectedWarningCount = 26

$testPassed = 0
if ($actualWarningCount -ne $expectedWarningCount)
Expand Down
2 changes: 1 addition & 1 deletion examples/AspNetCore/Examples.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>$(DefaultTargetFrameworkForExampleApps)</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions examples/AspNetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
var appBuilder = WebApplication.CreateBuilder(args);

// Note: Switch between Zipkin/Jaeger/OTLP/Console by setting UseTracingExporter in appsettings.json.
var tracingExporter = appBuilder.Configuration.GetValue<string>("UseTracingExporter").ToLowerInvariant();
var tracingExporter = appBuilder.Configuration.GetValue("UseTracingExporter", defaultValue: "console")!.ToLowerInvariant();

// Note: Switch between Prometheus/OTLP/Console by setting UseMetricsExporter in appsettings.json.
var metricsExporter = appBuilder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();
var metricsExporter = appBuilder.Configuration.GetValue("UseMetricsExporter", defaultValue: "console")!.ToLowerInvariant();

// Note: Switch between Console/OTLP by setting UseLogExporter in appsettings.json.
var logExporter = appBuilder.Configuration.GetValue<string>("UseLogExporter").ToLowerInvariant();
var logExporter = appBuilder.Configuration.GetValue("UseLogExporter", defaultValue: "console")!.ToLowerInvariant();

// Note: Switch between Explicit/Exponential by setting HistogramAggregation in appsettings.json
var histogramAggregation = appBuilder.Configuration.GetValue<string>("HistogramAggregation").ToLowerInvariant();
var histogramAggregation = appBuilder.Configuration.GetValue("HistogramAggregation", defaultValue: "explicit")!.ToLowerInvariant();

// Build a resource configuration action to set service information.
Action<ResourceBuilder> configureResource = r => r.AddService(
serviceName: appBuilder.Configuration.GetValue<string>("ServiceName"),
serviceName: appBuilder.Configuration.GetValue("ServiceName", defaultValue: "otel-test")!,
serviceVersion: typeof(Program).Assembly.GetName().Version?.ToString() ?? "unknown",
serviceInstanceId: Environment.MachineName);

Expand Down Expand Up @@ -94,7 +94,7 @@
builder.AddOtlpExporter(otlpOptions =>
{
// Use IConfiguration directly for Otlp exporter endpoint option.
otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue<string>("Otlp:Endpoint"));
otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: "http://localhost:4317")!);
});
break;

Expand Down Expand Up @@ -142,7 +142,7 @@
builder.AddOtlpExporter(otlpOptions =>
{
// Use IConfiguration directly for Otlp exporter endpoint option.
otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue<string>("Otlp:Endpoint"));
otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: "http://localhost:4317")!);
});
break;
default:
Expand All @@ -169,7 +169,7 @@
options.AddOtlpExporter(otlpOptions =>
{
// Use IConfiguration directly for Otlp exporter endpoint option.
otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue<string>("Otlp:Endpoint"));
otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: "http://localhost:4317")!);
});
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/Examples.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>$(DefaultTargetFrameworkForExampleApps)</TargetFramework>
<NoWarn>$(NoWarn),CS0618</NoWarn>

<!-- this is temporary. will remove in future PR. -->
Expand Down
2 changes: 1 addition & 1 deletion examples/GrpcService/Examples.GrpcService.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>$(DefaultTargetFrameworkForExampleApps)</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions examples/GrpcService/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ public void ConfigureServices(IServiceCollection services)
.WithTracing(builder =>
{
builder
.ConfigureResource(r => r.AddService(this.Configuration.GetValue<string>("ServiceName")))
.ConfigureResource(r => r.AddService(this.Configuration.GetValue("ServiceName", defaultValue: "otel-test")!))
.AddAspNetCoreInstrumentation();

// Switch between Jaeger/Zipkin/Console by setting UseExporter in appsettings.json.
var exporter = this.Configuration.GetValue<string>("UseExporter").ToLowerInvariant();
var exporter = this.Configuration.GetValue("UseExporter", defaultValue: "console")!.ToLowerInvariant();
switch (exporter)
{
case "jaeger":
builder.AddJaegerExporter(jaegerOptions =>
_ = builder.AddJaegerExporter(jaegerOptions =>
{
jaegerOptions.AgentHost = this.Configuration.GetValue<string>("Jaeger:Host");
jaegerOptions.AgentPort = this.Configuration.GetValue<int>("Jaeger:Port");
jaegerOptions.AgentHost = this.Configuration.GetValue("Jaeger:Host", defaultValue: "localhost");
jaegerOptions.AgentPort = this.Configuration.GetValue("Jaeger:Port", defaultValue: 6831);
});
break;
case "zipkin":
builder.AddZipkinExporter(zipkinOptions =>
{
zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue<string>("Zipkin:Endpoint"));
zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue("Zipkin:Endpoint", defaultValue: "http://localhost:9411/api/v2/spans")!);
});
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion examples/MicroserviceExample/WebApi/WebApi.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>$(DefaultTargetFrameworkForExampleApps)</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>$(DefaultTargetFrameworkForExampleApps)</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
using System.Data;
using System.Diagnostics;
using OpenTelemetry.Trace;
#if NET6_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
#endif

namespace OpenTelemetry.Instrumentation.SqlClient.Implementation;

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)]
#endif
internal sealed class SqlClientDiagnosticListener : ListenerHandler
{
public const string SqlDataBeforeExecuteCommand = "System.Data.SqlClient.WriteCommandBefore";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// limitations under the License.
// </copyright>

#if NET6_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
#endif
using OpenTelemetry.Instrumentation.SqlClient.Implementation;

namespace OpenTelemetry.Instrumentation.SqlClient;
Expand All @@ -24,7 +27,9 @@ namespace OpenTelemetry.Instrumentation.SqlClient;
internal sealed class SqlClientInstrumentation : IDisposable
{
internal const string SqlClientDiagnosticListenerName = "SqlClientDiagnosticListener";

#if NET6_0_OR_GREATER
internal const string SqlClientTrimmingUnsupportedMessage = "Trimming is not yet supported with SqlClient instrumentation.";
#endif
#if NETFRAMEWORK
private readonly SqlEventSourceListener sqlEventSourceListener;
#else
Expand All @@ -48,6 +53,9 @@ internal sealed class SqlClientInstrumentation : IDisposable
/// Initializes a new instance of the <see cref="SqlClientInstrumentation"/> class.
/// </summary>
/// <param name="options">Configuration options for sql instrumentation.</param>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(SqlClientTrimmingUnsupportedMessage)]
#endif
public SqlClientInstrumentation(
SqlClientInstrumentationOptions options = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// limitations under the License.
// </copyright>

#if NET6_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
#endif
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Instrumentation.SqlClient;
Expand All @@ -32,6 +35,9 @@ public static class TracerProviderBuilderExtensions
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)]
#endif
public static TracerProviderBuilder AddSqlClientInstrumentation(this TracerProviderBuilder builder)
=> AddSqlClientInstrumentation(builder, name: null, configureSqlClientInstrumentationOptions: null);

Expand All @@ -41,6 +47,9 @@ public static TracerProviderBuilder AddSqlClientInstrumentation(this TracerProvi
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <param name="configureSqlClientInstrumentationOptions">Callback action for configuring <see cref="SqlClientInstrumentationOptions"/>.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)]
#endif
public static TracerProviderBuilder AddSqlClientInstrumentation(
this TracerProviderBuilder builder,
Action<SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions)
Expand All @@ -53,6 +62,10 @@ public static TracerProviderBuilder AddSqlClientInstrumentation(
/// <param name="name">Name which is used when retrieving options.</param>
/// <param name="configureSqlClientInstrumentationOptions">Callback action for configuring <see cref="SqlClientInstrumentationOptions"/>.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)]
#endif

public static TracerProviderBuilder AddSqlClientInstrumentation(
this TracerProviderBuilder builder,
string name,
Expand Down

0 comments on commit d51688e

Please sign in to comment.