Skip to content

Commit

Permalink
Merge pull request #2 from rsmith013/config
Browse files Browse the repository at this point in the history
Config
  • Loading branch information
rsmith013 authored Jan 31, 2023
2 parents 6e0726b + fb005c1 commit cf38f39
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
rev: 22.12.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/PyCQA/flake8
rev: 3.8.2
hooks:
- id: flake8
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![PyPI version](https://badge.fury.io/py/metaflow-sentry-logger.svg)](https://badge.fury.io/py/metaflow-sentry-logger)

# Sentry Logging Plugin for Metaflow

Enabling the use of [Sentry](https://sentry.io/) with [Metaflow](https://metaflow.org/)
Expand Down Expand Up @@ -33,10 +35,10 @@ The sentry plugin can be called using either the `--with sentry` command line ar

Only basic configuration is currently supported using environment variables.

| Envrionment Variable | Description | Required |
| -------------------- | ------------------------------------------------- | -------- |
| `SENTRY_DSN` | The DSN for the target sentry project | `True` |
| `METAFLOW_PROFILE` | Used by this plugin to determine the environment. | `False` |
| Name | Description | Required | Location |
| --------------------- | ------------------------------------------------- | -------- | ---------------------------------------- |
| `METAFLOW_SENTRY_DSN` | The DSN for the target sentry project | `True` | `Environment Variable` `Metaflow Config` |
| `METAFLOW_PROFILE` | Used by this plugin to determine the environment. | `False` | `Environment Variable` |

## Examples

Expand Down
11 changes: 11 additions & 0 deletions metaflow_extensions/sentry/config/metaflow_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Metaflow configuration over-rides.
Use `metaflow.from_conf` to set values with the following prioritisation
order: 1) System environment variable 2) Your Metaflow profile (JSON
config) 3) The value passed to `from_conf`
"""
from metaflow.metaflow_config import from_conf

# Path to the client cache
SENTRY_DSN = from_conf("SENTRY_DSN", None)
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import sentry_sdk
from metaflow import decorators
from metaflow_extensions.sentry.config.metaflow_config import SENTRY_DSN

logger = logging.getLogger(__name__)

Expand All @@ -11,6 +12,16 @@ class SentryLoggingStepDecorator(decorators.StepDecorator):

name = "sentry"

def step_init(
self, flow, graph, step_name, decorators, environment, flow_datastore, logger
):
if not SENTRY_DSN:
msg = (
"You have requested the sentry logging decorator "
"without setting the METAFLOW_SENTRY_DSN configuration value."
)
raise ValueError(msg)

def task_pre_step(
self,
step_name,
Expand All @@ -25,15 +36,9 @@ def task_pre_step(
ubf_context,
inputs,
):
if not (sentry_dsn := os.environ.get("SENTRY_DSN")):
msg = (
"You have requested the sentry logging decorator "
"without setting SENTRY_DSN environment variable"
)
raise ValueError(msg)

sentry_sdk.init(
dsn=sentry_dsn,
dsn=SENTRY_DSN,
environment=os.environ.get("METAFLOW_PROFILE"),
)

Expand Down
2 changes: 1 addition & 1 deletion metaflow_extensions/sentry/toplevel/sentry_toplevel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__mf_extensions__ = "sentry"

__version__ = None
__version__ = "0.2.0"
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "metaflow-sentry-logger"
version= "0.1.0"
version = "0.2.0"
description="Sentry logging plugins for Metaflow (metaflow.org)"
readme="README.md"
authors=[{name = "Richard Smith"}]
Expand All @@ -30,7 +30,7 @@ metaflow_extensions = "metaflow_extensions"
Homepage = "https://github.com/rsmith013/metaflow-sentry-logger"

[tool.bumpver]
current_version = "0.1.0"
current_version = "0.2.0"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "Bump version {old_version} -> {new_version}"
commit = true
Expand Down

0 comments on commit cf38f39

Please sign in to comment.