Skip to content

[logs-sdk] Remove LogData and extend SDK LogRecord to have instrumentation scope #4676

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ can cause a deadlock to occur over `logging._lock` in some cases ([#4636](https:
([#4669](https://github.com/open-telemetry/opentelemetry-python/pull/4669))
- Set expected User-Agent in HTTP headers for grpc OTLP exporter
([#4658](https://github.com/open-telemetry/opentelemetry-python/pull/4658))
- Remove LogData and extend SDK LogRecord to have instrumentation scope
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a breaking changes section or something here, maybe I can update the title of the PR to reflect that

([#4676](https://github.com/open-telemetry/opentelemetry-python/pull/4676))

## Version 1.34.0/0.55b0 (2025-06-04)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,45 @@
ResourceLogs,
ScopeLogs,
)
from opentelemetry.sdk._logs import LogData
from opentelemetry.sdk._logs import SDKLogRecord


def encode_logs(batch: Sequence[LogData]) -> ExportLogsServiceRequest:
def encode_logs(batch: Sequence[SDKLogRecord]) -> ExportLogsServiceRequest:
return ExportLogsServiceRequest(resource_logs=_encode_resource_logs(batch))


def _encode_log(log_data: LogData) -> PB2LogRecord:
def _encode_log(log_record: SDKLogRecord) -> PB2LogRecord:
span_id = (
None
if log_data.log_record.span_id == 0
else _encode_span_id(log_data.log_record.span_id)
if log_record.span_id == 0
else _encode_span_id(log_record.span_id)
)
trace_id = (
None
if log_data.log_record.trace_id == 0
else _encode_trace_id(log_data.log_record.trace_id)
if log_record.trace_id == 0
else _encode_trace_id(log_record.trace_id)
)
body = log_data.log_record.body
body = log_record.body
return PB2LogRecord(
time_unix_nano=log_data.log_record.timestamp,
observed_time_unix_nano=log_data.log_record.observed_timestamp,
time_unix_nano=log_record.timestamp,
observed_time_unix_nano=log_record.observed_timestamp,
span_id=span_id,
trace_id=trace_id,
flags=int(log_data.log_record.trace_flags),
flags=int(log_record.trace_flags),
body=_encode_value(body, allow_null=True),
severity_text=log_data.log_record.severity_text,
attributes=_encode_attributes(
log_data.log_record.attributes, allow_null=True
),
dropped_attributes_count=log_data.log_record.dropped_attributes,
severity_number=log_data.log_record.severity_number.value,
event_name=log_data.log_record.event_name,
severity_text=log_record.severity_text,
attributes=_encode_attributes(log_record.attributes, allow_null=True),
dropped_attributes_count=log_record.dropped_attributes,
severity_number=log_record.severity_number.value,
event_name=log_record.event_name,
)


def _encode_resource_logs(batch: Sequence[LogData]) -> List[ResourceLogs]:
def _encode_resource_logs(batch: Sequence[SDKLogRecord]) -> List[ResourceLogs]:
sdk_resource_logs = defaultdict(lambda: defaultdict(list))

for sdk_log in batch:
sdk_resource = sdk_log.log_record.resource
sdk_resource = sdk_log.resource
sdk_instrumentation = sdk_log.instrumentation_scope or None
pb2_log = _encode_log(sdk_log)

Expand Down
Loading
Loading