open-telemetry / open-telemetry/opentelemetry-python-contrib

Non existing object in botocore boto3.client("s3").head_object() records an exception

Open
#2,882 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Describe your environment

OS: (e.g, Ubuntu 22.04)
Python version: (e.g., Python 3.12.6)
Package version: (e.g., 0.48b0)

What happened?

When the object doesn't exist it records an exception. I'm using Uptrace as frontend which raises alarm on all exceptions.
In Sentry.io it doesn't record an exception as example.

Steps to Reproduce
def clean():
    import boto3
    from botocore.exceptions import ClientError
    from opentelemetry.trace import get_tracer

    s3 = boto3.client(
        "s3",
        endpoint_url="host",
        aws_access_key_id="aws_access_key_id",
        aws_secret_access_key="aws_secret_access_key",
        region_name="region",
    )

    otel_spawn_tracer = get_tracer("spawn")
    with otel_spawn_tracer.start_as_current_span("mytrace"):
        try:
            response = s3.head_object(Bucket="bucket", Key="non_existing_key.txt")
        except ClientError as exc:
            # Not found
            if exc.response.get("ResponseMetadata", {}).get("HTTPStatusCode", -1) == 404:
                return False
            raise
        else:
            return bool(response["ContentLength"])


# todo fix the config according to your s3 config

clean()
Expected Result

I didn't expect it to record an exception. Since this is a normal workflow to check if object exists. It's not an exceptional workflow.

Actual Result

I didn't expect it to record an exception since this is the normal workflow to check if objects exists in S3. Maybe we need a way to exclude some cases like this one from recording exceptions?

Additional context

No response

Would you like to implement a fix?

None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Python reproduction and locate the instrumentation path that records exceptions for boto3 S3 head_object(). Reproduce the 404 case and compare it with other ClientError responses. Done means a normal missing-object check is not recorded as an exception while genuinely unexpected errors remain recorded.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
cloud, observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.