{"record":{"id":"af0de6c07126f711","repo":"microsoft/autogen","slug":"unknown-metadata-type-type-metadata","errorCode":null,"errorMessage":"Unknown metadata type: {type(metadata)}","messagePattern":"Unknown metadata type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/_telemetry/_propagation.py","lineNumber":99,"sourceCode":"\ndef get_telemetry_context(metadata: TelemetryMetadataContainer) -> Context:\n    \"\"\"\n    Retrieves the telemetry context from the given metadata.\n\n    Args:\n        metadata (Optional[EnvelopeMetadata]): The metadata containing the telemetry context.\n\n    Returns:\n        Context: The telemetry context extracted from the metadata, or an empty context if the metadata is None.\n    \"\"\"\n    if metadata is None:\n        return Context()\n    elif isinstance(metadata, EnvelopeMetadata):\n        return extract(_get_carrier_for_envelope_metadata(metadata))\n    elif hasattr(metadata, \"__getitem__\"):\n        return extract(_get_carrier_for_remote_call_metadata(metadata))\n    else:\n        raise ValueError(f\"Unknown metadata type: {type(metadata)}\")\n\n\ndef get_telemetry_links(\n    metadata: TelemetryMetadataContainer,\n) -> Optional[Sequence[Link]]:\n    \"\"\"\n    Retrieves the telemetry links from the given metadata.\n\n    Args:\n        metadata (Optional[EnvelopeMetadata]): The metadata containing the telemetry links.\n\n    Returns:\n        Optional[Sequence[Link]]: The telemetry links extracted from the metadata, or None if there are no links.\n    \"\"\"\n    if metadata is None:\n        return None\n    elif isinstance(metadata, EnvelopeMetadata):\n        context = extract(_get_carrier_for_envelope_metadata(metadata))","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_telemetry/_propagation.py#L81-L117","documentation":"In the telemetry propagation helper, get_telemetry_context_from_metadata accepts only three shapes: None (empty context), an EnvelopeMetadata instance, or any object exposing __getitem__ (dict-like remote-call metadata such as gRPC/OPC metadata). Anything else raises ValueError with the offending type name. The function is part of OpenTelemetry trace-context propagation, so the error means your metadata carrier is an unsupported type before telemetry extraction can even run.","triggerScenarios":"Passing a string, bytes, list of tuples without __getitem__, a dataclass, or a custom metadata object to the telemetry extraction path — typically indirectly by putting a non-standard metadata object on a message envelope or RPC call that the runtime then instruments.","commonSituations":"Custom transports or protocols that define their own metadata type instead of reusing EnvelopeMetadata or a Mapping; upgrading autogen-core where the telemetry module became stricter; test doubles that stub metadata with a plain object() or NamedTuple.","solutions":["Convert your metadata to a dict (or any Mapping) before it reaches the runtime — duck-typed __getitem__ support is enough.","Use autogen_core's own EnvelopeMetadata when attaching telemetry context to message envelopes.","Pass None when there is no telemetry context to propagate.","If you wrote a custom transport, mirror how the built-in gRPC transport exposes metadata as a Mapping."],"exampleFix":"# before\nspan_context = get_telemetry_context_from_metadata(\"traceparent: 00-abc...\")  # ValueError\n\n# after\nspan_context = get_telemetry_context_from_metadata({\"traceparent\": \"00-abc...\"})","handlingStrategy":"validation","validationCode":"def is_supported_metadata(md: object) -> bool:\n    return md is None or isinstance(md, EnvelopeMetadata) or hasattr(md, \"__getitem__\")\n\nassert is_supported_metadata(my_metadata)","typeGuard":"from typing import Mapping, Optional, Union\nfrom autogen_core.models._types import EnvelopeMetadata  # adjust import to actual path\n\nSupportedMetadata = Optional[Union[EnvelopeMetadata, Mapping[str, str]]]","tryCatchPattern":"try:\n    ctx = get_telemetry_context_from_metadata(md)\nexcept ValueError:\n    ctx = Context()  # telemetry is best-effort; degrade to no propagation","preventionTips":["Represent RPC metadata as dict/Mapping, not custom classes.","Reuse EnvelopeMetadata for message envelopes instead of inventing a carrier type.","Add a type annotation of Optional[Union[EnvelopeMetadata, Mapping]] at API boundaries to catch this statically."],"tags":["python","autogen-core","telemetry","opentelemetry","metadata","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}