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

Add instrumentation example to logging #3314

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

Conversation

andremm
Copy link
Contributor

@andremm andremm commented Feb 28, 2025

Description

There's no instrumentation examples inside logging. This PR adds one example.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  1. Clone contrib repo: git clone https://github.com/open-telemetry/opentelemetry-python-contrib
  2. Clone OTel Python repo: git clone https://github.com/open-telemetry/opentelemetry-python
  3. Access the contrib repo: cd opentelemetry-python-contrib
  4. Create a virtual env: python3 -m venv otelvenv
  5. Activate the virtual env: source otelvenv/bin/activate
  6. Install common dependencies:
pip install opentelemetry-distro/ opentelemetry-instrumentation/ \
 ../opentelemetry-python/opentelemetry-semantic-conventions/ \
 ../opentelemetry-python/opentelemetry-api/ \
 ../opentelemetry-python/opentelemetry-sdk/ \
 ../opentelemetry-python/opentelemetry-proto/ \
 ../opentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-common
  1. Install logging specific requirements:
pip install -r instrumentation/opentelemetry-instrumentation-logging/test-requirements.txt
  1. Copy the instrumentation examples inside the instrumentation main __init__.py file into different Python files and try to run them.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

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

@xrmx xrmx added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Feb 28, 2025

LoggingInstrumentor().instrument()

logging.warning('OTel test')
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be useful to add an example of the output after the code block

Copy link
Contributor

Choose a reason for hiding this comment

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

Uhm I think we need an export OTEL_PYTHON_LOG_CORRELATION=true to have the instrumentation do something

Copy link
Member

Choose a reason for hiding this comment

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

In #2904 there are some sentences regarding this I think we can reuse here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks both for pointing that out. I had missed that. @emdneto I borrowed some sentences from the documentation to improve the examples. :)

logging.warning('OTel test')

When running the above example you will see the following output:
```
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this syntax works for rst


.. code-block:: python

# export OTEL_PYTHON_LOG_CORRELATION=true
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# export OTEL_PYTHON_LOG_CORRELATION=true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants