Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TaoChenOSU committed Aug 22, 2024
1 parent 673ba80 commit d813b64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
6 changes: 3 additions & 3 deletions python/semantic_kernel/functions/kernel_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
logger: logging.Logger = logging.getLogger(__name__)
tracer: trace.Tracer = trace.get_tracer(__name__)
meter: metrics.Meter = metrics.get_meter_provider().get_meter(__name__)
MeasurementFunctionTagName: str = "semantic_kernel.function.name"
MEASUREMENT_FUNCTION_TAG_NAME: str = "semantic_kernel.function.name"

TEMPLATE_FORMAT_MAP = {
KERNEL_TEMPLATE_FORMAT_NAME: KernelPromptTemplate,
Expand Down Expand Up @@ -227,7 +227,7 @@ async def invoke(
KernelFunctionLogMessages.log_function_invoking(logger, self.fully_qualified_name)
KernelFunctionLogMessages.log_function_arguments(logger, arguments)

attributes = {MeasurementFunctionTagName: self.fully_qualified_name}
attributes = {MEASUREMENT_FUNCTION_TAG_NAME: self.fully_qualified_name}
starting_time_stamp = time.perf_counter()
try:
stack = kernel.construct_call_stack(
Expand Down Expand Up @@ -287,7 +287,7 @@ async def invoke_stream(
KernelFunctionLogMessages.log_function_streaming_invoking(logger, self.fully_qualified_name)
KernelFunctionLogMessages.log_function_arguments(logger, arguments)

attributes = {MeasurementFunctionTagName: self.fully_qualified_name}
attributes = {MEASUREMENT_FUNCTION_TAG_NAME: self.fully_qualified_name}
starting_time_stamp = time.perf_counter()
try:
stack = kernel.construct_call_stack(
Expand Down
21 changes: 7 additions & 14 deletions python/semantic_kernel/functions/kernel_function_log_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@ class KernelFunctionLogMessages:
@staticmethod
def log_function_invoking(logger: Logger, kernel_function_name: str):
"""Log message when a kernel function is invoked."""
if logger.isEnabledFor(logging.INFO):
logger.info("Function %s invoking.", kernel_function_name)
logger.info("Function %s invoking.", kernel_function_name)

@staticmethod
def log_function_arguments(logger: Logger, arguments: KernelArguments):
"""Log message when a kernel function is invoked."""
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Function arguments: %s", arguments)
logger.debug("Function arguments: %s", arguments)

@staticmethod
def log_function_invoked_success(logger: Logger, kernel_function_name: str):
"""Log message when a kernel function is invoked successfully."""
if logger.isEnabledFor(logging.INFO):
logger.info("Function %s succeeded.", kernel_function_name)
logger.info("Function %s succeeded.", kernel_function_name)

@staticmethod
def log_function_result_value(logger: Logger, function_result: FunctionResult | None):
Expand All @@ -48,23 +45,19 @@ def log_function_result_value(logger: Logger, function_result: FunctionResult |
@staticmethod
def log_function_error(logger: Logger, error: Exception):
"""Log message when a kernel function fails."""
if logger.isEnabledFor(logging.ERROR):
logger.error("Function failed. Error: %s", error)
logger.error("Function failed. Error: %s", error)

@staticmethod
def log_function_completed(logger: Logger, duration: float):
"""Log message when a kernel function is completed."""
if logger.isEnabledFor(logging.INFO):
logger.info("Function completed. Duration: %fs", duration)
logger.info("Function completed. Duration: %fs", duration)

@staticmethod
def log_function_streaming_invoking(logger: Logger, kernel_function_name: str):
"""Log message when a kernel function is invoked via streaming."""
if logger.isEnabledFor(logging.INFO):
logger.info("Function %s streaming.", kernel_function_name)
logger.info("Function %s streaming.", kernel_function_name)

@staticmethod
def log_function_streaming_completed(logger: Logger, duration: float):
"""Log message when a kernel function is completed via streaming."""
if logger.isEnabledFor(logging.INFO):
logger.info("Function streaming completed. Duration: %fs", duration)
logger.info("Function streaming completed. Duration: %fs", duration)

0 comments on commit d813b64

Please sign in to comment.