Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
shaykeren committed Feb 12, 2023
2 parents 71a7f0b + e0fc1ac commit 413a172
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
43 changes: 24 additions & 19 deletions Sample.MoneyTransfer.Api/Controllers/SampleInsights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Mvc;
using OpenTelemetry.Trace;
using Sample.MoneyTransfer.API.Utils;

namespace Sample.MoneyTransfer.API.Controllers;

Expand Down Expand Up @@ -245,34 +246,38 @@ private static async Task DelayAsync(TimeSpan timeSpan)
}

[HttpGet]
[Route(nameof(NPlusOneWithoutInternalSpan))]
public void NPlusOneWithoutInternalSpan()
[Route(nameof(NPlusOne))]
public void NPlusOne()
{
for (int i = 0; i < 100; i++)
using (Activity.StartActivity("NewInternalSpan"))
{
DbQuery();
Enumerable.Range(0, 100).Foreach(_ => DbQueryUsers());
}

Enumerable.Range(0, 90).Foreach(_ => DbQueryAccounts());
Enumerable.Range(0, 80).Foreach(_ => DbQueryRoles());
Enumerable.Range(0, 70).Foreach(_ => DbQueryGroups());
}

[HttpGet]
[Route(nameof(NPlusOneWithInternalSpan))]
public void NPlusOneWithInternalSpan()
private static void DbQueryUsers()
{
Console.WriteLine("doing stuff before");

using (Activity.StartActivity("SomeInternalSpan"))
{
for (int i = 0; i < 100; i++)
{
DbQuery();
}
}
using var activity = Activity.StartActivity(ActivityKind.Client);
activity?.SetTag("db.statement", "select * from users");
}
private static void DbQueryAccounts()
{
using var activity = Activity.StartActivity(ActivityKind.Client);
activity?.SetTag("db.statement", "select * from accounts");
}

private static void DbQuery()
private static void DbQueryRoles()
{
using var activity = Activity.StartActivity(ActivityKind.Client);
activity?.SetTag("db.statement", "select * from roles");
}
private static void DbQueryGroups()
{
using var activity = Activity.StartActivity(ActivityKind.Client);
activity.SetTag("db.statement", "select * from users");
activity?.SetTag("db.statement", "select * from groups");
}

[HttpGet]
Expand Down
12 changes: 12 additions & 0 deletions Sample.MoneyTransfer.Api/Utils/CollectionUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Sample.MoneyTransfer.API.Utils;

public static class CollectionUtils
{
public static void Foreach<T>(this IEnumerable<T> list, Action<T> action)
{
foreach (var item in list)
{
action(item);
}
}
}

0 comments on commit 413a172

Please sign in to comment.