mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
* dev: enable api logging and control worker count through env * dev: enable logger instead of printing * dev: remove worker counts * dev: enable global level log settings * dev: add rotating logger * fix: logging configuration * dev: api logging and moving the capture exception to utils for logging and then capturing * fix: information leaking through print logs * dev: linting fix * dev: logging configuration for django * fix: linting errors * dev: add logs for migrator * dev: logging cofiguration * dev: add permision for captain user in Plane * dev: add log paths in compose * dev: create directory for logs * dev: fix linting errors
83 lines
2.3 KiB
Python
83 lines
2.3 KiB
Python
import os
|
|
import uuid
|
|
|
|
# third party imports
|
|
from celery import shared_task
|
|
from posthog import Posthog
|
|
|
|
# module imports
|
|
from plane.license.utils.instance_value import get_configuration_value
|
|
from plane.utils.exception_logger import log_exception
|
|
|
|
|
|
def posthogConfiguration():
|
|
POSTHOG_API_KEY, POSTHOG_HOST = get_configuration_value(
|
|
[
|
|
{
|
|
"key": "POSTHOG_API_KEY",
|
|
"default": os.environ.get("POSTHOG_API_KEY", None),
|
|
},
|
|
{
|
|
"key": "POSTHOG_HOST",
|
|
"default": os.environ.get("POSTHOG_HOST", None),
|
|
},
|
|
]
|
|
)
|
|
if POSTHOG_API_KEY and POSTHOG_HOST:
|
|
return POSTHOG_API_KEY, POSTHOG_HOST
|
|
else:
|
|
return None, None
|
|
|
|
|
|
@shared_task
|
|
def auth_events(user, email, user_agent, ip, event_name, medium, first_time):
|
|
try:
|
|
POSTHOG_API_KEY, POSTHOG_HOST = posthogConfiguration()
|
|
|
|
if POSTHOG_API_KEY and POSTHOG_HOST:
|
|
posthog = Posthog(POSTHOG_API_KEY, host=POSTHOG_HOST)
|
|
posthog.capture(
|
|
email,
|
|
event=event_name,
|
|
properties={
|
|
"event_id": uuid.uuid4().hex,
|
|
"user": {"email": email, "id": str(user)},
|
|
"device_ctx": {
|
|
"ip": ip,
|
|
"user_agent": user_agent,
|
|
},
|
|
"medium": medium,
|
|
"first_time": first_time,
|
|
},
|
|
)
|
|
except Exception as e:
|
|
log_exception(e)
|
|
return
|
|
|
|
|
|
@shared_task
|
|
def workspace_invite_event(
|
|
user, email, user_agent, ip, event_name, accepted_from
|
|
):
|
|
try:
|
|
POSTHOG_API_KEY, POSTHOG_HOST = posthogConfiguration()
|
|
|
|
if POSTHOG_API_KEY and POSTHOG_HOST:
|
|
posthog = Posthog(POSTHOG_API_KEY, host=POSTHOG_HOST)
|
|
posthog.capture(
|
|
email,
|
|
event=event_name,
|
|
properties={
|
|
"event_id": uuid.uuid4().hex,
|
|
"user": {"email": email, "id": str(user)},
|
|
"device_ctx": {
|
|
"ip": ip,
|
|
"user_agent": user_agent,
|
|
},
|
|
"accepted_from": accepted_from,
|
|
},
|
|
)
|
|
except Exception as e:
|
|
log_exception(e)
|
|
return
|