Skip to content

[WIP] feat: added telemetry for pinecone DB#39

Merged
nirga merged 20 commits intotraceloop:mainfrom
kartikay-bagla:main
Jan 30, 2024
Merged

[WIP] feat: added telemetry for pinecone DB#39
nirga merged 20 commits intotraceloop:mainfrom
kartikay-bagla:main

Conversation

@kartikay-bagla
Copy link
Copy Markdown
Contributor

@kartikay-bagla kartikay-bagla commented Jan 23, 2024

Fixes #32.

This is my first foray into NodeJS and its ecosystem so I'm a little unsure about a couple of things:

  • How do I run tests?
  • How do I run the sample app to check if everything is looking good? Sample app is working now :)
  • I have marked a few places in the code where I'm unsure if I need to change code
  • Any general feedback on style/formatting/prose would be very appreciated!

@quest-bot loot #32

@quest-bot quest-bot bot mentioned this pull request Jan 23, 2024
1 task
@quest-bot quest-bot bot added the ⚔️ Quest Tracks quest-bot quests label Jan 23, 2024
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 23, 2024

CLA assistant check
All committers have signed the CLA.

@quest-bot
Copy link
Copy Markdown

quest-bot bot commented Jan 23, 2024

Quest PR submitted! image Quest PR submitted!

@kartikay-bagla You are attempting to solve the issue and loot this Quest. Will you be successful?


Questions? Check out the docs.

@nirga
Copy link
Copy Markdown
Member

nirga commented Jan 24, 2024

Thanks @kartikay-bagla
Looking into your code now.
Running the tests is easy using nx (https://www.traceloop.com/docs/openllmetry/contributing/developing#basic-guide-for-using-nx) - nx run-many -t test

@nirga
Copy link
Copy Markdown
Member

nirga commented Jan 24, 2024

One comment about the test - I'd test it similarly to how we did it in Python (i.e. - instead of made-up vectors).

@kartikay-bagla
Copy link
Copy Markdown
Contributor Author

One comment about the test - I'd test it similarly to how we did it in Python (i.e. - instead of made-up vectors).

I thought since we're specifically testing the tracing with pinecone, it would be better to reduce dependency on other things.

@nirga
Copy link
Copy Markdown
Member

nirga commented Jan 24, 2024

One comment about the test - I'd test it similarly to how we did it in Python (i.e. - instead of made-up vectors).

I thought since we're specifically testing the tracing with pinecone, it would be better to reduce dependency on other things.

Yeah that also makes sense so I'm fine with that. There's always the tension between writing integration tests and unit tests. We chose the integration test path since they catch more bugs easily (specifically in the LLM domain where the library maintainers have a tendency to break APIs all the time), but they are harder to run locally and in CI.
So I'm also fine with us having more easy to run unit tests :)

BTW we have an effort on the Python SDK to instrument the vectors themselves so might worth doing it here as well.

@kartikay-bagla
Copy link
Copy Markdown
Contributor Author

kartikay-bagla commented Jan 24, 2024

BTW we have an effort on the Python SDK to instrument the vectors themselves so might worth doing it here as well.

I'm sorry but I'm not exactly clear on what "instrumenting the vectors" mean.

Also, I was able to get the unit tests working :)

provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
instrumentation = new PineconeInstrumentation();
instrumentation.setTracerProvider(provider);
instrumentation.manuallyInstrument(pc_module);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@nirga I'm not sure why but I need to call manuallyInstrument because otherwise the wrappers are not working. Could you help me debug this?

To replicate this, you can comment out line 42 here and try running the tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kartikay-bagla you need to initialize the instrumentation in the SDK, here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Already did that, check here and here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And it still doesn't work for you without manually instrument?

Copy link
Copy Markdown
Contributor Author

@kartikay-bagla kartikay-bagla Jan 28, 2024

Choose a reason for hiding this comment

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

yep, I need to call it manually (while running the sample app or the tests).

@nirga
Copy link
Copy Markdown
Member

nirga commented Jan 25, 2024

BTW we have an effort on the Python SDK to instrument the vectors themselves so might worth doing it here as well.

I'm sorry but I'm not exactly clear on what "instrumenting the vectors" mean.

Also, I was able to get the unit tests working :)

Check out this PR. Basically it's sending as span events the vectors you get in response when calling Pinecone's query method.

@kartikay-bagla
Copy link
Copy Markdown
Contributor Author

@nirga I have added span events as well!.

@nirga
Copy link
Copy Markdown
Member

nirga commented Jan 28, 2024

Thanks @kartikay-bagla! Let me know when it's ready for review and I'll do a full check up :)

@kartikay-bagla
Copy link
Copy Markdown
Contributor Author

kartikay-bagla commented Jan 28, 2024

Thanks @kartikay-bagla! Let me know when it's ready for review and I'll do a full check up :)

@nirga apart from needing to call manuallyInstrument, everything else is good to go.

@nirga
Copy link
Copy Markdown
Member

nirga commented Jan 29, 2024

@kartikay-bagla I suspect that the auto-instrumentation is not working well since it can't find the module automatically. We encountered some similar issues in the langchain instrumentation, see the solution @Kartik1397 came up with there -

protected init(): InstrumentationModuleDefinition<any>[] {

@kartikay-bagla
Copy link
Copy Markdown
Contributor Author

@kartikay-bagla I suspect that the auto-instrumentation is not working well since it can't find the module automatically. We encountered some similar issues in the langchain instrumentation, see the solution @Kartik1397 came up with there -

protected init(): InstrumentationModuleDefinition<any>[] {

I think that fixes it! Sample app is now working as well!

@nirga you can do a full review now.

@kartikay-bagla kartikay-bagla marked this pull request as ready for review January 29, 2024 19:42
@nirga
Copy link
Copy Markdown
Member

nirga commented Jan 29, 2024

Looks good overall @kartikay-bagla! Can we just align the semantic conventions to the ones we have in Python, and add them to the ai-semantic-conventions package?

Also, I see the test is failing with 404... Does it also happen to you locally?

@kartikay-bagla
Copy link
Copy Markdown
Contributor Author

Also, I see the test is failing with 404... Does it also happen to you locally?

The 404 could happen due to a missing API key for pinecone. You need to add it to the environment as PINECONE_API_KEY

@nirga
Copy link
Copy Markdown
Member

nirga commented Jan 30, 2024

The API key was there, the problem was with the configuration we had in Pinecone :/
I've fixed that now but I see the build is failing as you're missing dependency on ai semantic conventions in the pinecone instrumentation. Also, when I ran the tests locally I get an error:

 1 failing
  1) Test Pinecone instrumentation
       should set attributes in span for DB query:
      AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
2 !== 8

      + expected - actual
      -2
      +8
      
      at Context.<anonymous> (test/instrumentation.test.ts:127:12)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

(BTW the build and test here fails automatically on your commits due to some Github limitation that doesn't allow outside contributors to use our secrets for running the tests and I'm triggering it manually everytime. So it should pass if the tests work and I trigger them).

@kartikay-bagla
Copy link
Copy Markdown
Contributor Author

Fixed package.json issue.

And I have attributed the test error to just not waiting long enough for pinecone to update. I tried running the tests locally about 100 times, it sometimes failed like yours did. Added a 30 second wait time before querying any freshly inserted datam and that seemed to fix the issue!

@nirga nirga merged commit 4f1ba2a into traceloop:main Jan 30, 2024
@quest-bot
Copy link
Copy Markdown

quest-bot bot commented Jan 30, 2024

🧚 @kartikay-bagla congratulations for completing Quest #32

💰 A reward of $100 has been credited to you.

To claim your $100 reward follow the instructions here.

Questions? Check out the docs.

5war00p pushed a commit to 5war00p/openllmetry-js that referenced this pull request Feb 4, 2024
Co-authored-by: Nir Gazit <nirga@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚔️ Quest Tracks quest-bot quests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 Feature: Pinecone Instrumentation

3 participants