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

Conversation

hectorhdzg
Copy link
Member

@hectorhdzg hectorhdzg commented Jul 9, 2025

Description

Removing LogData and extending SDK LogRecord to have instrumentation scope

Fixes #4313

Type of change

Please delete options that are not relevant.

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A

@hectorhdzg hectorhdzg requested a review from a team as a code owner July 9, 2025 23:05
@hectorhdzg
Copy link
Member Author

Contrib tests expect an object like log.log_record returned in log_exporter.get_finished_logs()
I can update contrib tests for this breaking issue, let me know your thoughts

@DylanRussell
Copy link
Contributor

What if instead of removing LogData, we remove LogRecord from the SDK, and update LogData to have 3 fields: the API LogRecord, the resource, and the instrumentation_scope..

I don't think we need a LogRecord in both the API and the SDK, when they are exactly the same except for 2 additional fields on the SDK version (resource and instrumentation_scope)..

This way we don't need to update 2 classes every time a change is made to the log data structure.

Also I think our implementation is confusing the 2 classes in a bunch of places maybe because they are named the same. For example I think Logger.emit should be taking an API LogRecord instead of an SDK one. We tell instrumentations to use the API LogRecord, and instrumentations therfore call Logger.emit with the API LogRecord, the SDK implementation should be adding instrumentation_scope and resource (to LogData) and then forward it along..

@hectorhdzg
Copy link
Member Author

@DylanRussell
Copy link
Contributor

DylanRussell commented Jul 14, 2025

Yeah I think i'm OK with that name too. But what do you think of it being just the 3 fields I mentioned above ? And switching Logger.emit in the SDK to take the API LogRecord and then create the SDK LogRecord and attach instrumentation_scope/resource to it..

That looks to be what javascript is doing too:

https://github.com/open-telemetry/opentelemetry-js/blob/99dde7786f52d8d7e3d080a0a69b9685104c29e2/experimental/packages/sdk-logs/src/Logger.ts#L42

@@ -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

@@ -49,13 +48,9 @@ def emit(self, event: Event) -> None:
if isinstance(self._logger, NoOpLogger):
# Do nothing if SDK is disabled
return
span_context = trace.get_current_span().get_span_context()
Copy link
Member Author

Choose a reason for hiding this comment

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

Context is not being passed anymore, but this code is going away so not sure if we want to add it

@hectorhdzg
Copy link
Member Author

@DylanRussell updated, still having SDKLogRecord inheriting API LogRecord, having the API LogRecord as an attribute feels really weird to me, I think it could cause more confusion an issues than solving them, let me know what you think.

@@ -210,48 +195,20 @@ def __init__(
event_name: str | None = None,
): ...

@overload
@deprecated(
Copy link
Member Author

Choose a reason for hiding this comment

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

This is changing the actual class name so I think is a good opportunity to get rid of previously deprecated parameters

@hectorhdzg
Copy link
Member Author

@open-telemetry/python-maintainers this is definitely a big breaking change, do we want to use another branch to group the Logs updates together?, we discussed this last week SIG meeting, but trying to understand what is the best way to move forward here.

@DylanRussell
Copy link
Contributor

In my opinion just have SdkLogRecord with a ApiLogRecord attribute, it should not inherit from it at all now.. We don't need another class with all the same attributes.

We just need a small wrapper class..

Logger.emit should accept an ApiLogRecord (not an SDK log record), it should then create the SdkLogRecord with the logger's instrumentation_scope and resource.

And LoggingHandler._translate should produce an ApiLogRecord..

@DylanRussell
Copy link
Contributor

Looks like some instrumentations fail w/ this change (https://github.com/open-telemetry/opentelemetry-python-contrib/blob/f20fa77ad59d90aae4978ae28cb1a98b12fbb959/instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/test_function_calling.py#L4 -- this instrumentation is accessing log_data.log_record.. If you keep log_record as an attribute that might pass)

Copy link
Contributor

@DylanRussell DylanRussell left a comment

Choose a reason for hiding this comment

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

Mostly LGTM

@DylanRussell
Copy link
Contributor

I know at one of the spec meetings we agreed it was a good idea to make a bunch of the breaking changes in one release.. Do we want to add the @Deprecation wrappers to some of these things first (ex: on LogData and the SDK LogRecord), wait a release, then do it, or just go ahead and make the change ?

@xrmx
Copy link
Contributor

xrmx commented Jul 24, 2025

This may also fix #4319

@hectorhdzg
Copy link
Member Author

@aabmass @DylanRussell I'm struggling to implement ReadableLogRecord and ReadWriteLogRecord(SDKLogRecord) with current composition approach (SDKLogRecord having a log_record attribute instead of inheriting from API LogRecord), inheritance model is being used in Span and that is pretty easy for me to follow, with composition model I need to create ReadableLogRecord class with some special API log_record attribute that is read only, so I may need to define another ReadableApiLogRecord, not sure if that is what we want. let me know what you think
https://opentelemetry.io/docs/specs/otel/logs/sdk/#additional-logrecord-interfaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logs SDK: consider removing LogData and extending SDK LogRecord to have instrumentation scope
3 participants