Skip to content

Bug: fix tracing subsegment exception when using fluent api #1031

@hjgraca

Description

@hjgraca

Expected Behaviour

Should allow to create subsegments when using Fluent API
This is a regression

        Tracing.WithSubsegment("LoggingResponse",
            subsegment =>
            {
                subsegment.AddAnnotation("AccountId", apigwProxyEvent.RequestContext.AccountId);
                subsegment.AddMetadata("LookupRecord", lookupRecord);
            });

Current Behaviour

After introducing a new way of setting subsegments the old way started failing with System.NullReferenceException: Object reference not set to an instance of an object.
This was caused when using Fluent API

        Tracing.WithSubsegment("LoggingResponse",
            subsegment =>
            {
                subsegment.AddAnnotation("AccountId", apigwProxyEvent.RequestContext.AccountId);
                subsegment.AddMetadata("LookupRecord", lookupRecord);
            });

the new version works as expected

        using var gatewaySegment = Tracing.BeginSubsegment("LoggingResponse");
        gatewaySegment.AddAnnotation("AccountId", apigwProxyEvent.RequestContext.AccountId);
        gatewaySegment.AddMetadata("LookupRecord", lookupRecord);

Code snippet

Tracing.WithSubsegment("LoggingResponse",
            subsegment =>
            {
                subsegment.AddAnnotation("AccountId", apigwProxyEvent.RequestContext.AccountId);
                subsegment.AddMetadata("LookupRecord", lookupRecord);
            });

Possible Solution

No response

Steps to Reproduce

add code

        Tracing.WithSubsegment("LoggingResponse",
            subsegment =>
            {
                subsegment.AddAnnotation("AccountId", apigwProxyEvent.RequestContext.AccountId);
                subsegment.AddMetadata("LookupRecord", lookupRecord);
            });

Powertools for AWS Lambda (.NET) version

latest

AWS Lambda function runtime

dotnet8

Debugging logs

System.NullReferenceException: Object reference not set to an instance of an object.

Metadata

Metadata

Assignees

Labels

bugUnexpected, reproducible and unintended software behaviour

Type

Projects

Status

👀 In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions