Skip to content

Commit 7eb9f58

Browse files
committed
Update
1 parent 1025fb1 commit 7eb9f58

2 files changed

Lines changed: 87 additions & 126 deletions

File tree

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ def _from_env_if_absent(
158158
return value
159159

160160

161-
_UnsetLogLimits = LogLimits(
162-
max_attributes=LogLimits.UNSET,
163-
max_attribute_length=LogLimits.UNSET,
164-
)
165-
166-
167161
@dataclass(frozen=True)
168162
class ReadableLogRecord:
169163
"""Readable LogRecord should be kept exactly in-sync with ReadWriteLogRecord, only difference is the frozen=True param."""
@@ -188,35 +182,23 @@ class ReadWriteLogRecord:
188182
pertinent to the event being logged.
189183
"""
190184

191-
@overload
192-
def __init__(
193-
self,
194-
log_record: LogRecord,
195-
resource: Resource | None = None,
196-
197-
limits: LogLimits | None = _UnsetLogLimits,
198-
): ...
185+
log_record: LogRecord
186+
resource: Resource | None = Resource.create({})
187+
instrumentation_scope: InstrumentationScope | None = None
188+
limits: LogLimits | None = None
199189

200-
def __init__(
201-
self,
202-
log_record: LogRecord,
203-
resource: Resource | None = None,
204-
limits: LogLimits | None = _UnsetLogLimits,
205-
instrumentation_scope: InstrumentationScope | None = None,
206-
):
207-
self.log_record = log_record
190+
def __post_init__(self):
191+
if self.limits is None:
192+
self.limits = LogLimits()
208193
self.log_record.attributes = BoundedAttributes(
209-
maxlen=limits.max_attributes,
194+
maxlen=self.limits.max_attributes,
210195
attributes=self.log_record.attributes
211196
if self.log_record.attributes
212197
else None,
213198
immutable=False,
214-
max_value_len=limits.max_attribute_length,
199+
max_value_len=self.limits.max_attribute_length,
215200
extended_attributes=True,
216201
)
217-
218-
self.resource = resource if resource else Resource.create({})
219-
self.instrumentation_scope = instrumentation_scope
220202
if self.dropped_attributes > 0:
221203
warnings.warn(
222204
"Log record attributes were dropped due to limits",
@@ -282,11 +264,13 @@ def _from_api_log_record(
282264
record: LogRecord,
283265
resource: Resource,
284266
instrumentation_scope: InstrumentationScope | None = None,
267+
limits: LogLimits | None = None,
285268
) -> ReadWriteLogRecord:
286269
return cls(
287270
log_record=record,
288271
resource=resource,
289272
instrumentation_scope=instrumentation_scope,
273+
limits=limits,
290274
)
291275

292276

0 commit comments

Comments
 (0)