Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ The implementation is validated through:
```csharp
// Create TracerProvider
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource(AgentOpenTelemetryConsts.DefaultSourceName)
.AddSource(OpenTelemetryAgent.DefaultSourceName)
.AddConsoleExporter()
.Build();

Expand Down
12 changes: 12 additions & 0 deletions dotnet/src/Microsoft.Agents.AI/OpenTelemetryAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public sealed class OpenTelemetryAgent : DelegatingAIAgent, IDisposable
// inner agent not directly but rather via OpenTelemetryChatClient, which wraps a ForwardingChatClient that in turn
// calls back into the inner agent.

/// <summary>
/// Gets the default <see cref="ActivitySource"/> name used by <see cref="OpenTelemetryAgent"/> when no source
/// name is supplied to the constructor.
/// </summary>
/// <remarks>
/// Pass this value to the tracing pipeline (for example, <c>TracerProviderBuilder.AddSource</c>) to subscribe to
/// the spans emitted by agents that use the default source name, instead of hardcoding the literal name. This is
/// a property rather than a constant so that the value is read at run time: a consumer that upgrades the package
/// picks up the current source name without recompiling.
/// </remarks>
public static string DefaultSourceName => OpenTelemetryConsts.DefaultSourceName;

/// <summary>The <see cref="OpenTelemetryChatClient"/> providing the bulk of the telemetry.</summary>
private readonly OpenTelemetryChatClient _otelClient;
/// <summary>The provider name extracted from <see cref="AIAgentMetadata"/>.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,17 @@ public async Task AutoWireChatClient_UserFactoryAddsOwnOTel_CoexistsWithBelowFic
Assert.Equal(2, activities.Count(a => string.Equals(a.GetTagItem("gen_ai.operation.name") as string, "chat", StringComparison.Ordinal)));
}

[Fact]
public void DefaultSourceName_ReturnsDocumentedSourceName()
{
// Callers pass this to TracerProviderBuilder.AddSource, so it must stay in sync with the source name the
// agent emits spans under, which Ctor_NullOrWhitespaceSourceName_AutoWiredChatClientUsesDefaultSource_Async
// pins to the same literal. Comparing against the literal here guards a rename of the internal constant.

// Arrange & Act & Assert
Assert.Equal("Experimental.Microsoft.Agents.AI", OpenTelemetryAgent.DefaultSourceName);
}

[Theory]
[InlineData(null)]
[InlineData("")]
Expand Down
Loading