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

Add Sentry logs to all backend components #540

Open
peterdudfield opened this issue May 8, 2024 · 10 comments
Open

Add Sentry logs to all backend components #540

peterdudfield opened this issue May 8, 2024 · 10 comments
Assignees

Comments

@peterdudfield
Copy link
Contributor

peterdudfield commented May 8, 2024

Detailed Description

It would be great to have sentry logs in all back end components

Context

  • good to have logs all going to one palce

Possible Implementation

SImilar to the api

https://github.com/openclimatefix/pv-site-api/blob/main/pv_site_api/main.py#L89C1-L93C2

def traces_sampler(sampling_context):
    """
    Filter tracing for sentry logs.

    Examine provided context data (including parent decision, if any)
    along with anything in the global namespace to compute the sample rate
    or sampling decision for this transaction
    """

    if os.getenv("ENVIRONMENT") == "local":
        return 0.0
    elif "error" in sampling_context["transaction_context"]["name"]:
        # These are important - take a big sample
        return 1.0
    elif sampling_context["parent_sampled"] is True:
        # These aren't something worth tracking - drop all transactions like this
        return 0.0
    else:
        # Default sample rate
        return 0.05

sentry_sdk.init(
    dsn=os.getenv("SENTRY_DSN"),
    environment=os.getenv("ENVIRONMENT", "local"),
    traces_sampler=traces_sampler,
)

this bit of code needs to sit at the start of the main app, and sentry_sdk be added to the requirements file

  • add SENTRY_DSN into infrastructure code, and ENVIRONMENT
component code ready dev pro
GSP Consumer yes 1.1.19 yes yes
NWP Consumer yes 0.5.28 yes
Satellite Consumer yes 2.12.8 yes yes
uk-pvnet-app yes yes 2.4.1 Not working
pvnet app DA yes yes 2.4.1 Not working
National xg yes 1.0.38 yes yes
forecast sites yes 1.0.10 yes yes
blend yes yes 1.0.2 yes
Metrics yes 1.2.21 yes yes
UK GPS api yes yes yes
UK sites api yes yes yes
India api yes 1.0.41 yes yes
india ruvnl consumer 0.1.12 yes yes yes
india forecast yes TODO add version and name yes yes
india satellite yes 2.12.8 yes yes
india nwp yes 0.5.28 yes
PVConsumer yes yes 2.1.0
@peterdudfield peterdudfield added enhancement New feature or request good first issue Good for newcomers and removed enhancement New feature or request labels May 8, 2024
@peterdudfield
Copy link
Contributor Author

@braddf I've put this here, as other people might be able to contribute to this

@peterdudfield
Copy link
Contributor Author

Ive tested the above code in the india-forecast-app, so it can be rolled out to other repos now

@Plomo-02
Copy link

hello, can I be assigned to this issue?

@Plomo-02
Copy link

Plomo-02 commented Jun 4, 2024

@peterdudfield can I have more info about the sentry_sdk version repos need?

@peterdudfield
Copy link
Contributor Author

what do you mean version?

https://github.com/openclimatefix/india-forecast-app/pull/75/files this is a good example of what would be great to do to the other repos

@peterdudfield
Copy link
Contributor Author

for GSPConumer - openclimatefix/GSPConsumer#76

@peterdudfield
Copy link
Contributor Author

openclimatefix/Satip#280

@peterdudfield
Copy link
Contributor Author

Here's a good example - openclimatefix/uk-pvnet-app#125

@peterdudfield
Copy link
Contributor Author

A nice simple way to do this is (this should be put in the main app)

import sentry_sdk
import os

sentry_sdk.init(
    dsn=os.getenv("SENTRY_DSN", ""),
    environment=f'{os.getenv("ENVIRONMENT", "local")}',
    traces_sample_rate=1.0,
    profiles_sample_rate=1.0,
)
sentry_sdk.set_tag("app_name", APP_NAME)
sentry_sdk.set_tag("version", VERSION)

@peterdudfield
Copy link
Contributor Author

Currently deployed on uk-pvnet-app on development, but errors not showing up in sentry. Weird

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

No branches or pull requests

3 participants