Skip to content

Bug: OpenTelemetry span attributes use method references instead of calling for methods #2773

@da-the-dev

Description

@da-the-dev

Describe the bug
OpenTelemetry span attributes use method references instead of calling for methods as described in 1

How to reproduce
Minimal code

from faststream import FastStream
from faststream.confluent import KafkaBroker, KafkaMessage
from faststream.kafka.opentelemetry import KafkaTelemetryMiddleware
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter


# Setup tracing
resource = Resource.create({"service.name": "inference-worker"})
tracer_provider = TracerProvider(resource=resource)
trace.set_tracer_provider(tracer_provider)
otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True)
span_processor = BatchSpanProcessor(otlp_exporter)
tracer_provider.add_span_processor(span_processor)


# Broker and app
broker = KafkaBroker(
    "localhost:9092",
    middlewares=[KafkaTelemetryMiddleware(tracer_provider=tracer_provider)],
)
app = FastStream(broker)


# Basic subscriber
@broker.subscriber("chat.incoming", auto_offset_reset="earliest")
async def process_request(
    body: str,
    msg: KafkaMessage,
):
    print(body, msg.correlation_id)

Now send a message to that topic

After that, if you check Jaeger, you'll see the following trace
Image

Also, in the console for the inference-worker you'll see the following:

2026-02-18 13:28:23,180 INFO     - chat.incoming | 31-1771410 - Received
Invalid type builtin_function_or_method for attribute 'messaging.kafka.destination.partition' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
Invalid type builtin_function_or_method for attribute 'messaging.kafka.message.offset' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
Invalid type builtin_function_or_method for attribute 'messaging.destination_publish.name' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
Invalid type builtin_function_or_method for attribute 'messaging.kafka.message.key' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
awdwda 63504778-593d-4ff4-9f35-9b97e5f2b659
2026-02-18 13:28:23,181 INFO     - chat.incoming | 31-1771410 - Processed

Expected behavior
A correctly named trace and no warnings in the console

Observed behavior
Warnings in the console and incorrectly named trace

Environment

$ faststream -v
Running FastStream 0.6.6 with CPython 3.12.11 on Darwin

Environment in requirement.txt. I use this environment in a real project, so some packages (like redis) might be unrelated to the bug. Key deps are OTEL deps and faststream dep

# This file was autogenerated by uv via the following command:
#    uv export --format requirements.txt --no-hashes --no-annotate
aiokafka==0.13.0
altair==6.0.0
annotated-doc==0.0.4
annotated-types==0.7.0
anyio==4.12.1
asgiref==3.11.1
async-timeout==5.0.1
attrs==25.4.0
blinker==1.9.0
cachetools==6.2.6
certifi==2026.1.4
charset-normalizer==3.4.4
click==8.3.1
colorama==0.4.6 ; sys_platform == 'win32'
confluent-kafka==2.13.0
fast-depends==3.0.5
fastapi==0.129.0
faststream==0.6.6
gitdb==4.0.12
gitpython==3.1.46
googleapis-common-protos==1.72.0
grpcio==1.78.0
h11==0.16.0
idna==3.11
importlib-metadata==8.7.1
jinja2==3.1.6
jsonschema==4.26.0
jsonschema-specifications==2025.9.1
kafka==1.3.5
kafka-python==2.3.0
kafka-python-ng==2.2.3
markdown-it-py==4.0.0
markupsafe==3.0.3
mdurl==0.1.2
narwhals==2.16.0
numpy==2.4.2
opentelemetry-api==1.39.1
opentelemetry-exporter-otlp==1.39.1
opentelemetry-exporter-otlp-proto-common==1.39.1
opentelemetry-exporter-otlp-proto-grpc==1.39.1
opentelemetry-exporter-otlp-proto-http==1.39.1
opentelemetry-instrumentation==0.60b1
opentelemetry-instrumentation-asgi==0.60b1
opentelemetry-instrumentation-fastapi==0.60b1
opentelemetry-instrumentation-kafka-python==0.60b1
opentelemetry-proto==1.39.1
opentelemetry-sdk==1.39.1
opentelemetry-semantic-conventions==0.60b1
opentelemetry-util-http==0.60b1
packaging==26.0
pandas==2.3.3
pillow==12.1.1
protobuf==6.33.5
pyarrow==23.0.1
pydantic==2.12.5
pydantic-core==2.41.5
pydeck==0.9.1
pygments==2.19.2
python-dateutil==2.9.0.post0
pytz==2025.2
redis==7.2.0
referencing==0.37.0
requests==2.32.5
rich==14.3.2
rpds-py==0.30.0
shellingham==1.5.4
six==1.17.0
smmap==5.0.2
starlette==0.52.1
streamlit==1.54.0
tenacity==9.1.4
toml==0.10.2
tornado==6.5.4
typer==0.21.1
typing-extensions==4.15.0
typing-inspection==0.4.2
tzdata==2025.3
urllib3==2.6.3
uvicorn==0.41.0
watchdog==6.0.0 ; sys_platform != 'darwin'
watchfiles==1.1.1
wrapt==1.17.3
zipp==3.23.0

Additional context

  • I closely followed this tutorial, but swapped for Jaeger
  • docker compose just for convenience
services:
  kafka:
    image: confluentinc/cp-kafka
    container_name: kafka
    ports:
      - "9092:9092"
    environment:
      KAFKA_KRAFT_MODE: "true"

      CLUSTER_ID: "test_cluster"
      KAFKA_NODE_ID: 1

      KAFKA_PROCESS_ROLES: broker,controller
      KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
      KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER

      KAFKA_LOG_DIRS: /tmp/kraft-combined-logs
    volumes:
      - kafka_raft:/var/lib/kafka/data

  otel-collector:
    image: otel/opentelemetry-collector-contrib:latest
    command: ["--config=/etc/otel-collector-config.yaml"]
    volumes:
      - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
    ports:
      - "4317:4317" # OTLP gRPC receiver

  jaeger:
    image: cr.jaegertracing.io/jaegertracing/jaeger:2.15.0
    ports:
      - "6831:6831/udp" # UDP port for Jaeger agent
      - "16686:16686" # Web UI
      - "14268:14268" # HTTP port for spans
    depends_on:
      - otel-collector

volumes:
  kafka_raft:

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions