mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
531132057b
* OTEL Demo * updating telemetry sample * OTEL updates * WIP * Adding GetService and Agent Metadata for Telemetry * WIP * Add UT for OTEL System behavior * Address Unicode problem * Add logging * Adjust for new extensions * Change Logger to LoggerFactory for the extension method * Address AI Feedback * Simplify script and readme just for Azure OpenAI * Increase code converage * Address merge conflict * Another slnx fix * Address PR comments * Address PR feedback + Add UT * Added Hosting UT to the solution * Address PR comments * Address missing sensitivity tests * Remove unecessary override * Address PR comments
28 lines
1.3 KiB
C#
28 lines
1.3 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Microsoft.Extensions.AI.Agents;
|
|
|
|
/// <summary>
|
|
/// Extension methods for <see cref="AIAgent"/>.
|
|
/// </summary>
|
|
public static class AgentExtensions
|
|
{
|
|
/// <summary>
|
|
/// Wraps the agent with OpenTelemetry instrumentation.
|
|
/// </summary>
|
|
/// <param name="agent">The agent to wrap.</param>
|
|
/// <param name="loggerFactory">The <see cref="ILogger"/> to use for emitting events.</param>
|
|
/// <param name="sourceName">An optional source name that will be used on the telemetry data.</param>
|
|
/// <param name="enableSensitiveData">When <see langword="true"/> indicates whether potentially sensitive information should be included in telemetry. Default is <see langword="false"/></param>
|
|
/// <returns>An <see cref="OpenTelemetryAgent"/> that wraps the original agent with telemetry.</returns>
|
|
public static OpenTelemetryAgent WithOpenTelemetry(this AIAgent agent, ILoggerFactory? loggerFactory = null, string? sourceName = null, bool? enableSensitiveData = null)
|
|
{
|
|
return new OpenTelemetryAgent(agent, loggerFactory?.CreateLogger(typeof(OpenTelemetryAgent)), sourceName)
|
|
{
|
|
EnableSensitiveData = enableSensitiveData ?? false
|
|
};
|
|
}
|
|
}
|