Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9463781
created custom "per route" sampling logic
dylan-asos Jun 4, 2025
38a1e7e
renamed directory and solution
dylan-asos Jun 4, 2025
a32e647
structure updates
dylan-asos Jun 4, 2025
2cac3f8
updating docs
dylan-asos Jun 4, 2025
2fa5588
removed icon usage
dylan-asos Jun 4, 2025
4e14044
keep paths local to projects
dylan-asos Jun 4, 2025
6e29a6a
ongoing work for head/tail based sampling support
dylan-asos Jul 19, 2025
d7a6873
Initial plan
Copilot Jul 19, 2025
a54bede
Start comprehensive documentation improvements
Copilot Jul 19, 2025
11f8898
Complete comprehensive documentation improvements
Copilot Jul 19, 2025
e9833c1
Merge branch 'feature/sampling' into copilot/fix-23
dylan-asos Jul 19, 2025
1d28a5b
[WIP] Improve documentation (#24)
Copilot Jul 19, 2025
ed29953
fixed up test
dylan-asos Jul 20, 2025
a46a288
Update OpenTelemetrySetupTests.cs
dylan-asos Jul 20, 2025
1ee924b
API improvements
dylan-asos Jul 20, 2025
5b408d0
Merge branch 'feature/sampling' of https://github.com/ASOS/asos-open-…
dylan-asos Jul 20, 2025
a13829b
Update azure-pipelines.yml for Azure Pipelines
dylan-asos Jul 20, 2025
94e5218
Update azure-pipelines.yml for Azure Pipelines
dylan-asos Jul 20, 2025
8f68434
Update azure-pipelines.yml for Azure Pipelines
dylan-asos Jul 20, 2025
ff222fa
Simplify API and added a Log Processor
dylan-asos Jul 21, 2025
8520691
Merge remote-tracking branch 'origin/feature/sampling' into feature/s…
dylan-asos Jul 21, 2025
f403f8e
Allow more processing time on fast test
dylan-asos Jul 21, 2025
0a587e4
refactors, validation and setting tags for itemCounts
dylan-asos Jul 21, 2025
b2db585
tweaks to dependency failure detection
dylan-asos Jul 21, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.18" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="NUnit" Version="3.14.0"/>
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Asos.OpenTelemetry.AspNetCore\Asos.OpenTelemetry.AspNetCore.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc;

namespace Asos.OpenTelemetry.AspNetCore.Tests.Controllers;

[ApiController]
[Route("api/health")]
public class HealthController : ControllerBase
{
[HttpGet]
public IActionResult Health()
{
return Ok("Healthy");
}

[HttpGet("detailed")]
public IActionResult DetailedHealth()
{
return Ok("Detailed health");
}

[HttpGet("exception")]
public IActionResult HealthException()
{
throw new InvalidOperationException("Health check failed");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;

namespace Asos.OpenTelemetry.AspNetCore.Tests.Controllers;

[ApiController]
[Route("api/orders")]
public class OrdersController : ControllerBase
{
[HttpPost]
public IActionResult CreateOrder([FromBody] object order)
{
return Ok("Order created");
}

[HttpPost("invalid")]
public IActionResult CreateInvalidOrder([FromBody] object order)
{
return BadRequest("Invalid order");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;

namespace Asos.OpenTelemetry.AspNetCore.Tests.Controllers;

[ApiController]
[Route("api/products")]
public class ProductsController : ControllerBase
{
[HttpGet("{id}")]
public IActionResult GetProduct(int id)
{
return Ok($"Product {id}");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.AspNetCore.Mvc;

namespace Asos.OpenTelemetry.AspNetCore.Tests.Controllers;

/// <summary>
/// Test controllers for simulating different scenarios
/// </summary>
[ApiController]
[Route("api/test")]
public class TestController : ControllerBase
{
[HttpGet("server-error")]
public IActionResult ServerError()
{
return StatusCode(500, "Internal Server Error");
}

[HttpGet("exception")]
public IActionResult Exception([FromQuery] string type = "InvalidOperation")
{
throw type switch
{
"ArgumentNull" => new ArgumentNullException("Test parameter"),
"Timeout" => new TimeoutException("Test timeout"),
_ => new InvalidOperationException("Test exception")
};
}

[HttpGet("slow")]
public async Task<IActionResult> Slow([FromQuery] int delay = 1000)
{
await Task.Delay(delay);
return Ok("Slow response");
}

[HttpGet("status/{code}")]
public IActionResult Status(int code)
{
return StatusCode(code, $"Status {code}");
}

[HttpGet("performance/{id}")]
public IActionResult Performance(int id)
{
return Ok($"Performance test {id}");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Text.RegularExpressions;
using Asos.OpenTelemetry.AspNetCore.Sampling;
using Asos.OpenTelemetry.AspNetCore.Sampling.Head;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Trace;

namespace Asos.OpenTelemetry.AspNetCore.Tests;

public class OpenTelemetrySetupTests
{
[Test]
public void ConfigureOpenTelemetry_RegistersRequiredServices()
{
var builder = WebApplication.CreateBuilder();
builder.Configuration["OpenTelemetry:Sampling:RouteSamplingRules:0:RoutePattern"] = "/api/test";

builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

builder.AddOpenTelemetryCustomSampling();

var provider = builder.Services.BuildServiceProvider();

// Assert RouteSamplingOptions are bound correctly
var routeSamplingOptions = provider.GetRequiredService<IOptions<RouteSamplingOptions>>().Value;
Assert.That(routeSamplingOptions.RouteSamplingRules, Has.Exactly(1).Items);
Assert.Multiple(() =>
{
Assert.That(routeSamplingOptions.RouteSamplingRules[0].RoutePattern, Is.EqualTo("/api/test"));
Assert.That(routeSamplingOptions.RouteSamplingRules[0].CompiledPattern, Is.Not.Null);
});
Assert.That(routeSamplingOptions.RouteSamplingRules[0].CompiledPattern, Is.InstanceOf<Regex>());

// Assert that ConfigurableRouteSampler is registered
var sampler = provider.GetService<RouteRuleSampler>();
Assert.That(sampler, Is.Not.Null);
}
}
Loading