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 function #9

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/satellite_consumer/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"""

import datetime as dt
import os
from importlib.metadata import PackageNotFoundError, version

from dotenv import load_dotenv
import sentry_sdk
import eumdac.product
from joblib import Parallel, delayed
from loguru import logger as log
Expand All @@ -23,11 +26,29 @@
from satellite_consumer.storage import create_empty_zarr, create_latest_zip, get_fs, write_to_zarr
from satellite_consumer.validate import validate

# Load environment variables from .env file
load_dotenv()
Copy link
Contributor

@devsjc devsjc Mar 7, 2025

Choose a reason for hiding this comment

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

Not sure what the necessity of this is? The env vars are pulled from the environment, not a .env file. I think the os.getenv calls should work as they are without this!

Copy link
Author

@lambaaryan011 lambaaryan011 Mar 7, 2025

Choose a reason for hiding this comment

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

@devsjc "I’m using a .env file for local development to load SENTRY_DSN via load_dotenv(). This makes it easier to manage sensitive configuration locally. In production, environment variables are set externally, so the .env file isn’t needed."


# Get Sentry DSN from environment variables
SENTRY_DSN = os.getenv("SENTRY_DSN")

# Initialize Sentry if DSN is available
if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN, # Using .env variable
traces_sample_rate=1.0,
environment="production"
)
log.info("✅ Sentry initialized successfully!")
else:
log.warning("⚠️ SENTRY_DSN is not set. Sentry will not be initialized.")

try:
__version__ = version("satellite-consumer")
except PackageNotFoundError:
__version__ = "v?"


def _consume_command(command_opts: ArchiveCommandOptions | ConsumeCommandOptions) -> None:
"""Run the download and processing pipeline."""
fs = get_fs(path=command_opts.zarr_path)
Expand Down Expand Up @@ -79,7 +100,8 @@ def _etl(product: eumdac.product.Product) -> str:
f"Deleting {len(nat_filepaths)} raw files in {command_opts.raw_folder}",
num_files=len(nat_filepaths), dst=command_opts.raw_folder,
)
_ = [f.unlink() for f in nat_filepaths] # type:ignore
for f in nat_filepaths:
f.unlink() # type: ignore # Removed unnecessary list comprehension


def run(config: SatelliteConsumerConfig) -> None:
Expand Down