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

logs: introduce LogAttributes type #4342

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

xrmx
Copy link
Contributor

@xrmx xrmx commented Dec 9, 2024

Description

Logs attribute accepts AnyValue as AttributeValue add a type to describe that and start using it.

Fixes #4315

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • 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

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@xrmx xrmx requested a review from a team as a code owner December 9, 2024 11:45
@xrmx xrmx marked this pull request as draft December 9, 2024 11:46
@xrmx xrmx added the Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary label Dec 9, 2024
@@ -273,7 +273,7 @@ def get_logger(
instrumenting_library_version: str = "",
logger_provider: Optional[LoggerProvider] = None,
schema_url: Optional[str] = None,
attributes: Optional[Attributes] = None,
attributes: LogAttributes = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason not to have them as Optional like other params?

Copy link
Contributor Author

@xrmx xrmx Dec 16, 2024

Choose a reason for hiding this comment

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

They are, it's just that it's not repeated :)

LogAttributes = Optional[Mapping[str, "AnyValue"]]

Copy link

Choose a reason for hiding this comment

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

Yeah, but that's not really common. This usually leads to a wrong type inside the function, because you usually want different logic between None (default), and the actual type.

opentelemetry-api/src/opentelemetry/util/types.py Outdated Show resolved Hide resolved
@@ -273,7 +273,7 @@ def get_logger(
instrumenting_library_version: str = "",
logger_provider: Optional[LoggerProvider] = None,
schema_url: Optional[str] = None,
attributes: Optional[Attributes] = None,
attributes: LogAttributes = None,
Copy link

Choose a reason for hiding this comment

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

Yeah, but that's not really common. This usually leads to a wrong type inside the function, because you usually want different logic between None (default), and the actual type.

@xrmx xrmx force-pushed the logs-attributes-typing branch from 66ec409 to 57a6fb3 Compare December 24, 2024 08:15
@xrmx xrmx requested a review from lmolkova December 24, 2024 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Logs API and SDK: logs attributes are allowed to have AnyValue values
4 participants