Skip to content

Commit 3ff248a

Browse files
kesmit13claude
andauthored
Improve UDF logging options (#88)
* Update docs * feat(functions): refactor logging configuration for UDF applications - Add log_file, log_format, and log_level parameters to Application class - Move logging configuration from main() to Application.__init__() via _configure_logging() - Add external_function.log_file and external_function.log_format config options - Update Application docstring to document all parameters including logging - Refactor Timer.finish() to return metrics dict instead of logging directly - Configure uvicorn logging to use same log file when specified This refactoring centralizes logging configuration and allows for more flexible UDF application logging through configuration parameters. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add disable_metrics option to external functions - Add external_function.disable_metrics configuration option (default: False) - Add disable_metrics parameter to Application class constructor - Update Application to create logger-specific instances with unique names - Add --disable-metrics command-line argument to main function - Conditionally log metrics based on disable_metrics flag - Support configuration via environment variable SINGLESTOREDB_EXT_FUNC_DISABLE_METRICS This allows users to disable the logging of function call metrics when needed, while maintaining backward compatibility with existing behavior. * refactor(functions): remove log_format config, add app_name parameter - Remove external_function.log_format configuration option and --log-format CLI flag - Standardize on JSON formatted logging for all external function applications - Add external_function.app_name configuration option with --app-name CLI flag - Change Application class constructor parameter from 'name=' to 'app_name=' for consistency - Update logging configuration to use JSON formatter for both console and file output - Improve structured logging with additional context fields (app_name, request_id, etc.) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Propagate log level to UDF app * feat: add get_uvicorn_log_config method to Application class - Move uvicorn log config creation from main() into a reusable method - Allow external users to match the Application's logging format - Simplify main() by using the new method - Uses the same JSON formatter and settings as Application's internal logging 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 202a5bf commit 3ff248a

File tree

5 files changed

+291
-42
lines changed

5 files changed

+291
-42
lines changed

singlestoredb/apps/_python_udfs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ async def run_udf_app(
4747
udf_suffix = ''
4848
if app_config.running_interactively:
4949
udf_suffix = '_test'
50-
app = Application(url=base_url, app_mode='managed', name_suffix=udf_suffix)
50+
app = Application(
51+
url=base_url,
52+
app_mode='managed',
53+
name_suffix=udf_suffix,
54+
log_level=log_level,
55+
)
5156

5257
if not app.endpoints:
5358
raise ValueError('You must define at least one function.')
@@ -60,7 +65,7 @@ async def run_udf_app(
6065
app,
6166
host='0.0.0.0',
6267
port=app_config.listen_port,
63-
log_level=log_level,
68+
log_config=app.get_uvicorn_log_config(),
6469
)
6570

6671
# Register the functions only if the app is running interactively.

singlestoredb/config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@
407407
environ=['SINGLESTOREDB_EXT_FUNC_LOG_LEVEL'],
408408
)
409409

410+
register_option(
411+
'external_function.log_file', 'string', check_str, None,
412+
'File path to write logs to instead of console.',
413+
environ=['SINGLESTOREDB_EXT_FUNC_LOG_FILE'],
414+
)
415+
410416
register_option(
411417
'external_function.name_prefix', 'string', check_str, '',
412418
'Prefix to add to external function names.',
@@ -450,6 +456,18 @@
450456
environ=['SINGLESTOREDB_EXT_FUNC_TIMEOUT'],
451457
)
452458

459+
register_option(
460+
'external_function.disable_metrics', 'bool', check_bool, False,
461+
'Disable logging of function call metrics.',
462+
environ=['SINGLESTOREDB_EXT_FUNC_DISABLE_METRICS'],
463+
)
464+
465+
register_option(
466+
'external_function.app_name', 'string', check_str, None,
467+
'Name for the external function application instance.',
468+
environ=['SINGLESTOREDB_EXT_FUNC_APP_NAME'],
469+
)
470+
453471
#
454472
# Debugging options
455473
#

0 commit comments

Comments
 (0)