mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: Workflow observability (#959)
* Add basic Workflow telemetry * Add sample * Add source propagation for executor spans * Fix tests and address comments * Fix formatting * Fix declarative unit tests * Address comments * Remove Microsoft.Extensions.AI.Agents.EnableTelemetry * Formatting * Formatting * Formatting * fix solution * Address comments * Add workflow json definition for serialization * Formmating * Address comments
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Agents.AI.Workflows.Checkpointing;
|
||||
using Microsoft.Agents.AI.Workflows.Execution;
|
||||
using Microsoft.Agents.AI.Workflows.Observability;
|
||||
using Microsoft.Agents.AI.Workflows.Reflection;
|
||||
|
||||
namespace Microsoft.Agents.AI.Workflows;
|
||||
@@ -25,6 +26,9 @@ public abstract class Executor : IIdentified
|
||||
|
||||
private readonly ExecutorOptions _options;
|
||||
|
||||
private static readonly string s_namespace = typeof(Executor).Namespace!;
|
||||
private static readonly ActivitySource s_activitySource = new(s_namespace);
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the executor with a unique identifier
|
||||
/// </summary>
|
||||
@@ -88,6 +92,12 @@ public abstract class Executor : IIdentified
|
||||
/// <exception cref="TargetInvocationException">An exception is generated while handling the message.</exception>
|
||||
public async ValueTask<object?> ExecuteAsync(object message, TypeId messageType, IWorkflowContext context)
|
||||
{
|
||||
using var activity = s_activitySource.StartActivity(ActivityNames.ExecutorProcess, ActivityKind.Internal);
|
||||
activity?.SetTag(Tags.ExecutorId, this.Id)
|
||||
.SetTag(Tags.ExecutorType, this.GetType().FullName)
|
||||
.SetTag(Tags.MessageType, messageType.TypeName)
|
||||
.CreateSourceLinks(context.TraceContext);
|
||||
|
||||
await context.AddEventAsync(new ExecutorInvokedEvent(this.Id, message)).ConfigureAwait(false);
|
||||
|
||||
CallResult? result = await this.Router.RouteMessageAsync(message, context, requireRoute: true)
|
||||
|
||||
Reference in New Issue
Block a user