-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add activity extensions (#124)
- Loading branch information
Showing
4 changed files
with
31 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...n.Authorization.ServiceDefaults/src/ServiceDefaults/Telemetry/AltinnActivityExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Diagnostics; | ||
|
||
namespace Altinn.Authorization.ServiceDefaults.Telemetry; | ||
|
||
/// <summary> | ||
/// Extension methods for <see cref="Activity"/> and <see cref="ActivitySource"/>. | ||
/// </summary> | ||
public static class AltinnActivityExtensions | ||
{ | ||
/// <summary> | ||
/// Creates and starts a new <see cref="Activity"/> object if there is any listener to the Activity, returns null otherwise. | ||
/// </summary> | ||
/// <param name="source">The <see cref="ActivitySource"/>.</param> | ||
/// <param name="kind">The <see cref="ActivityKind"/>.</param> | ||
/// <param name="name">The operation name of the Activity.</param> | ||
/// <param name="tags">The operation tags.</param> | ||
/// <returns>The created <see cref="Activity"/> object or null if there is no any event listener.</returns> | ||
public static Activity? StartActivity(this ActivitySource source, ActivityKind kind, string name, ReadOnlySpan<KeyValuePair<string, object?>> tags) | ||
{ | ||
using var state = ActivityHelper.ThreadLocalState; | ||
state.AddTags(tags); | ||
|
||
return source.StartActivity(kind, tags: state.Tags, name: name); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...aults.Npgsql.Tests/ActivityHelperTests.cs → ...viceDefaults.Tests/ActivityHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters