Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add airbyer property
Browse files Browse the repository at this point in the history
bnchrch committed Oct 14, 2023
1 parent 61df0ed commit bb2f5db
Showing 2 changed files with 39 additions and 23 deletions.
24 changes: 1 addition & 23 deletions airbyte-ci/connectors/pipelines/pipelines/commands/airbyte_ci.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@

import importlib
from typing import List
import sys

import click
from github import PullRequest
@@ -27,29 +26,8 @@
from .groups.metadata import metadata
from .groups.tests import test

from pipelines.telemetry import track_command

import segment.analytics as analytics

analytics.write_key = 'ER8EjdRVFut7n05XPaaTKrSEnjLscyKr'
analytics.send = False
def on_error(error, items):
print("An error occurred:", error)


analytics.debug = True
analytics.on_error = on_error

def track_command(f):
def wrapper(*args, **kwargs):
full_cmd = " ".join(sys.argv)
is_local = kwargs.get('is_local', False)
user_id = 'local-user' if is_local else 'ci-user'

# IMPORTANT! do not log kwargs as they may contain secrets
analytics.track(user_id=user_id, event=f.__name__, properties={'command': full_cmd})

return f(*args, **kwargs)
return wrapper

# HELPERS

38 changes: 38 additions & 0 deletions airbyte-ci/connectors/pipelines/pipelines/telemetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys
import getpass
import os

import segment.analytics as analytics

analytics.write_key = 'ER8EjdRVFut7n05XPaaTKrSEnjLscyKr'
analytics.send = True
analytics.debug = True

def _is_airbyte_user():
return os.getenv("AIRBYTE_ROLE") == "airbyter"

def track_command(f):
"""
Decorator to track CLI commands with segment.io
"""
def wrapper(*args, **kwargs):
ctx = args[0]
top_level_command = ctx.command_path
full_cmd = " ".join(sys.argv)

sys_user_name = getpass.getuser()
airbyter = _is_airbyte_user()

# remove anything prior to the command name f.__name__
# to avoid logging inline secrets
santized_cmd = full_cmd[full_cmd.find(top_level_command):]

is_local = kwargs.get('is_local', False)
user_id = 'local-user' if is_local else 'ci-user'
event = f"airbyte-ci:{f.__name__}"

# IMPORTANT! do not log kwargs as they may contain secrets
analytics.track(user_id, event, {'username': sys_user_name, 'command': santized_cmd, 'airbyter': airbyter})

return f(*args, **kwargs)
return wrapper

0 comments on commit bb2f5db

Please sign in to comment.