Skip to content
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

Add more restrictive typing to Log body field #4185

Merged
merged 12 commits into from
Sep 30, 2024
Merged
14 changes: 14 additions & 0 deletions opentelemetry-api/src/opentelemetry/util/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@

from typing import Mapping, Optional, Sequence, Tuple, Union

# This is the implementation of the "Any" type as specified by the specifications of OpenTelemetry data model for logs.
# For more details, refer to the OTel specification:
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#type-any
AnyValue = Union[
emdneto marked this conversation as resolved.
Show resolved Hide resolved
str,
bool,
int,
float,
bytes,
Sequence["AnyValue"],
Mapping[str, "AnyValue"],
None,
]
xrmx marked this conversation as resolved.
Show resolved Hide resolved

AttributeValue = Union[
str,
bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
get_current_span,
)
from opentelemetry.trace.span import TraceFlags
from opentelemetry.util.types import Attributes
from opentelemetry.util.types import AnyValue, Attributes

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -179,7 +179,7 @@ def __init__(
trace_flags: Optional[TraceFlags] = None,
severity_text: Optional[str] = None,
severity_number: Optional[SeverityNumber] = None,
body: Optional[Any] = None,
body: Optional[AnyValue] = None,
resource: Optional[Resource] = None,
attributes: Optional[Attributes] = None,
limits: Optional[LogLimits] = _UnsetLogLimits,
Expand Down