-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
airbyte-ci: Add basic segment tracking #31354
Changes from 5 commits
917831f
61df0ed
bb2f5db
673e1cf
9f94944
d4340f3
a9bad78
4f2b4c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import getpass | ||
import os | ||
import sys | ||
|
||
import segment.analytics as analytics | ||
|
||
analytics.write_key = "G6G7whgro81g9xM00kN2buclGKvcOjFd" | ||
analytics.send = True | ||
analytics.debug = True | ||
|
||
|
||
def _is_airbyte_user(): | ||
return os.getenv("AIRBYTE_ROLE") == "airbyter" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. |
||
|
||
|
||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any PII worries here? I guess this is an internal tool for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good callout. @evantahler Ill go ahead and hash their machine info |
||
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cool checking this in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine so. We already have checked in the write key for octavia cli. I dont see the difference here.
Also not too disimilar to how sentry/segment FE libraries work