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

opentelemetry: add span event attributes #6531

Conversation

v1v
Copy link
Contributor

@v1v v1v commented May 17, 2023

SUMMARY

Enable populating span attributes to event attributes with OpenTelemetry in order to allow logs correlations with traces.

This is quite handy when the OTEL ventor does not show those details in the UI directly.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

opentelemetry

ADDITIONAL INFORMATION

#4175 was the original implementation.

Closes #6526

Given

---
- name: MyPlabook
  hosts: localhost
  connection: local

  roles:
  - role: myrole
  tasks:
  - name: MyTask2
    uri:
      url: https://www.elastic.co
      return_content: no
    register: webpage

And if I run with the logs:

OTEL_SERVICE_NAME=test-ansible \
OTEL_EXPORTER_OTLP_ENDPOINT=localhost:4317 \
OTEL_EXPORTER_OTLP_INSECURE=true \
ansible-playbook -i hosts my-playbook.yml

Produces

Kapture 2023-05-17 at 22 57 46

image

And if I run setting the attributes in the logs to false:

OTEL_SERVICE_NAME=test-ansible \
OTEL_EXPORTER_OTLP_ENDPOINT=localhost:4317 \
OTEL_EXPORTER_OTLP_INSECURE=true \
ANSIBLE_OPENTELEMETRY_DISABLE_ATTRIBUTES_IN_LOGS=false \
ansible-playbook -i hosts my-playbook.yml

Produces

image

@v1v v1v changed the title add span event attributes (task name and host name) opentelemetry: add span event attributes (task name and host name) May 17, 2023
@ansibullbot ansibullbot added WIP Work in progress callback callback plugin feature This issue/PR relates to a feature request plugins plugin (any type) small_patch Hopefully easy to review labels May 17, 2023
@v1v v1v marked this pull request as ready for review May 17, 2023 21:05
@ansibullbot ansibullbot removed WIP Work in progress small_patch Hopefully easy to review labels May 17, 2023
@ansibullbot ansibullbot added has_issue needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels May 17, 2023
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-7 labels May 18, 2023
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label May 26, 2023
@v1v v1v changed the title opentelemetry: add span event attributes (task name and host name) opentelemetry: add span event attributes May 30, 2023
@v1v
Copy link
Contributor Author

v1v commented May 30, 2023

I just refactored the span attributes to be able to populate the same attributes to the span events

Elastic specific view for the events

image

Jaeger specific view for the span/logs

image

@ansibullbot ansibullbot removed the stale_ci CI is older than 7 days, rerun before merging label May 30, 2023
@felixfontein
Copy link
Collaborator

@v1v do you want to make more changes, or is this ready for merging?

@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label May 31, 2023
there are some vendors that might not require those attributes since those details are shown in the UI when accessing the spans, i.e.: jaeger
@v1v
Copy link
Contributor Author

v1v commented May 31, 2023

do you want to make more changes, or is this ready for merging?

I think It's now ready to be reviewed, I was not happy with the initial implementation, so there is a new flag to disable this behaviour. Some OTEL vendors might visualise the span attributes in the logs while others won't, hence the feature flag to disable when no needed.

Thanks for your review 🙏

@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels May 31, 2023
Co-authored-by: Felix Fontein <felix@fontein.de>
@ansibullbot ansibullbot removed ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels May 31, 2023
@gone-for-coding
Copy link

This looks great @v1v! Looking forward to having it in the next release.

Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

I glanced over the change, it looks good to me. If nobody objects I'll merge in a couple of days.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Jun 6, 2023
@felixfontein felixfontein merged commit 58958fc into ansible-collections:main Jun 6, 2023
@patchback
Copy link

patchback bot commented Jun 6, 2023

Backport to stable-7: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-7/58958fc417c832d024c6a6e0ddf6f7ceaae656e6/pr-6531

Backported as #6631

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jun 6, 2023
* add span event attributes (task name and host name)

* add fragment

* refactor: use set_attributes

* Add same span attributes to the event

* chore: change description in the fragment

* as mentioned in the code review

* use flag to disable the attributes in logs

there are some vendors that might not require those attributes since those details are shown in the UI when accessing the spans, i.e.: jaeger

* Update plugins/callback/opentelemetry.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 58958fc)
@felixfontein
Copy link
Collaborator

@v1v thanks for your contribution!

felixfontein pushed a commit that referenced this pull request Jun 6, 2023
…attributes (#6631)

opentelemetry: add span event attributes (#6531)

* add span event attributes (task name and host name)

* add fragment

* refactor: use set_attributes

* Add same span attributes to the event

* chore: change description in the fragment

* as mentioned in the code review

* use flag to disable the attributes in logs

there are some vendors that might not require those attributes since those details are shown in the UI when accessing the spans, i.e.: jaeger

* Update plugins/callback/opentelemetry.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 58958fc)

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
span.end(end_time=host_data.finish)
# This will avoid populating span attributes to the logs
span.add_event(task_data.dump, attributes={} if disable_attributes_in_logs else attributes)
span.end(end_time=host_data.finish)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bug, I've just found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
callback callback plugin feature This issue/PR relates to a feature request has_issue plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add more information to opentelemetry logs
4 participants