Skip to content

Instantly share code, notes, and snippets.

@pridhi-arora
Last active February 20, 2023 13:33
Show Gist options
  • Save pridhi-arora/4a97d6403cc8fa582b636d00bdb832a9 to your computer and use it in GitHub Desktop.
Save pridhi-arora/4a97d6403cc8fa582b636d00bdb832a9 to your computer and use it in GitHub Desktop.
opentelemetry Outreachy
Things to read:
grpc: https://grpc.io/docs/what-is-grpc/core-concepts/
https://opentelemetry.io/docs/instrumentation/python/
@pridhi-arora
Copy link
Author

pridhi-arora commented Nov 25, 2022

Creating a virtual environment
python -m venv <directory>

python3 -m venv otel_env
Activate/sourcing the virtual environment
source otel_env/bin/activate
make sure you are creating this environment inside of the project you are working on.
cd opentelemetry-python
the above environment was created in open telemetry python.

@pridhi-arora
Copy link
Author

pridhi-arora commented Nov 25, 2022

ls in opentelemetry-python, there is dev_requirements.txt
cat dev_requirements.txt to view the requirements

make sure your virtual env is activated then install the requirements using this pip command
pip install -r dev_requirements.txt

To check the installed requirements use pip freeze command

@pridhi-arora
Copy link
Author

write command deactivate to deactivate the python virtual env

@pridhi-arora
Copy link
Author

Clone project:
Goto PR
click <>code on left
click <>code on right
clone SSH
Goto terminal : git clone 'copied SSH'

@pridhi-arora
Copy link
Author

@pridhi-arora
Copy link
Author

would reformat otel_env/lib64/python3.9/site-packages/pip/_vendor/html5lib/treebuilders/etree.py

Oh no! 💥 💔 💥
4 files would be reformatted, 13931 files would be left unchanged.
Traceback (most recent call last):
  File "/home/pridhi/opentelemetry-python/scripts/eachdist.py", line 675, in <module>
    main()
  File "/home/pridhi/opentelemetry-python/scripts/eachdist.py", line 671, in main
    args.func(args)
  File "/home/pridhi/opentelemetry-python/scripts/eachdist.py", line 518, in lint_args
    runsubprocess(
  File "/home/pridhi/opentelemetry-python/scripts/eachdist.py", line 388, in runsubprocess
    return subprocess_run(params, *args, check=check, **kwargs)
  File "/usr/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/home/pridhi/opentelemetry-python/.tox/lint/bin/black', '--config', 'pyproject.toml', '.', '--diff', '--check']' returned non-zero exit status 1.
ERROR: InvocationError for command /home/pridhi/opentelemetry-python/.tox/lint/bin/python scripts/eachdist.py lint --check-only (exited with code 1)
_________________________________________________________________________________________________ summary _________________________________________________________________________________________________
ERROR:   lint: commands failed

@pridhi-arora
Copy link
Author

Faced some issues in otel_env, so created a new environment and deleted the existing one by using the command rm -rf otel_env.
issue was
ImportError: cannot import name '__diag__' from partially initialized module 'pip._vendor.pyparsing' (most likely due to a circular import) (/home/pridhi/opentelemetry-python/otel_env/lib/python3.9/site-packages/pip/_vendor/pyparsing/__init__.py)
Created a new otel_env, now I ran black . , it was reformatting the otel_env also so we moved the environment to the previous directory by using the command
mv otel_env ../

@pridhi-arora
Copy link
Author

Lint errors were not getting fixed. For some reason, the main branch was failing with specific lint errors which were not being reflected on CI.

************* Module opentelemetry-sdk.src.opentelemetry.sdk.metrics._internal.aggregation
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py:19:0: E0611: No name 'inf' in module 'math' (no-name-in-module)
************* Module opentelemetry-sdk.src.opentelemetry.sdk.metrics._internal.exponential_histogram.mapping.exponent_mapping
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exponential_histogram/mapping/exponent_mapping.py:15:0: E0611: No name 'ldexp' in module 'math' (no-name-in-module)
************* Module opentelemetry-sdk.src.opentelemetry.sdk.metrics._internal.exponential_histogram.mapping.logarithm_mapping
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exponential_histogram/mapping/logarithm_mapping.py:15:0: E0611: No name 'exp' in module 'math' (no-name-in-module)
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exponential_histogram/mapping/logarithm_mapping.py:15:0: E0611: No name 'floor' in module 'math' (no-name-in-module)
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exponential_histogram/mapping/logarithm_mapping.py:15:0: E0611: No name 'ldexp' in module 'math' (no-name-in-module)
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exponential_histogram/mapping/logarithm_mapping.py:15:0: E0611: No name 'log' in module 'math' (no-name-in-module)
************* Module exporter.opentelemetry-exporter-jaeger-thrift.src.opentelemetry.exporter.jaeger.thrift.send
exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/send.py:74:26: I1101: Module 'math' has no 'ceil' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member)
exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/send.py:75:22: I1101: Module 'math' has no 'ceil' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member)
exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/send.py:94:27: E1101: Module 'socket' has no 'AF_INET' member (no-member)
exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/send.py:94:43: E1101: Module 'socket' has no 'SOCK_DGRAM' member (no-member)


@pridhi-arora
Copy link
Author

I tried to set up and get tracing telemetry from an HTTP server with Flask. For this, I installed flask and opentelemetry-distro package after this created the HTTP server with the /rolldice route. The code for the same is

from random import randint
from flask import Flask, request

app = Flask(__name__)

@app.route("/rolldice")
def roll_dice():
    return str(do_roll())

def do_roll():
    return randint(1, 6)

But I failed to run this. So, I added the following lines to the end of code

if __name__ == " __main__ " :
    app.run()

After this, I installed flask instrumentation
opentelemetry-bootstrap -a install
For running the instrumented app :

opentelemetry-instrument \
    --traces_exporter console \
    --metrics_exporter console \
    flask run

After sending a request to the server we now get a trace with a span in the console.

@pridhi-arora
Copy link
Author

typed-ast error, switch to python 3.9 for all the errors.

@pridhi-arora
Copy link
Author

pridhi-arora commented Feb 20, 2023

Also, use tox from the development version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment