Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Amazon.XRay.Recorder.Core.Internal.Entities;

namespace AWS.Lambda.Powertools.Tracing.Internal;

/// <summary>
/// Class TracingSubsegment.
/// It's a wrapper for Subsegment from Amazon.XRay.Recorder.Core.Internal.
/// </summary>
/// <seealso cref="Subsegment" />
public class TracingSubsegment : Subsegment
{
/// <summary>
/// Wrapper constructor
/// </summary>
/// <param name="name"></param>
public TracingSubsegment(string name) : base(name) { }
}
13 changes: 7 additions & 6 deletions libraries/src/AWS.Lambda.Powertools.Tracing/Tracing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static void AddHttpInformation(string key, object value)
/// <param name="name">The name of the subsegment.</param>
/// <param name="subsegment">The AWS X-Ray subsegment for the wrapped consumer.</param>
/// <exception cref="ArgumentNullException">Thrown when the name is not provided.</exception>
public static void WithSubsegment(string name, Action<Subsegment> subsegment)
public static void WithSubsegment(string name, Action<TracingSubsegment> subsegment)
{
WithSubsegment(null, name, subsegment);
}
Expand All @@ -145,7 +145,7 @@ public static void WithSubsegment(string name, Action<Subsegment> subsegment)
/// <param name="name">The name of the subsegment.</param>
/// <param name="subsegment">The AWS X-Ray subsegment for the wrapped consumer.</param>
/// <exception cref="System.ArgumentNullException">name</exception>
public static void WithSubsegment(string nameSpace, string name, Action<Subsegment> subsegment)
public static void WithSubsegment(string nameSpace, string name, Action<TracingSubsegment> subsegment)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));
Expand All @@ -154,7 +154,8 @@ public static void WithSubsegment(string nameSpace, string name, Action<Subsegme
XRayRecorder.Instance.SetNamespace(GetNamespaceOrDefault(nameSpace));
try
{
subsegment?.Invoke((Subsegment) XRayRecorder.Instance.GetEntity());
var entity = XRayRecorder.Instance.GetEntity() as TracingSubsegment;
subsegment?.Invoke(entity);
}
finally
{
Expand All @@ -174,7 +175,7 @@ public static void WithSubsegment(string nameSpace, string name, Action<Subsegme
/// <param name="subsegment">The AWS X-Ray subsegment for the wrapped consumer.</param>
/// <exception cref="ArgumentNullException">Thrown when the name is not provided.</exception>
/// <exception cref="ArgumentNullException">Thrown when the entity is not provided.</exception>
public static void WithSubsegment(string name, Entity entity, Action<Subsegment> subsegment)
public static void WithSubsegment(string name, Entity entity, Action<TracingSubsegment> subsegment)
{
WithSubsegment(null, name, subsegment);
}
Expand All @@ -191,15 +192,15 @@ public static void WithSubsegment(string name, Entity entity, Action<Subsegment>
/// <param name="subsegment">The AWS X-Ray subsegment for the wrapped consumer.</param>
/// <exception cref="System.ArgumentNullException">name</exception>
/// <exception cref="System.ArgumentNullException">entity</exception>
public static void WithSubsegment(string nameSpace, string name, Entity entity, Action<Subsegment> subsegment)
public static void WithSubsegment(string nameSpace, string name, Entity entity, Action<TracingSubsegment> subsegment)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));

if (entity is null)
throw new ArgumentNullException(nameof(entity));

var childSubsegment = new Subsegment($"## {name}");
var childSubsegment = new TracingSubsegment($"## {name}");
entity.AddSubsegment(childSubsegment);
childSubsegment.Sampled = entity.Sampled;
childSubsegment.SetStartTimeToNow();
Expand Down