Skip to content

fix!: check if span has the attributes method to avoid internal error #1645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

xuan-cao-swi
Copy link
Contributor

Description

In rare cases, the span may be a no-op span because it is a non-recording span. If the span attempts to access its attributes, it will raise an error. A check has been added to prevent this internal error.

@@ -43,7 +43,7 @@ def wrap_lambda(event:, context:, handler:, flush_timeout: DEFAULT_FLUSH_TIMEOUT
begin
response = yield

unless span.attributes.key?(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE)
if span.respond_to?(:attributes) && !span.attributes.key?(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can just check if the span is recording, right?

Suggested change
if span.respond_to?(:attributes) && !span.attributes.key?(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE)
if span.recording? && !span.attributes.key?(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this span attribute getting set anyways? Instrumentation should really not be making any decisions based of the contents of the spans attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aws lambda instrumentation attribute is set through otel_attributes(event, context) from in_span; and then it will add the attribute HTTP_STATUS_CODE.

Instrumentation should really not be making any decisions based of the contents of the spans attributes.

This part only sets attributes like HTTP_STATUS_CODE as part of span metadata.

The issue is that if the span is not recording, it won't have the attributes method, which can raise an error. This error could overshadow the user's original Lambda function error, causing confusion.

xuan-cao-swi and others added 2 commits August 21, 2025 12:28
…ws_lambda/wrap.rb

Co-authored-by: Robert <robertlaurin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants