Skip to content

Commit 1ca1619

Browse files
authored
Merge pull request #1032 from aws-powertools/fix/tracing-subsegment
fix: tracing subsegment when using fluent api Tracing.WithSubsegment
2 parents 96fe99e + 709ef3f commit 1ca1619

File tree

2 files changed

+549
-2
lines changed

2 files changed

+549
-2
lines changed

libraries/src/AWS.Lambda.Powertools.Tracing/Tracing.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,20 @@ public static void WithSubsegment(string nameSpace, string name, Action<TracingS
154154
XRayRecorder.Instance.SetNamespace(GetNamespaceOrDefault(nameSpace));
155155
try
156156
{
157-
var entity = XRayRecorder.Instance.GetEntity() as TracingSubsegment;
158-
subsegment?.Invoke(entity);
157+
var entity = XRayRecorder.Instance.GetEntity();
158+
var tracingSubsegment = new TracingSubsegment("## " + name);
159+
160+
// Copy properties from the current entity
161+
if (entity != null)
162+
{
163+
if (entity is Subsegment subsegmentEntity)
164+
{
165+
tracingSubsegment.Namespace = subsegmentEntity.Namespace;
166+
}
167+
tracingSubsegment.Sampled = entity.Sampled;
168+
}
169+
170+
subsegment?.Invoke(tracingSubsegment);
159171
}
160172
finally
161173
{

0 commit comments

Comments
 (0)