| | | 1 | | namespace NexusLabs.Needlr.AgentFramework.Diagnostics; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Configuration options for the agent framework's OpenTelemetry metrics and tracing. |
| | | 5 | | /// </summary> |
| | | 6 | | /// <remarks> |
| | | 7 | | /// <para> |
| | | 8 | | /// Consumers that have existing dashboards keyed to a specific meter name (e.g., |
| | | 9 | | /// <c>"BrandGhost.Agents"</c>) can set <see cref="MeterName"/> to match, avoiding a |
| | | 10 | | /// dashboard migration when adopting Needlr's <see cref="IAgentMetrics"/>. |
| | | 11 | | /// </para> |
| | | 12 | | /// <para> |
| | | 13 | | /// Configure via the syringe: |
| | | 14 | | /// <code> |
| | | 15 | | /// .UsingAgentFramework(af => af |
| | | 16 | | /// .ConfigureMetrics(o => o.MeterName = "MyApp.Agents")) |
| | | 17 | | /// </code> |
| | | 18 | | /// </para> |
| | | 19 | | /// </remarks> |
| | | 20 | | [DoNotAutoRegister] |
| | | 21 | | public sealed class AgentFrameworkMetricsOptions |
| | | 22 | | { |
| | | 23 | | /// <summary> |
| | | 24 | | /// The name used for the <see cref="System.Diagnostics.Metrics.Meter"/> that emits |
| | | 25 | | /// counters and histograms. Defaults to <c>"NexusLabs.Needlr.AgentFramework"</c>. |
| | | 26 | | /// </summary> |
| | 258 | 27 | | public string MeterName { get; set; } = "NexusLabs.Needlr.AgentFramework"; |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// The name used for the <see cref="System.Diagnostics.ActivitySource"/> that emits |
| | | 31 | | /// distributed tracing spans. Defaults to <see cref="MeterName"/> when |
| | | 32 | | /// <see langword="null"/>. |
| | | 33 | | /// </summary> |
| | 98 | 34 | | public string? ActivitySourceName { get; set; } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Controls how Needlr's diagnostics middleware creates |
| | | 38 | | /// <see cref="System.Diagnostics.Activity"/> spans for chat completion calls. |
| | | 39 | | /// </summary> |
| | | 40 | | /// <remarks> |
| | | 41 | | /// <para> |
| | | 42 | | /// When MEAI's <c>UseOpenTelemetry()</c> or MAF's <c>WithOpenTelemetry()</c> is |
| | | 43 | | /// also active, both Needlr and the upstream middleware create spans for the same |
| | | 44 | | /// chat completion call. Set this to |
| | | 45 | | /// <see cref="ChatCompletionActivityMode.EnrichParent"/> to avoid duplicate spans — |
| | | 46 | | /// Needlr will add its tags (sequence number, char counts, agent name) to the |
| | | 47 | | /// existing parent <c>gen_ai.*</c> activity instead of creating a new one. |
| | | 48 | | /// </para> |
| | | 49 | | /// <para> |
| | | 50 | | /// Tool call activities (<c>agent.tool</c>) are not affected by this setting — |
| | | 51 | | /// they are always created because neither MEAI nor MAF produces per-tool-call spans. |
| | | 52 | | /// </para> |
| | | 53 | | /// </remarks> |
| | 0 | 54 | | public ChatCompletionActivityMode ChatCompletionActivityMode { get; set; } = |
| | | 55 | | ChatCompletionActivityMode.Always; |
| | | 56 | | |
| | 87 | 57 | | internal string ResolvedActivitySourceName => ActivitySourceName ?? MeterName; |
| | | 58 | | } |