Exemplo n.º 1
0
def log_event(
    distinct_id: str,
    ip: str,
    site_url: str,
    data: dict,
    team_id: int,
    now: datetime.datetime,
    sent_at: Optional[datetime.datetime],
    event_uuid: UUIDT,
    *,
    topics: Sequence[str],
) -> None:
    if settings.DEBUG:
        print(f'Logging event {data["event"]} to Kafka topics {" and ".join(topics)}')
    producer = KafkaProducer()
    data = {
        "uuid": str(event_uuid),
        "distinct_id": distinct_id,
        "ip": ip,
        "site_url": site_url,
        "data": json.dumps(data),
        "team_id": team_id,
        "now": now.isoformat(),
        "sent_at": sent_at.isoformat() if sent_at else "",
    }
    for topic in topics:
        producer.produce(topic=topic, data=data)
Exemplo n.º 2
0
def log_event(
    distinct_id: str,
    ip: str,
    site_url: str,
    data: dict,
    team_id: int,
    now: datetime.datetime,
    sent_at: Optional[datetime.datetime],
) -> None:
    data = {
        "distinct_id": distinct_id,
        "ip": ip,
        "site_url": site_url,
        "data": json.dumps(data),
        "team_id": team_id,
        "now": now.strftime("%Y-%m-%d %H:%M:%S.%f"),
        "sent_at": sent_at.strftime("%Y-%m-%d %H:%M:%S.%f") if sent_at else "",
    }
    p = KafkaProducer()
    p.produce(topic=KAFKA_EVENTS_WAL, data=data)