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

Improve resource field structure for LogRecords #3972

Merged
merged 5 commits into from
Jun 17, 2024

Conversation

emdneto
Copy link
Member

@emdneto emdneto commented Jun 14, 2024

Description

In #3547, we suggested the resource field structure be more consistent for LogRecords by making it similar to the representation used in Spans when using a console exporter. This PR extends that by improving the resource field structure for LogRecords using the resource.to_json() method in the same way we have in spans

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

  • tox

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

@emdneto emdneto requested a review from a team as a code owner June 14, 2024 11:53
@lzchen
Copy link
Contributor

lzchen commented Jun 14, 2024

Are you getting a different output with the current implementation? I seem to get the expected dict representation when printing out the attributes of a resource.

tp = TracerProvider()
print(repr(tp.resource.attributes))

outputs:

{'telemetry.sdk.language': 'python', 'telemetry.sdk.name': 'opentelemetry', 'telemetry.sdk.version': '1.25.0', 'service.name': 'unknown_service'}

@emdneto
Copy link
Member Author

emdneto commented Jun 14, 2024

Are you getting a different output with the current implementation? I seem to get the expected dict representation when printing out the attributes of a resource.

tp = TracerProvider()
print(repr(tp.resource.attributes))

outputs:

{'telemetry.sdk.language': 'python', 'telemetry.sdk.name': 'opentelemetry', 'telemetry.sdk.version': '1.25.0', 'service.name': 'unknown_service'}

I think this repr is fine, but I was working on some tests with LogRecord and noticed the structure of the resource field is different from the one we have for spans (for example) during the to_json() call in LogRecord.

I found this issue #3547, which was concerned about that too. So I'm suggesting we use resource.to_json() for the resource field in the same way we have in traces sdk instead of repr. I updated the PR description to be more clear.

@emdneto emdneto changed the title Fix json output for LogRecord Improve resource field structure for LogRecords during json output Jun 16, 2024
@emdneto emdneto changed the title Improve resource field structure for LogRecords during json output Improve resource field structure for LogRecords Jun 16, 2024
@lzchen lzchen merged commit 2d5cd58 into open-telemetry:main Jun 17, 2024
269 checks passed
@xrmx xrmx mentioned this pull request Jun 26, 2024
1 task
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.

None yet

3 participants