Setup Bitbucket Integration

I am finishing setting up our sentry on premise server and I am having difficulty getting bit bucket integration to work. I’m assuming its a configuration error on my part so here is what I have.

I set the bitbucket env varaibles
BITBUCKET_CONSUMER_KEY = “secret-key”
BITBUCKET_CONSUMER_SECRET = “secret”

I made sure that the system.url-prefix is set correctly.

Set these permissions in bitbucket.
image

On bitbucket auth page everything looks fine.

When I click on grant access I get a HTTP ERROR 405 before the popup window closes.

In the sentry internal project I see a couple errors for it
https://sentry.wallsmetalroofing.com/share/issue/1d751b844a43460bb246ea1be5258a61/

The server in question is running centos 7 with docker 19.03.2 and python 2.7.16.

Is there anything else that I am missing as to why I can’t integrate with bitbucket? I am not hosting the bitbucket instance…

Trying some more stuff…

I tried the bitbucket varaibles in the sentry.conf.py file, in the .env file and neither made a difference. Then I tried a incorrect value in both the key and secret and the same result. So where should I be putting those values. It seems as if the values don’t matter or aren’t being used.

1 Like

Hi @trevor! Can you provide more details about your setup, such as which version of Sentry you are using and what type of installation is it (docker-compose based from our onpremise repo, pip based custom, or something else?)

Also our docs mention some admin permissions both on Sentry and Bitbucket side: https://docs.sentry.io/workflow/integrations/global-integrations/#bitbucket - maybe you should try granting those too first?

1 Like

Hi @BYK. Thanks for your reply. So I went and ran the install.sh file again in the on premise repo. In the logs this was the current version
$SENTRY_IMAGE not set, using latest stable: sentry:9.1.2
and I am using the docker-compose. Both the sentry and bitbucket accounts are owners.

Full install log here https://pastebin.com/mBp80Db1

I retried to add the bitbucket integration and I got 1 screen further. It asked me to enable my developer account for the integration. After doing that it error-ed out with a 405 again.

1 Like

So two things:

Please share the logs from sentry_web when you get the 405 and also make sure you rebuild (reinstall via install.sh) every time you make changes to sentry.conf.py file.

Also it is not clear to me which side is giving the HTTP 405 error: Sentry or Bitbucket? If it is Sentry, then the only place this can happen is https://github.com/getsentry/sentry-plugins/blob/19735273a60afc228573c676cddbf432750beedb/src/sentry_plugins/bitbucket/endpoints/webhook.py#L117-L120 which means for some reason, Bitbucket is not POSTing the response. If it is the Bitbucket side, this may indicate a bug in the plugin.

1 Like

Is these the logs that you were looking for? And in case you are curious I am using ngrok for my proxy.

172.19.0.1 - - [16/Oct/2019:11:49:19 +0000] “GET /api/0/organizations/walls-metal-roofing/config/integrations/ HTTP/1.0” 200 13903 “Sign In | Sentry” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36”
172.19.0.1 - - [16/Oct/2019:11:49:19 +0000] “GET /api/0/organizations/walls-metal-roofing/repos/?status=unmigratable HTTP/1.0” 200 765 “Sign In | Sentry” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36”
172.19.0.1 - - [16/Oct/2019:11:49:24 +0000] “GET /organizations/walls-metal-roofing/integrations/bitbucket/setup/? HTTP/1.0” 302 862 “Sign In | Sentry” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36”
172.19.0.1 - - [16/Oct/2019:11:49:30 +0000] “GET /extensions/bitbucket/descriptor/ HTTP/1.0” 200 800 “-” “python-requests/2.19.1”
172.19.0.1 - - [16/Oct/2019:11:49:45 +0000] “GET /extensions/bitbucket/descriptor/ HTTP/1.0” 200 800 “-” “python-requests/2.19.1”
Traceback (most recent call last):
File “/usr/local/lib/python2.7/site-packages/sentry/api/base.py”, line 90, in handle_exception
response = super(Endpoint, self).handle_exception(exc)
File “/usr/local/lib/python2.7/site-packages/sentry/api/base.py”, line 190, in dispatch
response = handler(request, *args, **kwargs)
File “/usr/local/lib/python2.7/site-packages/sentry/integrations/bitbucket/installed.py”, line 22, in post
data = BitbucketIntegrationProvider().build_integration(state)
File “/usr/local/lib/python2.7/site-packages/sentry/integrations/bitbucket/integration.py”, line 176, in build_integration
‘name’: principal_data[‘username’],
KeyError: ‘username’
172.19.0.1 - - [16/Oct/2019:11:49:45 +0000] “POST /extensions/bitbucket/installed/ HTTP/1.0” 500 329 “-” “python-requests/2.19.1”
172.19.0.1 - - [16/Oct/2019:11:49:46 +0000] “POST /extensions/bitbucket/uninstalled/ HTTP/1.0” 400 211 “-” “python-requests/2.19.1”
172.19.0.1 - - [16/Oct/2019:11:49:46 +0000] “GET /api/0/broadcasts/ HTTP/1.0” 200 511 “Sign In | Sentry” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36”

And as far as where the error happens… Its on the bitbucket page after making a request to sentry.

This is the error that the internal Project gives me. Sentry With additional body details.

{
baseApiUrl: https://api.bitbucket.org,
baseUrl: https://bitbucket.org,
clientKey: connection: 3687935,
eventType: installed,
key: sentry.wallsmetalroofing.com.bitbucket,
principal: {
account_id: …,
account_status: active,
created_on: 2018-05-11T15:02:26.970547+00: 00,
display_name: Trevor …,
has_2fa_enabled: True,
is_staff: False,
links: {},
nickname: …,
properties: {},
type: user,
uuid: { … }
},
productType: bitbucket,
publicKey: …/…/…,
sharedSecret: [ Filtered ],
user: {
account_id: …,
account_status: active,
created_on: 2018-05-11T15:02: 26.970547+00:00,
display_name: Trevor …,
has_2fa_enabled: True,
is_staff: False,
links: {},
nickname: …,
properties: {},
type: user,
uuid: { … }
}
}

As far as install goes. I simply rerun the install.sh every time I change any of the config files.

@trevor, thanks a lot for providing all this info! I’ve finally found the issue, it is a bug in our Bitbucket integration :smiley:

Good news is it is fixed, bad news is the fix is not on 9.1.2 :frowning:

From the pull request, it sounds like this happens on accounts with hidden usernames. Right now, as a workaround, I think you can unhide your username, finish the setup and hide it again. Or if you feel adventurous, you can try our experimental v10 branch which is based off of latest master.

1 Like

Yea I wish that trick still worked. The only thing that I had hidden was my email. I made that public as well and still the same thing. I have a feeling that bitbucket made some changes recently as well.

Anyway… I guess it’s time to get fluent with building docker images and installing them. :laughing: I’ll definetly get a test server and try to get the v10 setup. I was debating on doing that previously but this just pushed me over that edge.

Thanks for your help @BYK

1 Like

Well, you don’t need much fluency: feat(sentry10): Make on-premise work for Sentry 10 by BYK · Pull Request #220 · getsentry/self-hosted · GitHub

Just use that v10 branch and run ./install.sh in there. The latest sentry image on Docker Hub, getsentry/sentry:latest is not too recent but it is not too old either. If you want a more recent one, see Uploading Source Files with Debug Information - #14 by BYK

I just merged build(gcr): Move to Google Cloud Build from Docker Hub autobui… by BYK · Pull Request #15116 · getsentry/sentry · GitHub so you should be able to do SENTRY_IMAGE=us.gcr.io/sentryio/sentry:latest for some time.

1 Like

Do Sentry 9 and 10 have the same requirements towards Redis, Postgres etc.?
I would like to test the Bitbucket integration in my on-premise setting too :slight_smile:

Can you be more specific?

Hi @BYK, if I would upgrade from Sentry 9 to 10, do I have to update the versions of my self-hosted (on-premise) Postgres and Redis instances too? I cannot find any requirements that state versions for that, but I guess I could figure it out from the docker-compose file.

@lkreimann - we recommend upgrading to Postgres 9.6 and started doing that in the install script automatically now. I don’t think that’s a hard requirement though. Same for redis, I don’t think there’s an upgrade requirement. Pinging @matt for the definite answer though.

1 Like

I’d just suggest whatever latest Redis is atm. We don’t track well which features we use. And yes to Postgres 9.6.

1 Like

Thanks @matt @BYK! That helps a lot :slight_smile:

1 Like