Skip to content

fix: pass auth_instance to sentry middleware#330

Merged
suvanbanerjee merged 4 commits into
mainfrom
fix/sentry-email
Jun 26, 2026
Merged

fix: pass auth_instance to sentry middleware#330
suvanbanerjee merged 4 commits into
mainfrom
fix/sentry-email

Conversation

@suvanbanerjee

Copy link
Copy Markdown
Member

Pull Request

Description

Sentry was only showing client IP addresses and was not logging user email information because the auth instance was not being passed through.

Fixes #329

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

@suvanbanerjee suvanbanerjee requested a review from braddf June 19, 2026 04:26
@suvanbanerjee suvanbanerjee self-assigned this Jun 19, 2026
@suvanbanerjee

Copy link
Copy Markdown
Member Author

@braddf I decoded the current JWT and these are the fields present:

{
  "trial_ends_at": "...",
  "https://openclimatefix.org/email": "...",
  "iss": "https://nowcasting-pro.eu.auth0.com/",
  "sub": "google-oauth2|10...34",
  "aud": [
    "https://api.nowcasting.io/",
    "https://nowcasting-pro.eu.auth0.com/userinfo"
  ],
  "iat": 1781842439,
  "exp": 1782706439,
  "scope": "openid profile email offline_access",
  "azp": "...",
  "permissions": [
    "read:trial"
  ]
}

When we add the organization_id, what key should we use to store it in the JWT?

I can also add it to the Sentry middleware so it gets attached to Sentry events.

@braddf

braddf commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@suvanbanerjee the org id should be stored/fetched already here:

https://github.com/openclimatefix/quartz-api/blob/main/src/quartz_api/internal/middleware/auth.py#L120

So you can use that key too

"email": payload.get(auth.EMAIL_KEY),
},
)
org_id = get_org_id_from_authdata(payload)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't worry about organization I'd, just ignore that

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if the email is there, thats fine

@suvanbanerjee

Copy link
Copy Markdown
Member Author

@suvanbanerjee the org id should be stored/fetched already here:

https://github.com/openclimatefix/quartz-api/blob/main/src/quartz_api/internal/middleware/auth.py#L120

So you can use that key too

I used the get_org_id_from_authdata function rather than accessing app_metadata["hubspot_id"] directly. That way, if the underlying key ever changes in the future, we only need to update it in one place instead of everywhere it's used.

@suvanbanerjee suvanbanerjee merged commit 4cc5576 into main Jun 26, 2026
8 checks passed
@suvanbanerjee suvanbanerjee deleted the fix/sentry-email branch June 26, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add user name to sentry logs

3 participants