-
Notifications
You must be signed in to change notification settings - Fork 129
Adding detailed telemetry #561
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
dd336ee
added detailed telemetry
mwojtyczka 6a81a0f
refactor
mwojtyczka 998645b
refactor
mwojtyczka 140fc64
refactor
mwojtyczka 909a5b3
Merge branch 'main' into telemetry
mwojtyczka 56b6d81
Merge branch 'main' into telemetry
mwojtyczka b0b85b9
updated api call to support group assigned clusters
mwojtyczka df541b1
updated logging logic
mwojtyczka eed9fc1
support local execution
mwojtyczka 7bd2d16
support local execution
mwojtyczka bfa68ec
fmt
mwojtyczka 9a15665
enforce workspace client validation
mwojtyczka a764505
enforce workspace client validation
mwojtyczka 91e15d1
refactor, added unit tests
mwojtyczka 2d6fece
made spark connect optional to support local execution and testing
mwojtyczka 406a910
fmt
mwojtyczka 0c822b0
updated docs, fmt
mwojtyczka 743ad3e
fmt
mwojtyczka 85917ad
fix copilot feedback
mwojtyczka 26a7c7f
updated docs
mwojtyczka e437274
updated docs
mwojtyczka d98551c
added more telemetry
mwojtyczka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import logging | ||
| from collections.abc import Callable | ||
| from databricks.sdk import WorkspaceClient | ||
| from databricks.sdk.config import with_user_agent_extra | ||
| from databricks.sdk.errors import DatabricksError | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def log_telemetry(ws: WorkspaceClient, key: str, value: str) -> None: | ||
| """ | ||
| Trace specific telemetry information in the Databricks workspace by setting user agent extra info. | ||
|
|
||
| Args: | ||
| ws: WorkspaceClient | ||
| key: telemetry key to log | ||
| value: telemetry value to log | ||
| """ | ||
| with_user_agent_extra(key, value) | ||
| try: | ||
| ws.current_user.me() | ||
| except DatabricksError as e: | ||
| # support local execution | ||
| logger.debug(f"Databricks workspace is not available: {e}") | ||
|
|
||
|
|
||
| def telemetry_logger(key: str, value: str) -> Callable: | ||
| """ | ||
| Decorator to log telemetry for method calls. | ||
|
|
||
| Usage: @telemetry_logger("telemetry_key", "telemetry_value") | ||
|
|
||
| Args: | ||
| key: Telemetry key to log | ||
| value: Telemetry value to log | ||
| """ | ||
|
|
||
| def decorator(func: Callable) -> Callable: | ||
| def wrapper(self, *args, **kwargs): | ||
|
mwojtyczka marked this conversation as resolved.
|
||
| """ | ||
| Expecting the workspace client be available in the calling class as 'ws' or 'workspace_client' attribute. | ||
| """ | ||
| if hasattr(self, 'ws'): # requires workspace client to be set | ||
| log_telemetry(self.ws, key, value) | ||
| elif hasattr(self, 'workspace_client'): # requires workspace client to be set | ||
| log_telemetry(self.workspace_client, key, value) | ||
| else: | ||
| raise AttributeError( | ||
| f"Workspace client not found on {self.__class__.__name__}. " | ||
| f"Telemetry decorator requires 'ws' or 'workspace_client' attribute. " | ||
| f"Make sure your class has a workspace client defined." | ||
|
mwojtyczka marked this conversation as resolved.
Outdated
|
||
| ) | ||
| return func(self, *args, **kwargs) | ||
|
|
||
| return wrapper | ||
|
|
||
| return decorator | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.