self-hosted
self-hosted copied to clipboard
OpenAI Integration not working
Environment
self-hosted (https://develop.sentry.dev/self-hosted/)
Steps to Reproduce
- Enable OpenAI in sentry.conf.py
- Add the API Key in docker-compose.yml
- Restart sentry
Expected Result
When I click on an issue and click on View Suggestion, I expect to see the AI suggestion
Actual Result
I get "There was an error loading data."
Product Area
Issues - Suggested Fix
Link
No response
DSN
No response
Version
23.7.2
Assigning to @getsentry/support for routing ⏲️
Routing to @getsentry/product-owners-settings-integrations for triage ⏲️
@chadwhitacre I think this is related to Self Hosted Sentry
Looks like it, transferring repos. 👍
Thanks for writing in, can you check your web
container logs to see if there's anything that might help us debug this issue?
The API just returns a 404, logs:
15:40:19 [INFO] sentry.superuser: superuser.request (url='http://sentry.example.org/api/0/projects/foo/bar/events/df7a2e88b4c54f279986890e81f42984/ai-fix-suggest/' method='GET' ip_address='<redacted>' user_id=1)
15:40:19 [INFO] sentry.superuser: superuser.superuser_access (superuser_token_id='HFaZifMymgWB' user_id=1 user_email='[email protected]' su_org_accessed='human')
15:40:19 [INFO] sentry.access.api: api.access (method='GET' view='sentry.api.endpoints.event_ai_suggested_fix.EventAiSuggestedFixEndpoint' response=404 user_id='1' is_app='None' token_type='None' is_frontend_request='True' organization_id='1' auth_id='None' path='/api/0/projects/foo/bar/events/df7a2e88b4c54f279986890e81f42984/ai-fix-suggest/' caller_ip='<redacted>' user_agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.203' rate_limited='False' rate_limit_category='None' request_duration_seconds=0.07407927513122559 rate_limit_type='DNE' concurrent_limit='None' concurrent_requests='None' reset_time='None' group='None' limit='None' remaining='None')
15:40:19 [WARNING] django.request: Not Found: /api/0/projects/foo/bar/events/df7a2e88b4c54f279986890e81f42984/ai-fix-suggest/ (status_code=404 request=<WSGIRequest: GET '/api/0/projects/foo/bar/events/df7a2e88b4c54f279986890e81f42984/ai-fix-suggest/'>)
172.19.0.1 - - [14/Aug/2023:15:40:19 +0000] "GET /api/0/projects/foo/bar/events/df7a2e88b4c54f279986890e81f42984/ai-fix-suggest/ HTTP/1.0" 404 50 "https://sentry.example.org/organizations/human/issues/350/?query=is%3Aunresolved&referrer=issue-stream&stream_index=2" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.203" "<redacted>, <redacted>"
Does api requests to /api/0/projects/foo/bar/events/df7a2e88b4c54f279986890e81f42984/
work?
Yes, requests to that endpoint work correctly. It's only the /ai-fix-suggest endpoint that returns resource not found.
Got it, this does appear to work in SaaS so it looks like it is potentially a self-hosted specific issue
I can confirm same happening on my end on 23.8.0
thanks for reporting this folks, will backlog this item for now
This can easily be fixed:
# .env / .env.custom
# ...
OPENAI_API_KEY=your-key
# sentry/sentry.conf.py
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
SENTRY_FEATURES["organizations:open-ai-suggestion"] = True
Don't forget to restart the container, e.g.:
docker compose --env-file .env.custom restart web
Hi, @Fumaz @fliespl just checking in, is this still broken on your end? If so, what version of self-hosted are you on?
Still broken on 24.1.0
@meenzen I'm trying to debug / find the root cause at Discord, jump there if you want to: https://discord.com/channels/621778831602221064/796028405833007104/1197108363021013053
Okay so, @meenzen @fliespl @Fumaz, can you try this out please?
On this section, add OPENAI_API_KEY = env("OPENAI_API_KEY", "")
https://github.com/getsentry/self-hosted/blob/800e6f51a139caf444783f9d788c3447e00205c6/sentry/sentry.conf.example.py#L310-L320
Your sentry/sentry.conf.py
should look like this:
##############################################
# Suggested Fix Feature / OpenAI Integration #
##############################################
# See https://docs.sentry.io/product/issues/issue-details/ai-suggested-solution/
# for more information about the feature. Make sure the OpenAI's privacy policy is
# aligned with your company.
# Set the feature to be True if you'd like to enable Suggested Fix. You'll also need to
# add your OPENAI_API_KEY to the docker-compose.yml file.
SENTRY_FEATURES["organizations:open-ai-suggestion"] = True
OPENAI_API_KEY = env("OPENAI_API_KEY", "")
Let me know if that works.
@aldy505 still same problem on my end: https://ss.codeone.pl/ss-2024-01-18-08-35-59-1705563359-wjRivs1X.png using 24.1.0
sentry.conf.py
#OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
SENTRY_FEATURES["organizations:open-ai-suggestion"] = True
OPENAI_API_KEY = env("OPENAI_API_KEY", "")
@fliespl Oh forgot one thing, after you modify your sentry/sentry.conf.py
you'll need to do sudo ./install.sh
again.
@aldy505 I did. I was updating to 24.1.0 during the process so full rebuild went through.
@fliespl Are you adding OPENAI_API_KEY
to your .env file?
@hubertdeng123 of course.
root@sentry:/opt/self-hosted# cat .env.custom
COMPOSE_PROJECT_NAME=sentry-self-hosted
SENTRY_EVENT_RETENTION_DAYS=90
# You can either use a port number or an IP:PORT combo for SENTRY_BIND
# See https://docs.docker.com/compose/compose-file/#ports for more
SENTRY_BIND=9000
# Set SENTRY_MAIL_HOST to a valid FQDN (host/domain name) to be able to send emails!
# SENTRY_MAIL_HOST=example.com
SENTRY_IMAGE=getsentry/sentry:24.1.0
SNUBA_IMAGE=getsentry/snuba:24.1.0
RELAY_IMAGE=getsentry/relay:24.1.0
SYMBOLICATOR_IMAGE=getsentry/symbolicator:24.1.0
VROOM_IMAGE=getsentry/vroom:24.1.0
WAL2JSON_VERSION=latest
HEALTHCHECK_INTERVAL=30s
HEALTHCHECK_TIMEOUT=1m30s
HEALTHCHECK_RETRIES=10
SENTRY_MAX_EXTERNAL_SOURCEMAP_SIZE=32M
OPENAI_API_KEY=sk-XitkC*****
Just running through options here, but when you hit the OpenAI API with that exact key manually, it works?
Assuming that is the case, this is likely an install issue. Maybe worth re-running ./install.sh
(again)? You can also check /src/sentry/api/urls.py
to see if ai-fix-suggest
shows up - if it does not, you are (somehow) still on an old version.
I tested it today with Sentry 24.2.0.dev0 (customization sentry.conf.py => set to True and added OpenAI Key to the .env file.... nevertheless I get the message in the log that the endpoint is unknown 404.
web-1 | 19:52:56 [INFO] sentry.superuser: superuser.request (url='http://sentry.domain.local/api/0/projects/myProject/myProjectName/events/5603f0bfcfd44c83bcb818d6b3e7d998/ai-fix-suggest/' method='GET' ip_address='46.555.666.56' user_id=1)
web-1 | 19:52:56 [INFO] sentry.superuser: superuser.superuser_access (superuser_token_id='bUWKvIzktovW' user_id=1 user_email='[email protected]' su_org_accessed='myProject')
web-1 | 19:52:56 [INFO] sentry.access.api: api.access (method='GET' view='sentry.api.endpoints.event_ai_suggested_fix.EventAiSuggestedFixEndpoint' response=404 user_id='1' is_app='False' token_type='None' is_frontend_request='True' organization_id='3' auth_id='None' path='/api/0/projects/myProject/myProjectName/events/5603f0bfcfd44c83bcb818d6b3e7d998/ai-fix-suggest/' caller_ip='46.555.666.56' user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' rate_limited='False' rate_limit_category='None' request_duration_seconds=0.03199362754821777 rate_limit_type='DNE' concurrent_limit='None' concurrent_requests='None' reset_time='None' group='None' limit='None' remaining='None')
web-1 | 19:52:56 [WARNING] django.request: Not Found: /api/0/projects/myProject/myProjectName/events/5603f0bfcfd44c83bcb818d6b3e7d998/ai-fix-suggest/ (status_code=404 request=<WSGIRequest: GET '/api/0/projects/myProject/myProjectName/events/5603f0bfcfd44c83bcb818d6b3e7d998/ai-fix-suggest/'>)
nginx-1 | 172.18.0.1 - - [02/Feb/2024:19:52:56 +0000] "GET /api/0/projects/myProject/myProjectName/events/5603f0bfcfd44c83bcb818d6b3e7d998/ai-fix-suggest/ HTTP/1.1" 404 50 "https://sentry.domain.local/organizations/myProject/issues/188/?query=is%3Aunresolved&referrer=issue-stream&statsPeriod=14d&stream_index=0" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" "46.555.666.56"
Hi @DannySotzny, after you customize your sentry.conf.py
and .env
files, did you do ./install.sh
again? Two reasons that the API returns 404 code is:
-
OPENAI_API_KEY
is falsy in python (empty string,None
) https://github.com/getsentry/sentry/blob/1f687b72bf714e6a8aa9033a7d80b3a7e7401a98/src/sentry/api/endpoints/event_ai_suggested_fix.py#L320-L322 - The error event does not exists https://github.com/getsentry/sentry/blob/1f687b72bf714e6a8aa9033a7d80b3a7e7401a98/src/sentry/api/endpoints/event_ai_suggested_fix.py#L324-L326
If by any chance you haven't execute ./install.sh
after modifying your configuration files, please do that first.
I just installed the self hosted last week and run into the same issue. I do have the OPENAI_API_KEY set in .env and also in sentry.conf.py. I also did run install.sh afterwards again. The event does exist. Why does it not work?
Now it works, thanks to @buffcode
The missing was
# sentry/sentry.conf.py
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
SENTRY_FEATURES["organizations:open-ai-suggestion"] = True
it's confusing, because it's not written in the comment on entry/sentry.conf.py. So to make it work you need the key in the .env and add the entry in the conf (including turning on of course)
How can we enable this in helm config of self hosted sentry, i added the openAI API key to openai.existingSecretKey parameter in values.yaml of helm chart and it does not work.
openai: #existingSecret: "" existingSecretKey: "sk-*******" # by default "api-token"
Below isn the error in sentry-web container logs
14:02:52 [WARNING] django.request: Not Found: /api/0/projects/abc/internal/events/
@prashant-prodigal You should ask the helm chart maintainers. We don't provide support for that in this repo. Good luck! :-)
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community
, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀