Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/demo/Client/Examples.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
8 changes: 5 additions & 3 deletions examples/demo/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// dotnet run http://localhost:5200
if (args.Length != 1)
{
Console.WriteLine(@"URL missing");
#pragma warning disable CA1303 // Do not pass literals as localized parameters
Console.WriteLine("URL missing");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
return 2;
}

Expand All @@ -15,13 +17,13 @@
{
try
{
var content = await httpClient.GetStringAsync(url);
var content = await httpClient.GetStringAsync(new Uri(url)).ConfigureAwait(false);
Console.WriteLine(content);
}
catch (HttpRequestException ex)
{
Console.WriteLine(ex.Message);
}

Thread.Sleep(5000);
await Task.Delay(5000).ConfigureAwait(false);
}
2 changes: 1 addition & 1 deletion examples/demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0.416-jammy@sha256:71217e2029c9844f13aa98114ae4aea9e77287cd8c152f7b7c09f8af61a1affa
FROM mcr.microsoft.com/dotnet/sdk:10.0.101-noble@sha256:d1823fecac3689a2eb959e02ee3bfe1c2142392808240039097ad70644566190

# install OpenTelemetry .NET Automatic Instrumentation
ARG OTEL_VERSION=1.13.0
Expand Down
3 changes: 1 addition & 2 deletions examples/demo/Service/Examples.Service.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" />
<PackageReference Include="Microsoft.Extensions.Logging" />
</ItemGroup>

</Project>
12 changes: 7 additions & 5 deletions examples/demo/Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@

async Task<string> Handler(ILogger<Program> logger)
{
await ExecuteSql("SELECT 1");
await ExecuteSql("SELECT 1").ConfigureAwait(false);

// .NET Diagnostics: create a manual span
using (var activity = activitySource.StartActivity("SayHello"))
{
activity?.SetTag("foo", 1);
activity?.SetTag("bar", "Hello, World!");
activity?.SetTag("baz", new int[] { 1, 2, 3 });
activity?.SetTag("baz", (int[])[1, 2, 3]);

var waitTime = Random.Shared.NextDouble(); // max 1 seconds
await Task.Delay(TimeSpan.FromSeconds(waitTime));
await Task.Delay(TimeSpan.FromSeconds(waitTime)).ConfigureAwait(false);

activity?.SetStatus(ActivityStatusCode.Ok);

Expand All @@ -47,7 +47,9 @@ async Task<string> Handler(ILogger<Program> logger)
async Task ExecuteSql(string sql)
{
using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();
await connection.OpenAsync().ConfigureAwait(false);
#pragma warning disable CA2100 // Review SQL queries for security vulnerabilities. It is static SQL for demo purposes.
using var command = new SqlCommand(sql, connection);
using var reader = await command.ExecuteReaderAsync();
#pragma warning restore CA2100 // Review SQL queries for security vulnerabilities. It is static SQL for demo purposes.
using var reader = await command.ExecuteReaderAsync().ConfigureAwait(false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ActionResult Delay(int seconds)
[Route("delay-async/{seconds}")]
public async Task<ActionResult> DelayAsync(int seconds)
{
await Task.Delay(TimeSpan.FromSeconds(seconds));
await Task.Delay(TimeSpan.FromSeconds(seconds)).ConfigureAwait(false);
return Ok(seconds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public IActionResult Index()
from prefix in prefixes
let key = (envVar.Key as string)?.ToUpperInvariant()
let value = envVar.Value as string
where key.StartsWith(prefix)
where key.StartsWith(prefix, StringComparison.Ordinal)
orderby key
select new KeyValuePair<string, string>(key, value);

Expand All @@ -41,14 +41,14 @@ public IActionResult Delay(int seconds)
public async Task<IActionResult> DelayAsync(int seconds)
{
ViewBag.StackTrace = StackTraceHelper.GetUsefulStack();
await Task.Delay(TimeSpan.FromSeconds(seconds));
await Task.Delay(TimeSpan.FromSeconds(seconds)).ConfigureAwait(false);
return View("Delay", seconds);
}

[Route("bad-request")]
public IActionResult ThrowException()
{
throw new Exception("This was a bad request.");
throw new InvalidOperationException("This was a bad request.");
}

[Route("status-code/{statusCode}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
<RootNamespace>Examples.AspNetCoreMvc</RootNamespace>
<!-- CA1515: Consider making public types internal. Controllers needs to be public. -->
<NoWarn>$(NoWarn);CA1515</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions examples/playground/AspNetCoreMvc/OtelSdkPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class OtelSdkPlugin
{
public void Initializing()
{
#pragma warning disable CA1303 // Do not pass literals as localized parameters
Console.WriteLine("Hello from OtelSdkPlugin");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
}
}
2 changes: 1 addition & 1 deletion examples/playground/AspNetCoreMvc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Examples.AspNetCoreMvc;

public class Program
internal static class Program
{
public static void Main(string[] args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace Examples.AspNetCoreMvc.Shared;

public static class StackTraceHelper
internal static class StackTraceHelper
{
public static string[] GetUsefulStack()
{
var stackTrace = Environment.StackTrace;
string[] methods = stackTrace.Split(new[] { " at " }, StringSplitOptions.None);
var methods = stackTrace.Split([" at "], StringSplitOptions.None);
return methods;
}
}
10 changes: 5 additions & 5 deletions test/IntegrationTests/AspNetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static string GetTestImageName(AppPoolMode appPoolMode, Gac useGac)
(AppPoolMode.Classic, Gac.UseLocal) => "testapplication-aspnet-netframework-classic-nogac",
(AppPoolMode.Integrated, Gac.UseGac) => "testapplication-aspnet-netframework-integrated",
(AppPoolMode.Integrated, Gac.UseLocal) => "testapplication-aspnet-netframework-integrated-nogac",
_ => throw new ArgumentOutOfRangeException()
_ => throw new ArgumentOutOfRangeException(nameof(appPoolMode), $"Pair of {appPoolMode} and {useGac} is not supported.")
};
}

Expand All @@ -231,13 +231,13 @@ private async Task CallTestApplicationEndpoint(int webPort)
client.DefaultRequestHeaders.Add("Custom-Request-Test-Header2", "Test-Value2");
client.DefaultRequestHeaders.Add("Custom-Request-Test-Header3", "Test-Value3");

var response = await client.GetAsync($"http://localhost:{webPort}");
var content = await response.Content.ReadAsStringAsync();
var response = await client.GetAsync(new Uri($"http://localhost:{webPort}")).ConfigureAwait(false);
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Output.WriteLine("MVC Response:");
Output.WriteLine(content);

response = await client.GetAsync($"http://localhost:{webPort}/api/values");
content = await response.Content.ReadAsStringAsync();
response = await client.GetAsync(new Uri($"http://localhost:{webPort}/api/values")).ConfigureAwait(false);
content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Output.WriteLine("WebApi Response:");
Output.WriteLine(content);
}
Expand Down
8 changes: 4 additions & 4 deletions test/IntegrationTests/AzureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public AzureFixture()

public async Task InitializeAsync()
{
_container = await LaunchAzureContainerAsync(Port);
_container = await LaunchAzureContainerAsync(Port).ConfigureAwait(false);
}

public async Task DisposeAsync()
{
if (_container != null)
{
await ShutdownAzureContainerAsync(_container);
await ShutdownAzureContainerAsync(_container).ConfigureAwait(false);
}
}

Expand All @@ -50,13 +50,13 @@ private static async Task<IContainer> LaunchAzureContainerAsync(int port)
.WithWaitStrategy(Wait.ForUnixContainer().UntilInternalTcpPortIsAvailable(BlobServicePort));

var container = containersBuilder.Build();
await container.StartAsync();
await container.StartAsync().ConfigureAwait(false);

return container;
}

private static async Task ShutdownAzureContainerAsync(IContainer container)
{
await container.DisposeAsync();
await container.DisposeAsync().ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void TraceContextIsCorrectlyAssociatedWithThreadSamples()
collector.AssertCollected();
}

private bool AssertAllProfiles(ICollection<ExportProfilesServiceRequest> profilesServiceRequests)
private static bool AssertAllProfiles(ICollection<ExportProfilesServiceRequest> profilesServiceRequests)
{
var totalSamplesWithTraceContextCount = 0;
var managedThreadsWithTraceContext = new HashSet<string>();
Expand Down Expand Up @@ -65,7 +65,7 @@ private bool AssertAllProfiles(ICollection<ExportProfilesServiceRequest> profile
return true;
}

private string GetThreadName(OpenTelemetry.Proto.Profiles.V1Development.Profile profile, OpenTelemetry.Proto.Profiles.V1Development.Sample sample)
private static string GetThreadName(OpenTelemetry.Proto.Profiles.V1Development.Profile profile, OpenTelemetry.Proto.Profiles.V1Development.Sample sample)
{
foreach (var attrIndex in sample.AttributeIndices)
{
Expand Down
11 changes: 6 additions & 5 deletions test/IntegrationTests/GraphQLTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#if NET

using System.Globalization;
using System.Net;
using System.Text;
using IntegrationTests.Helpers;
Expand Down Expand Up @@ -114,7 +115,7 @@ private static byte[] GetTraceIdBytes(byte id)

private static string GetTraceIdHex(byte id)
{
return id.ToString("x32");
return id.ToString("x32", CultureInfo.InvariantCulture);
}

private void Expect(
Expand Down Expand Up @@ -154,7 +155,7 @@ private async Task SubmitRequestsAsync(int aspNetCorePort, IEnumerable<RequestIn
var client = new HttpClient();
foreach (var requestInfo in requests)
{
await SubmitRequestAsync(client, aspNetCorePort, requestInfo);
await SubmitRequestAsync(client, aspNetCorePort, requestInfo).ConfigureAwait(false);
}
}

Expand All @@ -173,7 +174,7 @@ private async Task SubmitRequestAsync(HttpClient client, int aspNetCorePort, Req
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
requestMessage.Headers.Add("traceparent", w3c);

response = await client.SendAsync(requestMessage);
response = await client.SendAsync(requestMessage).ConfigureAwait(false);
}
else if (method == "POST")
{
Expand All @@ -186,7 +187,7 @@ private async Task SubmitRequestAsync(HttpClient client, int aspNetCorePort, Req
requestMessage.Content = new StringContent(requestInfo.RequestBody, Encoding.UTF8, "application/json");
requestMessage.Headers.Add("traceparent", w3c);

response = await client.SendAsync(requestMessage);
response = await client.SendAsync(requestMessage).ConfigureAwait(false);
}
else
{
Expand All @@ -196,7 +197,7 @@ private async Task SubmitRequestAsync(HttpClient client, int aspNetCorePort, Req

if (printResponseText)
{
var content = await response.Content.ReadAsStringAsync();
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

Output.WriteLine($"[http] {response.StatusCode} {content}");
}
Expand Down
2 changes: 1 addition & 1 deletion test/IntegrationTests/Helpers/DockerSystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace IntegrationTests.Helpers;

internal sealed class DockerSystemHelper
internal static class DockerSystemHelper
{
public static async Task<bool> GetIsWindowsEngineEnabled()
{
Expand Down
10 changes: 5 additions & 5 deletions test/IntegrationTests/IISContainerTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static async Task<IContainer> StartContainerAsync(
Dictionary<string, string> environmentVariables,
ITestOutputHelper testOutputHelper)
{
var networkName = await DockerNetworkHelper.SetupIntegrationTestsNetworkAsync();
var networkName = await DockerNetworkHelper.SetupIntegrationTestsNetworkAsync().ConfigureAwait(false);

var logPath = EnvironmentHelper.IsRunningOnCI()
? Path.Combine(Environment.GetEnvironmentVariable("GITHUB_WORKSPACE"), "test-artifacts", "profiler-logs")
Expand All @@ -43,14 +43,14 @@ public static async Task<IContainer> StartContainerAsync(
{
var wasStarted = container.StartAsync().Wait(TimeSpan.FromMinutes(5));
Assert.True(wasStarted, $"Container based on {imageName} has to be operational for the test.");
testOutputHelper.WriteLine($"Container was started successfully.");
testOutputHelper.WriteLine("Container was started successfully.");

await HealthzHelper.TestAsync($"http://localhost:{webPort}/healthz", testOutputHelper);
testOutputHelper.WriteLine($"IIS WebApp was started successfully.");
await HealthzHelper.TestAsync($"http://localhost:{webPort}/healthz", testOutputHelper).ConfigureAwait(false);
testOutputHelper.WriteLine("IIS WebApp was started successfully.");
}
catch
{
await container.DisposeAsync();
await container.DisposeAsync().ConfigureAwait(false);
throw;
}

Expand Down
10 changes: 5 additions & 5 deletions test/IntegrationTests/KafkaCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ public async Task InitializeAsync()
_containerNetwork = new NetworkBuilder()
.WithName(_testNetworkName)
.Build();
await _containerNetwork.CreateAsync();
_kafkaContainer = await LaunchKafkaContainer(_containerNetwork);
await _containerNetwork.CreateAsync().ConfigureAwait(false);
_kafkaContainer = await LaunchKafkaContainer(_containerNetwork).ConfigureAwait(false);
}

public async Task DisposeAsync()
{
if (_kafkaContainer != null)
{
await _kafkaContainer.DisposeAsync();
await _kafkaContainer.DisposeAsync().ConfigureAwait(false);
}

if (_containerNetwork != null)
{
await _containerNetwork.DisposeAsync();
await _containerNetwork.DisposeAsync().ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task DisposeAsync()
.WithNetwork(containerNetwork)
.Build();

await container.StartAsync();
await container.StartAsync().ConfigureAwait(false);

return container;
}
Expand Down
5 changes: 2 additions & 3 deletions test/IntegrationTests/KafkaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void SubmitsTraces(string packageVersion)
collector.Expect(KafkaInstrumentationScopeName, span => span.Kind == Span.Types.SpanKind.Producer && ValidateProduceExceptionSpan(span, topicName), "Failed Produce attempt without delivery handler set.");
collector.Expect(KafkaInstrumentationScopeName, span => span.Kind == Span.Types.SpanKind.Producer && ValidateResultProcessingProduceExceptionSpan(span, topicName), "Failed ProduceAsync attempt.");

if (packageVersion == string.Empty || Version.Parse(packageVersion) != new Version(1, 4, 0))
if (packageVersion.Length == 0 || Version.Parse(packageVersion) != new Version(1, 4, 0))
{
// Failed consume attempt.
collector.Expect(
Expand Down Expand Up @@ -153,8 +153,7 @@ private static bool ValidateBasicProduceExceptionSpan(Span span, string topicNam

private static bool ValidateProduceExceptionSpan(Span span, string topicName)
{
return ValidateBasicProduceExceptionSpan(span, topicName) &&
span.Attributes.Count(kv => kv.Key == KafkaMessageOffsetAttributeName) == 0;
return ValidateBasicProduceExceptionSpan(span, topicName) && span.Attributes.All(kv => kv.Key != KafkaMessageOffsetAttributeName);
}

private static bool ValidateResultProcessingProduceExceptionSpan(Span span, string topicName)
Expand Down
Loading
Loading