diff --git a/src/Braintrust.Sdk.Anthropic/InstrumentedMessageService.cs b/src/Braintrust.Sdk.Anthropic/InstrumentedMessageService.cs index 76498e7..950a0d6 100644 --- a/src/Braintrust.Sdk.Anthropic/InstrumentedMessageService.cs +++ b/src/Braintrust.Sdk.Anthropic/InstrumentedMessageService.cs @@ -203,6 +203,7 @@ private static void TagActivity( double? timeToFirstToken = null) { activity.SetTag("provider", "anthropic"); + activity.SetTag("braintrust.span_attributes", "{\"type\":\"llm\"}"); activity.SetTag("gen_ai.request.model", request.Model.Raw()); activity.SetTag("gen_ai.response.model", response.Model.Raw()); @@ -259,6 +260,7 @@ private static void TagStreamActivity(Activity activity, MessageCreateParams req { activity.SetTag("stream", true); activity.SetTag("provider", "anthropic"); + activity.SetTag("braintrust.span_attributes", "{\"type\":\"llm\"}"); activity.SetTag("gen_ai.request.model", request.Model.Raw()); try diff --git a/src/Braintrust.Sdk.OpenAI/InstrumentedChatClient.cs b/src/Braintrust.Sdk.OpenAI/InstrumentedChatClient.cs index 1bace95..4733b94 100644 --- a/src/Braintrust.Sdk.OpenAI/InstrumentedChatClient.cs +++ b/src/Braintrust.Sdk.OpenAI/InstrumentedChatClient.cs @@ -141,6 +141,7 @@ private void TagActivity( IEnumerable? messages) { activity.SetTag("provider", "openai"); + activity.SetTag("braintrust.span_attributes", "{\"type\":\"llm\"}"); var requestRaw = activity.GetBaggageItem("braintrust.http.request"); var responseRaw = activity.GetBaggageItem("braintrust.http.response"); diff --git a/tests/Braintrust.Sdk.Anthropic.Tests/BraintrustAnthropicTest.cs b/tests/Braintrust.Sdk.Anthropic.Tests/BraintrustAnthropicTest.cs index 59bc399..97a0b89 100644 --- a/tests/Braintrust.Sdk.Anthropic.Tests/BraintrustAnthropicTest.cs +++ b/tests/Braintrust.Sdk.Anthropic.Tests/BraintrustAnthropicTest.cs @@ -170,6 +170,11 @@ public async Task MessageCreation_CapturesRequestAndResponse() var ttft = Convert.ToDouble(timeToFirstToken); Assert.True(ttft >= 0, "time_to_first_token should be non-negative"); + + // Verify span attributes type is set to "llm" + var spanAttributes = span.GetTagItem("braintrust.span_attributes") as string; + Assert.NotNull(spanAttributes); + Assert.Contains("\"type\":\"llm\"", spanAttributes); } [Fact] diff --git a/tests/Braintrust.Sdk.OpenAI.Tests/BraintrustOpenAITest.cs b/tests/Braintrust.Sdk.OpenAI.Tests/BraintrustOpenAITest.cs index 89bf7bc..d751ec6 100644 --- a/tests/Braintrust.Sdk.OpenAI.Tests/BraintrustOpenAITest.cs +++ b/tests/Braintrust.Sdk.OpenAI.Tests/BraintrustOpenAITest.cs @@ -182,6 +182,11 @@ public async Task ChatCompletion_CapturesRequestAndResponse() // Verify time_to_first_token is a non-negative number var ttft = Convert.ToDouble(timeToFirstToken); Assert.True(ttft >= 0, "time_to_first_token should be greater than or equal to 0"); + + // Verify span attributes type is set to "llm" + var spanAttributes = span.GetTagItem("braintrust.span_attributes") as string; + Assert.NotNull(spanAttributes); + Assert.Contains("\"type\":\"llm\"", spanAttributes); } [Fact]