-
Notifications
You must be signed in to change notification settings - Fork 678
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-instrumentation: expose a way to init autoinstrumentation programmatically #3273
Conversation
This is a draft because I haven't tested it yet outside of unit tests. |
b1511ec
to
fd93744
Compare
This works, thanks. Here is how I tested it. I checked out your branch Inside there, I replaced requirements.txt with this
Then, I replaced main.py with this: # pylint: skip-file
import os
from openai import OpenAI
from opentelemetry.instrumentation import auto_instrumentation
auto_instrumentation.initialize()
def main():
client = OpenAI()
chat_completion = client.chat.completions.create(
model=os.getenv("CHAT_MODEL", "gpt-4o-mini"),
messages=[
{
"role": "user",
"content": "Write a short poem on OpenTelemetry.",
},
],
)
print(chat_completion.choices[0].message.content)
if __name__ == "__main__":
main() Then, I ran |
This works, I was missing one dep and adjusted my comment! |
Tested this with a flask app, opentelemetry-instrument still work, in order to work manually the initialize() must be called before importing Flask, I guess the developer experience will depend on the instrumentation. |
d444489
to
39f81ce
Compare
yeah maybe in general we suggest to init before other imports, though code style might interfere with this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per earlier comments, this is exactly what I was looking for and happy to see it!
Co-authored-by: Emídio Neto <[email protected]>
Co-authored-by: Leighton Chen <[email protected]>
Description
Expose the initialize function used to init auto-instrumentation programmatically in a more conventient way instead of importing sitecustomize and expect its side effects. While at it also update the code to handle the case of PYTHONPATH not set.
Fixes #3263
Closes #2886
Type of change
Please delete options that are not relevant.
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
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.