Skip to content

Commit d13640c

Browse files
committed
Remove option to initialize SentrySDK using AIOptions
1 parent 07a0111 commit d13640c

File tree

4 files changed

+21
-81
lines changed

4 files changed

+21
-81
lines changed

samples/Sentry.Samples.ME.AI.Console/Program.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@
1414
throw new InvalidOperationException($"Environment variable for OpenAI API key '{varName}' is not set.");
1515
}
1616

17+
// Initialize Sentry SDK
18+
SentrySdk.Init(options =>
19+
{
20+
#if !SENTRY_DSN_DEFINED_IN_ENV
21+
// A DSN is required. You can set here in code, or you can set it in the SENTRY_DSN environment variable.
22+
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
23+
options.Dsn = SamplesShared.Dsn;
24+
#endif
25+
options.Debug = true;
26+
options.DiagnosticLevel = SentryLevel.Debug;
27+
options.SampleRate = 1;
28+
options.TracesSampleRate = 1;
29+
});
30+
1731
// Create OpenAI API client and wrap it with Sentry instrumentation
1832
var openAiClient = new OpenAI.Chat.ChatClient("gpt-4o-mini", openAiApiKey)
1933
.AsIChatClient()
2034
.AddSentry(options =>
2135
{
22-
#if !SENTRY_DSN_DEFINED_IN_ENV
23-
// A DSN is required. You can set here in code, or you can set it in the SENTRY_DSN environment variable.
24-
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
25-
options.Dsn = SamplesShared.Dsn;
26-
#endif
27-
options.Debug = true;
28-
options.DiagnosticLevel = SentryLevel.Debug;
29-
options.SampleRate = 1;
30-
options.TracesSampleRate = 1;
31-
3236
// AI-specific settings
3337
options.RecordInputs = true;
3438
options.RecordOutputs = true;
35-
// Since this is a simple console app without Sentry already set up, we need to initialize our SDK
36-
options.InitializeSdk = true;
3739
});
3840

3941
var client = new ChatClientBuilder(openAiClient)

src/Sentry.Extensions.AI/SentryAIOptions.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ namespace Sentry.Extensions.AI;
33
/// <summary>
44
/// Sentry AI instrumentation options
55
/// </summary>
6-
/// <inheritdoc />
7-
public class SentryAIOptions : SentryOptions
6+
public class SentryAIOptions
87
{
98
/// <summary>
109
/// Whether to include request messages in spans.
@@ -20,12 +19,4 @@ public class SentryAIOptions : SentryOptions
2019
/// Name of the AI Agent
2120
/// </summary>
2221
public string AgentName { get; set; } = "Agent";
23-
24-
/// <summary>
25-
/// Whether to initialize the Sentry SDK through this integration.
26-
/// </summary>
27-
/// <remarks>
28-
/// If you have already set up Sentry in your application, there is no need to re-initialize the Sentry SDK
29-
/// </remarks>
30-
public bool InitializeSdk { get; set; } = false;
3122
}

src/Sentry.Extensions.AI/SentryChatClient.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ public SentryChatClient(IChatClient client, Action<SentryAIOptions>? configure =
1111
{
1212
_sentryAIOptions = new SentryAIOptions();
1313
configure?.Invoke(_sentryAIOptions);
14-
15-
// If user requested to initialize the SDK, and SDK is not enabled already, then use the options to init Sentry
16-
if (_sentryAIOptions.InitializeSdk && !SentrySdk.IsEnabled)
17-
{
18-
SentrySdk.Init(_sentryAIOptions);
19-
}
2014
}
2115

2216
/// <inheritdoc cref="IChatClient"/>

test/Sentry.Extensions.AI.Tests/SentryAIOptionsTests.cs

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public void Constructor_SetsDefaultValues()
1313
// Assert
1414
Assert.True(options.RecordInputs);
1515
Assert.True(options.RecordOutputs);
16-
Assert.False(options.InitializeSdk);
1716
}
1817

1918
[Fact]
@@ -44,69 +43,23 @@ public void IncludeResponseContent_CanBeSet()
4443
Assert.False(options.RecordOutputs);
4544
}
4645

47-
[Fact]
48-
public void InitializeSdk_CanBeSet()
49-
{
50-
// Arrange
51-
var options = new SentryAIOptions();
52-
53-
// Act
54-
options.InitializeSdk = true;
55-
56-
// Assert
57-
Assert.True(options.InitializeSdk);
58-
}
59-
60-
[Fact]
61-
public void InheritsFromSentryOptions()
62-
{
63-
// Arrange & Act
64-
var options = new SentryAIOptions();
65-
66-
// Assert
67-
Assert.IsType<SentryOptions>(options, exactMatch: false);
68-
}
69-
70-
[Fact]
71-
public void CanSetSentryOptionsProperties()
72-
{
73-
// Arrange
74-
var options = new SentryAIOptions();
75-
76-
// Act
77-
options.Dsn = "https://key@sentry.io/project";
78-
options.Environment = "test";
79-
options.Release = "1.0.0";
80-
81-
// Assert
82-
Assert.Equal("https://key@sentry.io/project", options.Dsn);
83-
Assert.Equal("test", options.Environment);
84-
Assert.Equal("1.0.0", options.Release);
85-
}
86-
8746
[Theory]
88-
[InlineData(true, true, true)]
89-
[InlineData(true, true, false)]
90-
[InlineData(true, false, true)]
91-
[InlineData(true, false, false)]
92-
[InlineData(false, true, true)]
93-
[InlineData(false, true, false)]
94-
[InlineData(false, false, true)]
95-
[InlineData(false, false, false)]
96-
public void AllPropertyCombinations_WorkCorrectly(bool includeRequest, bool includeResponse, bool initializeSdk)
47+
[InlineData(true, true)]
48+
[InlineData(true, false)]
49+
[InlineData(false, true)]
50+
[InlineData(false, false)]
51+
public void AllPropertyCombinations_WorkCorrectly(bool includeRequest, bool includeResponse)
9752
{
9853
// Arrange
9954
var options = new SentryAIOptions
10055
{
10156
// Act
10257
RecordInputs = includeRequest,
103-
RecordOutputs = includeResponse,
104-
InitializeSdk = initializeSdk
58+
RecordOutputs = includeResponse
10559
};
10660

10761
// Assert
10862
Assert.Equal(includeRequest, options.RecordInputs);
10963
Assert.Equal(includeResponse, options.RecordOutputs);
110-
Assert.Equal(initializeSdk, options.InitializeSdk);
11164
}
11265
}

0 commit comments

Comments
 (0)