Skip to content

Commit

Permalink
test adding instrumentation and activity tag
Browse files Browse the repository at this point in the history
  • Loading branch information
andracc committed Sep 24, 2024
1 parent 9bf3355 commit 0d8b6c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Backend.Tests/Controllers/WordControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
using BackendFramework.Controllers;
using BackendFramework.Interfaces;
using BackendFramework.Models;
using BackendFramework.Otel;
// using BackendFramework.Otel;
using BackendFramework.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
// using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;

namespace Backend.Tests.Controllers
Expand Down Expand Up @@ -391,8 +391,8 @@ public async Task TestUpdateDuplicateNonDuplicate()
[Test]
public async Task TestCreateWord()
{
var service = new ServiceCollection();
service.AddOpenTelemetryInstrumentation();
// var service = new ServiceCollection();
// service.AddOpenTelemetryInstrumentation();

var word = Util.RandomWord(_projId);

Expand Down
19 changes: 19 additions & 0 deletions Backend.Tests/Otel/OtelServiceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using BackendFramework.Otel;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;

namespace Backend.Tests.Otel
{
public class OtelServiceTests
{
[Test]
public static void TestAddOtelTag()
{
var services = new ServiceCollection();
OtelService.AddOtelInstrumentation(services);
OtelService.AddOtelTag("test key", "test val");

}

}
}
6 changes: 6 additions & 0 deletions Backend/Otel/OtelService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;

namespace BackendFramework.Otel;

Expand All @@ -12,4 +13,9 @@ public static void AddOtelTag(string key, object? value)
using var activity = new ActivitySource(OtelKernel.SourceName).StartActivity();
activity?.AddTag(key, value);
}

public static void AddOtelInstrumentation(IServiceCollection services)
{
services.AddOpenTelemetryInstrumentation();
}
}

0 comments on commit 0d8b6c5

Please sign in to comment.