Skip to content

Commit

Permalink
Merge branch 'release/0.13.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Keene committed Jan 25, 2023
2 parents ecca49d + 65539bd commit e962e83
Show file tree
Hide file tree
Showing 30 changed files with 2,624 additions and 1,193 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
- name: Get tag and tracker versions
id: version
run: |
echo ::set-output name=TAG_VERSION::${GITHUB_REF#refs/*/}
echo "##[set-output name=PYTHON_TRACKER_VERSION;]$(python setup.py --version)"
echo "TAG_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "PYTHON_TRACKER_VERSION=$(python setup.py --version)" >> $GITHUB_OUTPUT
- name: Fail if version mismatch
if: ${{ steps.version.outputs.TAG_VERSION != steps.version.outputs.PYTHON_TRACKER_VERSION }}
Expand Down
11 changes: 11 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Version 0.13.0 (2023-01-24)
---------------------------
Adds Snowplow Interface (#295)
Adds retry for failed events (#296)
Adds customisable retry codes (#297)
Adds EventStore with max limit (#309)
Adds Snowplow Example App (#302)
Fix Collector URL with trailing '/' (#300)
Rename unstruct_event to self_describing_event (#298)
Upgrade `set-output` in cd (#294)

Version 0.12.0 (2022-11-03)
---------------------------
Adds Domain Session ID and Domain Session Index to Subject class (#282) (Thanks to @cpnat)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2013-2022 Snowplow Analytics Ltd.
Copyright 2013-2023 Snowplow Analytics Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Assuming [docker](https://www.docker.com/) is installed
Copyright and license
---------------------

The Snowplow Python Tracker is copyright 2013-2022 Snowplow Analytics
The Snowplow Python Tracker is copyright 2013-2023 Snowplow Analytics
Ltd.

Licensed under the [Apache License, Version
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
# -- Project information -----------------------------------------------------

project = 'Snowplow Python Tracker'
copyright = '2022, Alex Dean, Paul Boocock, Matus Tomlein, Jack Keene'
copyright = "2023, Alex Dean, Paul Boocock, Matus Tomlein, Jack Keene"
author = 'Alex Dean, Paul Boocock, Matus Tomlein, Jack Keene'

# The full version, including alpha/beta/rc tags
release = '0.12'
release = "0.13"


# -- General configuration ---------------------------------------------------
Expand Down
59 changes: 59 additions & 0 deletions examples/snowplow_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import sys
from snowplow_tracker import (
Snowplow,
EmitterConfiguration,
Subject,
TrackerConfiguration,
SelfDescribingJson,
)


def get_url_from_args():
if len(sys.argv) != 2:
raise ValueError("Collector Endpoint is required")
return sys.argv[1]


def main():

collector_url = get_url_from_args()
# Configure Emitter
custom_retry_codes = {500: False, 401: True}
emitter_config = EmitterConfiguration(batch_size=5, custom_retry_codes=custom_retry_codes)

# Configure Tracker
tracker_config = TrackerConfiguration(encode_base64=True)

# Initialise subject
subject = Subject()
subject.set_user_id("uid")

Snowplow.create_tracker(
namespace="ns",
endpoint=collector_url,
app_id="app1",
subject=subject,
tracker_config=tracker_config,
emitter_config=emitter_config,
)

tracker = Snowplow.get_tracker("ns")

tracker.track_page_view("https://www.snowplow.io", "Homepage")
tracker.track_page_ping("https://www.snowplow.io", "Homepage")
tracker.track_link_click("https://www.snowplow.io/about")
tracker.track_page_view("https://www.snowplow.io/about", "About")

tracker.track_self_describing_event(
SelfDescribingJson(
"iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1",
{"targetUrl": "example.com"},
)
)
tracker.track_struct_event("shop", "add-to-basket", None, "pcs", 2)

tracker.flush()


if __name__ == "__main__":
main()
10 changes: 3 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# setup.py

# Copyright (c) 2013-2022 Snowplow Analytics Ltd. All rights reserved.
# Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved.

# This program is licensed to you under the Apache License Version 2.0,
# and you may not use this file except in compliance with the Apache License
Expand All @@ -13,11 +13,7 @@
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the Apache License Version 2.0 for the specific
# language governing permissions and limitations there under.

# Authors: Anuj More, Alex Dean, Fred Blundun, Paul Boocock
# Copyright: Copyright (c) 2013-2022 Snowplow Analytics Ltd
# License: Apache License Version 2.0
#
# """

#!/usr/bin/env python
# -*- coding: utf-8 -*-
Expand All @@ -37,7 +33,7 @@

setup(
name="snowplow-tracker",
version="0.12.0",
version="0.13.0",
author=authors_str,
author_email=authors_email_str,
packages=[
Expand Down
4 changes: 4 additions & 0 deletions snowplow_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from snowplow_tracker.emitters import logger, Emitter, AsyncEmitter
from snowplow_tracker.self_describing_json import SelfDescribingJson
from snowplow_tracker.tracker import Tracker
from snowplow_tracker.emitter_configuration import EmitterConfiguration
from snowplow_tracker.tracker_configuration import TrackerConfiguration
from snowplow_tracker.snowplow import Snowplow
from snowplow_tracker.contracts import disable_contracts, enable_contracts
from snowplow_tracker.event_store import EventStore

# celery extra
from .celery import CeleryEmitter
Expand Down
8 changes: 2 additions & 6 deletions snowplow_tracker/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# """
# _version.py

# Copyright (c) 2013-2022 Snowplow Analytics Ltd. All rights reserved.
# Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved.

# This program is licensed to you under the Apache License Version 2.0,
# and you may not use this file except in compliance with the Apache License
Expand All @@ -13,12 +13,8 @@
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the Apache License Version 2.0 for the specific
# language governing permissions and limitations there under.

# Authors: Anuj More, Alex Dean, Fred Blundun, Paul Boocock
# Copyright: Copyright (c) 2013-2022 Snowplow Analytics Ltd
# License: Apache License Version 2.0
# """

__version_info__ = (0, 12, 0)
__version_info__ = (0, 13, 0)
__version__ = ".".join(str(x) for x in __version_info__)
__build_version__ = __version__ + ""
43 changes: 24 additions & 19 deletions snowplow_tracker/celery/celery_emitter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# """
# celery_emitter.py

# Copyright (c) 2013-2022 Snowplow Analytics Ltd. All rights reserved.
# Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved.

# This program is licensed to you under the Apache License Version 2.0,
# and you may not use this file except in compliance with the Apache License
Expand All @@ -13,10 +13,6 @@
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the Apache License Version 2.0 for the specific
# language governing permissions and limitations there under.

# Authors: Anuj More, Alex Dean, Fred Blundun, Paul Boocock
# Copyright: Copyright (c) 2013-2022 Snowplow Analytics Ltd
# License: Apache License Version 2.0
# """

import logging
Expand All @@ -39,27 +35,32 @@

class CeleryEmitter(Emitter):
"""
Uses a Celery worker to send HTTP requests asynchronously.
Works like the base Emitter class,
but on_success and on_failure callbacks cannot be set.
Uses a Celery worker to send HTTP requests asynchronously.
Works like the base Emitter class,
but on_success and on_failure callbacks cannot be set.
"""

if _CELERY_OPT:

celery_app = None

def __init__(
self,
endpoint: str,
protocol: HttpProtocol = "http",
port: Optional[int] = None,
method: Method = "post",
buffer_size: Optional[int] = None,
byte_limit: Optional[int] = None) -> None:
super(CeleryEmitter, self).__init__(endpoint, protocol, port, method, buffer_size, None, None, byte_limit)
self,
endpoint: str,
protocol: HttpProtocol = "http",
port: Optional[int] = None,
method: Method = "post",
batch_size: Optional[int] = None,
byte_limit: Optional[int] = None,
) -> None:
super(CeleryEmitter, self).__init__(
endpoint, protocol, port, method, batch_size, None, None, byte_limit
)

try:
# Check whether a custom Celery configuration module named "snowplow_celery_config" exists
import snowplow_celery_config

self.celery_app = Celery()
self.celery_app.config_from_object(snowplow_celery_config)
except ImportError:
Expand All @@ -80,6 +81,10 @@ def async_flush(self) -> None:

else:

def __new__(cls, *args: Any, **kwargs: Any) -> 'CeleryEmitter':
logger.error("CeleryEmitter is not available. Please install snowplow-tracker with celery extra dependency.")
raise RuntimeError('CeleryEmitter is not available. To use: `pip install snowplow-tracker[celery]`')
def __new__(cls, *args: Any, **kwargs: Any) -> "CeleryEmitter":
logger.error(
"CeleryEmitter is not available. Please install snowplow-tracker with celery extra dependency."
)
raise RuntimeError(
"CeleryEmitter is not available. To use: `pip install snowplow-tracker[celery]`"
)
27 changes: 15 additions & 12 deletions snowplow_tracker/contracts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# """
# contracts.py

# Copyright (c) 2013-2022 Snowplow Analytics Ltd. All rights reserved.
# Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved.

# This program is licensed to you under the Apache License Version 2.0,
# and you may not use this file except in compliance with the Apache License
Expand All @@ -13,10 +13,6 @@
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the Apache License Version 2.0 for the specific
# language governing permissions and limitations there under.

# Authors: Anuj More, Alex Dean, Fred Blundun, Paul Boocock, Matus Tomlein
# Copyright: Copyright (c) 2013-2022 Snowplow Analytics Ltd
# License: Apache License Version 2.0
# """

import traceback
Expand Down Expand Up @@ -45,7 +41,9 @@ def contracts_enabled() -> bool:

def greater_than(value: float, compared_to: float) -> None:
if contracts_enabled() and value <= compared_to:
raise ValueError("{0} must be greater than {1}.".format(_get_parameter_name(), compared_to))
raise ValueError(
"{0} must be greater than {1}.".format(_get_parameter_name(), compared_to)
)


def non_empty(seq: Sized) -> None:
Expand Down Expand Up @@ -78,21 +76,26 @@ def _get_parameter_name() -> str:

match = _MATCH_FIRST_PARAMETER_REGEX.search(code)
if not match:
return 'Unnamed parameter'
return "Unnamed parameter"
return match.groups(0)[0]


def _check_form_element(element: Dict[str, Any]) -> bool:
"""
Helper method to check that dictionary conforms element
in sumbit_form and change_form schemas
Helper method to check that dictionary conforms element
in sumbit_form and change_form schemas
"""
all_present = isinstance(element, dict) and 'name' in element and 'value' in element and 'nodeName' in element
all_present = (
isinstance(element, dict)
and "name" in element
and "value" in element
and "nodeName" in element
)
try:
if element['type'] in FORM_TYPES:
if element["type"] in FORM_TYPES:
type_valid = True
else:
type_valid = False
except KeyError:
type_valid = True
return all_present and element['nodeName'] in FORM_NODE_NAMES and type_valid
return all_present and element["nodeName"] in FORM_NODE_NAMES and type_valid
Loading

0 comments on commit e962e83

Please sign in to comment.