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

🐛 Bug Report: Google Instrumentation does not work #2140

Closed
1 task done
coffecup25 opened this issue Oct 15, 2024 · 2 comments · Fixed by #2288
Closed
1 task done

🐛 Bug Report: Google Instrumentation does not work #2140

coffecup25 opened this issue Oct 15, 2024 · 2 comments · Fixed by #2288
Labels
bug Something isn't working

Comments

@coffecup25
Copy link

Which component is this bug for?

Traceloop SDK

📜 Description

The python sdk does not instrument the calls when using the google_generativeai sdk. However when manually calling the instrumentation like this:

from opentelemetry.instrumentation.google_generativeai import GoogleGenerativeAiInstrumentor

GoogleGenerativeAiInstrumentor().instrument()

The calls are correctly added to the trace.

👟 Reproduction steps

The example code doesn't work from the traceloop website doesn't work.

import google.generativeai as genai
from traceloop.sdk import Traceloop
from traceloop.sdk.decorators import workflow
from traceloop.sdk.instruments import Instruments

import os 
import dotenv

dotenv.load_dotenv(dotenv.find_dotenv())
Traceloop.init(app_name="joke_generation_service", instruments={Instruments.GOOGLE_GENERATIVEAI})


genai.configure(api_key=os.environ.get("GENAI_API_KEY"))

@workflow(name="joke_creation")
def create_joke():
    model = genai.GenerativeModel("gemini-1.0-pro-latest")
    response = model.generate_content(
        "Give me ten interview questions for the role of program manager.",
    )

    return response.text

print(create_joke())

👍 Expected behavior

The instrumentation should automatically work instead of having to manually initialise it.

👎 Actual Behavior with Screenshots

The calls using the google_generativeai calls didn't show up in my Grafana Tempo until I started the instrumentor from opentelementry manually

🤖 Python Version

3.12

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

None

@dosubot dosubot bot added the bug Something isn't working label Oct 15, 2024
Copy link

dosubot bot commented Oct 15, 2024

Hey there, @coffecup25! I'm here to help you out with any bugs, questions, or contributions you have in mind. Let's squash those bugs together! 🐞

The issue you're experiencing with the Traceloop SDK not automatically instrumenting the google_generativeai SDK can occur due to several reasons. Here are some steps and considerations to help address this:

  1. Manual Instrumentation: As you've discovered, manually calling the instrumentation using GoogleGenerativeAiInstrumentor().instrument() works. This suggests that the automatic instrumentation might not be initializing correctly in your setup.

  2. Initialization Order: Ensure that the Traceloop SDK is initialized before any calls to the google_generativeai SDK. This is crucial for the automatic instrumentation to hook into the library correctly.

  3. Check for Errors: The Traceloop SDK provides logging features that can help identify issues with automatic instrumentation. Ensure that any exceptions during the initialization are logged. You can modify the init_google_generativeai_instrumentor function to log exceptions if it's not already doing so.

  4. Environment Variables: Verify that all necessary environment variables, such as TRACELOOP_API_KEY, are correctly set and accessible in your environment.

  5. Disable Batch Sending: If you're working locally, try disabling batch sending to see if traces are sent immediately:

    Traceloop.init(disable_batch=True)
  6. Console Exporter: Use the ConsoleExporter to verify if traces are being generated and output to the console:

    from opentelemetry.sdk.trace.export import ConsoleSpanExporter
    
    Traceloop.init(exporter=ConsoleSpanExporter())

If these steps do not resolve the issue, it might be necessary to continue using manual instrumentation as a workaround until the automatic instrumentation is fixed or updated in the SDK.

To continue talking to Dosu, mention @dosu.

@nirga
Copy link
Member

nirga commented Nov 9, 2024

@coffecup25 sorry for taking too long here - fix is on the way!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants