Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/Braintrust.Sdk.Anthropic/InstrumentedMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
if (activity != null)
{
activity.SetStatus(ActivityStatusCode.Error, ex.Message);
activity.RecordException(ex);

Check warning on line 65 in src/Braintrust.Sdk.Anthropic/InstrumentedMessageService.cs

View workflow job for this annotation

GitHub Actions / build

'ActivityExtensions.RecordException(Activity?, Exception?)' is obsolete: 'Call Activity.AddException instead this method will be removed in a future version.'

Check warning on line 65 in src/Braintrust.Sdk.Anthropic/InstrumentedMessageService.cs

View workflow job for this annotation

GitHub Actions / build

'ActivityExtensions.RecordException(Activity?, Exception?)' is obsolete: 'Call Activity.AddException instead this method will be removed in a future version.'
}
throw;
}
Expand Down Expand Up @@ -115,7 +115,7 @@
if (activity != null)
{
activity.SetStatus(ActivityStatusCode.Error, ex.Message);
activity.RecordException(ex);

Check warning on line 118 in src/Braintrust.Sdk.Anthropic/InstrumentedMessageService.cs

View workflow job for this annotation

GitHub Actions / build

'ActivityExtensions.RecordException(Activity?, Exception?)' is obsolete: 'Call Activity.AddException instead this method will be removed in a future version.'

Check warning on line 118 in src/Braintrust.Sdk.Anthropic/InstrumentedMessageService.cs

View workflow job for this annotation

GitHub Actions / build

'ActivityExtensions.RecordException(Activity?, Exception?)' is obsolete: 'Call Activity.AddException instead this method will be removed in a future version.'
}
throw;
}
Expand Down Expand Up @@ -203,6 +203,7 @@
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());

Expand Down Expand Up @@ -259,6 +260,7 @@
{
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
Expand Down
1 change: 1 addition & 0 deletions src/Braintrust.Sdk.OpenAI/InstrumentedChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
if (activity != null)
{
activity.SetStatus(ActivityStatusCode.Error, ex.Message);
activity.RecordException(ex);

Check warning on line 74 in src/Braintrust.Sdk.OpenAI/InstrumentedChatClient.cs

View workflow job for this annotation

GitHub Actions / build

'ActivityExtensions.RecordException(Activity?, Exception?)' is obsolete: 'Call Activity.AddException instead this method will be removed in a future version.'

Check warning on line 74 in src/Braintrust.Sdk.OpenAI/InstrumentedChatClient.cs

View workflow job for this annotation

GitHub Actions / build

'ActivityExtensions.RecordException(Activity?, Exception?)' is obsolete: 'Call Activity.AddException instead this method will be removed in a future version.'
}
// intentionally re-throwing original exception
throw;
Expand Down Expand Up @@ -114,7 +114,7 @@
if (activity != null)
{
activity.SetStatus(ActivityStatusCode.Error, ex.Message);
activity.RecordException(ex);

Check warning on line 117 in src/Braintrust.Sdk.OpenAI/InstrumentedChatClient.cs

View workflow job for this annotation

GitHub Actions / build

'ActivityExtensions.RecordException(Activity?, Exception?)' is obsolete: 'Call Activity.AddException instead this method will be removed in a future version.'

Check warning on line 117 in src/Braintrust.Sdk.OpenAI/InstrumentedChatClient.cs

View workflow job for this annotation

GitHub Actions / build

'ActivityExtensions.RecordException(Activity?, Exception?)' is obsolete: 'Call Activity.AddException instead this method will be removed in a future version.'
}
// intentionally re-throwing original exception
throw;
Expand All @@ -141,6 +141,7 @@
IEnumerable<ChatMessage>? 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions tests/Braintrust.Sdk.OpenAI.Tests/BraintrustOpenAITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading