Skip to content

S3 HeadObject returns 403 when sentry_sdk.start_span and Datadog botocore instrumentation are both active #7031

Description

@andrey-berenda

Environment

  • Python 3.14
  • Linux aarch64
  • sentry-sdk==2.66.0
  • ddtrace==4.12.1 (Datadog admission-controller library injection)
  • FastAPI
  • boto3/botocore with AWS SigV4

Description

An S3 HeadObject request against an existing, accessible object returns 403 Forbidden only when it executes inside sentry_sdk.start_span(...) while Datadog's botocore integration is active. The same pod identity, bucket, key, client configuration, and credentials return 200 OK when either the Sentry span is removed or Datadog's botocore integration is disabled.

This also reproduces through our real FastAPI endpoint. The example below is read-only and reproduces on its first request.

Minimal reproducer

import boto3
import sentry_sdk
from botocore.config import Config
from fastapi import FastAPI
from fastapi.testclient import TestClient
from sentry_sdk.integrations.fastapi import FastApiIntegration

sentry_sdk.init(
    dsn=None,
    traces_sample_rate=1.0,
    integrations=[FastApiIntegration()],
)

s3 = boto3.client(
    "s3",
    config=Config(
        signature_version="s3v4",
        s3={
            "addressing_style": "virtual",
            "us_east_1_regional_endpoint": "regional",
        },
    ),
)

app = FastAPI()

@app.post("/reproduce")
def reproduce():
    with sentry_sdk.start_span(op="dependency.resolve", name="FileStorage"):
        response = s3.head_object(
            Bucket="YOUR_BUCKET",
            Key="YOUR_EXISTING_KEY",
        )
    return {"status": response["ResponseMetadata"]["HTTPStatusCode"]}

response = TestClient(app).post("/reproduce")
print(response.status_code, response.text)

Run under Datadog auto-instrumentation, for example:

DD_TRACE_BOTOCORE_ENABLED=true ddtrace-run python reproducer.py

Actual result

botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden

Control matrix

Datadog botocore integration Nested sentry_sdk.start_span Result
enabled present 403 Forbidden
enabled absent 200 OK
disabled present 200 OK

The confirmed workaround is:

DD_TRACE_BOTOCORE_ENABLED=false

A corresponding Datadog report exists at DataDog/dd-trace-py#19477. This appears to be an interoperability issue; we are reporting it to both projects because the trigger requires both instrumentations.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions