Skip to content
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

.Net: SK Telemetry improvements #1905

Merged
merged 51 commits into from
Jul 18, 2023
Merged

Conversation

dmytrostruk
Copy link
Member

@dmytrostruk dmytrostruk commented Jul 8, 2023

Motivation and Context

This PR contains changes to improve observability for Semantic Kernel users, including:

  • Logging: using already existing ILogger interface with some improvements described below.
  • Metering: implemented using Meter and MeterListener classes from System.Diagnostics.Metrics namespace.
  • Tracing: implemented using Activity, ActivitySource and ActivityListener classes from System.Diagnostics namespace.

Added telemetry uses native .NET methods, which means that it's not dependent on specific telemetry tool.
Current PR contains console application using Application Insights as example to show telemetry capabilities in Kernel.

Changes include instrumentation for SequentialPlanner as a starting point and later there will be new PRs for other types of planners and more improvements for kernel telemetry.

Also, there are updates for LogLevel handling across codebase to align with described log level purpose:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loglevel?view=dotnet-plat-ext-7.0

Particularly, there are changes for LogLevel.Trace to be used for sensitive data and most detailed messages, which should not be enabled in prodution environments.

Description

Changes:

  • Marked .WithLogger method in KernelBuilder as obsolete and added new method .WithLogging.
  • Added new methods .WithMetering and .WithTracing in KernelBuilder.
  • Improved LogLevel handling across codebase to cover cases of logging sensitive data.
  • Implemented InstrumentedSequentialPlanner for instrumentation using decorator pattern.
  • Extended InvokeAsync method in Plan for instrumentation.

Contribution Checklist

@dmytrostruk dmytrostruk requested review from a team as code owners July 8, 2023 00:43
@github-actions github-actions bot added docs and tests Improvements or additions to documentation .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel samples memory connector labels Jul 8, 2023
@shawncal shawncal removed the docs and tests Improvements or additions to documentation label Jul 18, 2023
SergeyMenshykh
SergeyMenshykh previously approved these changes Jul 18, 2023
@shawncal shawncal added this pull request to the merge queue Jul 18, 2023
Merged via the queue into microsoft:main with commit 55dc794 Jul 18, 2023
piotrek-appstream pushed a commit to Appstream-Studio/semantic-kernel that referenced this pull request Jul 19, 2023
### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

This PR contains changes to improve observability for Semantic Kernel
users, including:
- Logging: using already existing `ILogger` interface with some
improvements described below.
- Metering: implemented using `Meter` and `MeterListener` classes from
`System.Diagnostics.Metrics` namespace.
- Tracing: implemented using `Activity`, `ActivitySource` and
`ActivityListener` classes from `System.Diagnostics` namespace.

Added telemetry uses native .NET methods, which means that it's not
dependent on specific telemetry tool.
Current PR contains console application using Application Insights as
example to show telemetry capabilities in Kernel.

Changes include instrumentation for `SequentialPlanner` as a starting
point and later there will be new PRs for other types of planners and
more improvements for kernel telemetry.

Also, there are updates for `LogLevel` handling across codebase to align
with described log level purpose:

https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loglevel?view=dotnet-plat-ext-7.0

Particularly, there are changes for `LogLevel.Trace` to be used for
sensitive data and most detailed messages, which should not be enabled
in prodution environments.

### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
Changes:
- Marked `.WithLogger` method in KernelBuilder as obsolete and added new
method `.WithLogging`.
- Added new methods `.WithMetering` and `.WithTracing` in KernelBuilder.
- Improved `LogLevel` handling across codebase to cover cases of logging
sensitive data.
- Implemented `InstrumentedSequentialPlanner` for instrumentation using
decorator pattern.
- Extended `InvokeAsync` method in `Plan` for instrumentation.

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Shawn Callegari <36091529+shawncal@users.noreply.github.com>
github-merge-queue bot pushed a commit that referenced this pull request Jul 24, 2023
)

### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

This is follow-up PR to the previous one regarding telemetry:
#1905

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
1. Added small improvements in instrumentation for `SequentialPlanner`.
2. Added instrumentation for `ActionPlanner`.
3. Added instrumentation for `StepwisePlanner`.
4. Updated log levels in `StepwisePlanner` to disable sensitive data by
default.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Shawn Callegari <36091529+shawncal@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel Issues or pull requests impacting the core kernel memory connector .NET Issue or Pull requests regarding .NET code PR: ready for review All feedback addressed, ready for reviews
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

C# Kernel: Add End-to-End Telemetry
4 participants