An AWS approved version of https://github.com/TeoZosa/structlog-sentry-logger which is compatible with AWS Lambda as well as AWS Fargate
Project description
structlog-sentry-lambda
Description
This repository is a fork of https://github.com/TeoZosa/structlog-sentry-logger and all credits for this solution should go to @TeoZosa !!!
Use this ONLY if you are planning to integrate this into AWS Lambda or AWS Fargate.
For any other use-case, check the original repository.
Notes
Sentry SDK Initialization is NOT done within this library.
If you're going to use this library, you need to ensure that the Sentry SDK is properly initialized before importing the library.
Example for a standard AWS Lambda function:
filename = libraries/sentry.py
import os
import sentry_sdk
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
sentry_sdk.init(
dsn=os.environ.get('SENTRY_DSN'),
integrations= [AwsLambdaIntegration(timeout_warning=True)],
environment=os.environ.get('Workspace'),
send_default_pii=True,
traces_sample_rate=0.0,
release=os.environ.get('SENTRY_RELEASE')
)
filename = libraries/logger.py
import simplejson as json
import structlog_sentry_lambda
SENTRY_LOGGER = structlog_sentry_lambda.get_logger()
logger = SENTRY_LOGGER.bind()
def debug(log_message):
logger.debug(json.dumps(log_message, sort_keys=True, default=str))
def error(log_message):
logger.error(json.dumps(log_message, sort_keys=True, default=str))
def exception(log_message):
logger.exception(json.dumps(log_message, sort_keys=True, default=str))
def warning(log_message):
logger.warning(json.dumps(log_message, sort_keys=True, default=str))
def info(log_message):
logger.info(json.dumps(log_message, sort_keys=True, default=str))
def main(log_message):
logger.info(json.dumps(log_message, sort_keys=True, default=str))
def log(log_message):
logger.info(json.dumps(log_message, sort_keys=True, default=str))
filename = index.py
import sys
sys.path.append('../libraries/')
from libraries import sentry
from libraries import logger
def main(event, context):
logger.info(event)
logger.error("Trigger an alert in Sentry")
return True
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file structlog-sentry-lambda-1.4.2.tar.gz
.
File metadata
- Download URL: structlog-sentry-lambda-1.4.2.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6d2ea7e9f139e4d0d305df647919802c9560023c2a89833a188b0c9b5c4ad76 |
|
MD5 | 3329d582842eb4c93f7e9dd8782e0ce1 |
|
BLAKE2b-256 | 2f8a77ddfc180b73c42bf3d1fcc4c6c7f47cf836b51df79cdd241bd195240eb9 |
File details
Details for the file structlog_sentry_lambda-1.4.2-py3-none-any.whl
.
File metadata
- Download URL: structlog_sentry_lambda-1.4.2-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5983692ccc77748ab16cb4d95f6776f22fe98d6c388735cdefde806748781f0b |
|
MD5 | 7d84f6bdcd3f9b1b947ad91d2ead0a37 |
|
BLAKE2b-256 | 5f5becc51431478beadfe4d74cba0890f5a00d7a499ea5653dbf75966c5ee5a9 |