Skip to content

Commit c6bd674

Browse files
authored
Remove duplicate "public" APIs and Internal prefix/suffixes (#7546)
## Summary of changes - Removes APIs marked with `[Public]` which are no longer used - Remove `Internal` suffixes and prefixes ## Reason for change The `[Public]` attributes were introduced in v2 when we needed to segregate APIs customer's invoke from our own internal APIs. To work around that, we created "duplicate" APIs for many functions, and decorated the public ones with `[Public]`. However, in v3, we have a separate shim, so this is no longer necessary, and those public APIs are entirely unused (outside of testing). ## Implementation details - Remove unused APIs - Where `Internal` versions of the APIs exist, rename them and update calling code - Left _some_ `[Public]` attributes for methods that we still don't really want to call from inside Datadog.Trace - Will clean up this in a separate PR (e.g. rename `[Public]` to `[TestingOnly]`) to give the same usage guards but being more explicit about the purpose ## Test coverage Just removing dead code, so as long as the tests still pass, we should be good ## Other details Partly related to https://datadoghq.atlassian.net/browse/LANGPLAT-819 and the config stack, as want to avoid needing to handle unused APIs
1 parent 43e26c8 commit c6bd674

35 files changed

+71
-484
lines changed

tracer/src/Datadog.Trace.BenchmarkDotNet/DatadogExporter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static DatadogExporter()
4545

4646
private DatadogExporter()
4747
{
48-
TestSession = TestSession.InternalGetOrCreate(Environment.CommandLine, Environment.CurrentDirectory, CommonTags.TestingFrameworkNameBenchmarkDotNet, DateTime.UtcNow, false);
48+
TestSession = TestSession.GetOrCreate(Environment.CommandLine, Environment.CurrentDirectory, CommonTags.TestingFrameworkNameBenchmarkDotNet, DateTime.UtcNow, false);
4949
}
5050

5151
/// <inheritdoc />
@@ -79,15 +79,15 @@ public IEnumerable<string> ExportToFiles(Summary summary, ILogger consoleLogger)
7979
var moduleName = benchmarkModule.Key.GetName().Name ?? "Module";
8080
var framework = CommonTags.TestingFrameworkNameBenchmarkDotNet;
8181
testModule = moduleStartTime is null ?
82-
TestSession.InternalCreateModule(moduleName, framework, version) :
83-
TestSession.InternalCreateModule(moduleName, framework, version, startDate: moduleStartTime.Value);
82+
TestSession.CreateModule(moduleName, framework, version) :
83+
TestSession.CreateModule(moduleName, framework, version, startDate: moduleStartTime.Value);
8484
_testModules[benchmarkModule.Key] = testModule;
8585
}
8686

8787
foreach (var benchmarkSuite in benchmarkModule)
8888
{
8989
BenchmarkMetadata.GetTimes(benchmarkSuite.Key, out var suiteStartTime, out var suiteEndTime);
90-
var testSuite = testModule.InternalGetOrCreateSuite(benchmarkSuite.Key.FullName ?? "Suite", suiteStartTime);
90+
var testSuite = testModule.GetOrCreateSuite(benchmarkSuite.Key.FullName ?? "Suite", suiteStartTime);
9191

9292
foreach (var benchmarkTest in benchmarkSuite)
9393
{
@@ -129,7 +129,7 @@ public IEnumerable<string> ExportToFiles(Summary summary, ILogger consoleLogger)
129129

130130
BenchmarkMetadata.GetIds(benchmarkCase, out var traceId, out var spanId);
131131

132-
var test = testSuite.InternalCreateTest(testName, testStartTime, traceId, spanId);
132+
var test = testSuite.CreateTest(testName, testStartTime, traceId, spanId);
133133
test.SetTestMethodInfo(descriptor.WorkloadMethod);
134134
test.SetBenchmarkMetadata(
135135
new BenchmarkHostInfo

tracer/src/Datadog.Trace.Manual/Configuration/TracerSettings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ public void SetHttpServerErrorStatusCodes(IEnumerable<int> statusCodes)
466466
/// </summary>
467467
/// <param name="mappings">Mappings to use from original service name (e.g. <code>sql-server</code> or <code>graphql</code>)
468468
/// as the <see cref="KeyValuePair{TKey, TValue}.Key"/>) to replacement service names as <see cref="KeyValuePair{TKey, TValue}.Value"/>).</param>
469-
[PublicApi]
470469
public void SetServiceNameMappings(IEnumerable<KeyValuePair<string, string>> mappings)
471470
{
472471
// Check for null to be safe as it's a public API.

tracer/src/Datadog.Trace/AppSec/EventTrackingSdk.cs

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,13 @@ namespace Datadog.Trace.AppSec;
1717
/// </summary>
1818
public static class EventTrackingSdk
1919
{
20-
/// <summary>
21-
/// Sets the details of a successful logon on the local root span
22-
/// </summary>
23-
/// <param name="userId">The userId associated with the login success</param>
24-
[PublicApi]
25-
public static void TrackUserLoginSuccessEvent(string userId)
26-
{
27-
TelemetryFactory.Metrics.Record(PublicApiUsage.EventTrackingSdk_TrackUserLoginSuccessEvent);
28-
TrackUserLoginSuccessEvent(userId, null, Tracer.Instance);
29-
}
30-
3120
/// <summary>
3221
/// Sets the details of a successful logon on the local root span
3322
/// </summary>
3423
/// <param name="userId">The userId associated with the login success</param>
3524
/// <param name="metadata">Metadata associated with the login success</param>
36-
[PublicApi]
37-
public static void TrackUserLoginSuccessEvent(string userId, IDictionary<string, string> metadata)
38-
{
39-
TelemetryFactory.Metrics.Record(PublicApiUsage.EventTrackingSdk_TrackUserLoginSuccessEvent_Metadata);
40-
TrackUserLoginSuccessEvent(userId, metadata, Tracer.Instance);
41-
}
42-
43-
internal static void TrackUserLoginSuccessEvent(string userId, IDictionary<string, string> metadata, Tracer tracer)
25+
/// <param name="tracer">The tracer instance for retrieving the active scope</param>
26+
public static void TrackUserLoginSuccessEvent(string userId, IDictionary<string, string> metadata, Tracer tracer)
4427
{
4528
TelemetryFactory.Metrics.RecordCountUserEventSdk(MetricTags.UserEventSdk.UserEventLoginSuccessSdkV1);
4629

@@ -118,32 +101,14 @@ void RunWafAndCollectHeaders()
118101
}
119102
}
120103

121-
/// <summary>
122-
/// Sets the details of a logon failure on the local root span
123-
/// </summary>
124-
/// <param name="userId">The userId associated with the login failure</param>
125-
/// <param name="exists">If the userId associated with the login failure exists</param>
126-
[PublicApi]
127-
public static void TrackUserLoginFailureEvent(string userId, bool exists)
128-
{
129-
TelemetryFactory.Metrics.Record(PublicApiUsage.EventTrackingSdk_TrackUserLoginFailureEvent);
130-
TrackUserLoginFailureEvent(userId, exists, null, Tracer.Instance);
131-
}
132-
133104
/// <summary>
134105
/// Sets the details of a logon failure on the local root span
135106
/// </summary>
136107
/// <param name="userId">The userId associated with the login failure</param>
137108
/// <param name="exists">If the userId associated with the login failure exists</param>
138109
/// <param name="metadata">Metadata associated with the login failure</param>
139-
[PublicApi]
140-
public static void TrackUserLoginFailureEvent(string userId, bool exists, IDictionary<string, string> metadata)
141-
{
142-
TelemetryFactory.Metrics.Record(PublicApiUsage.EventTrackingSdk_TrackUserLoginFailureEvent_Metadata);
143-
TrackUserLoginFailureEvent(userId, exists, metadata, Tracer.Instance);
144-
}
145-
146-
internal static void TrackUserLoginFailureEvent(string userId, bool exists, IDictionary<string, string> metadata, Tracer tracer)
110+
/// <param name="tracer">The tracer instance for retrieving the active scope</param>
111+
public static void TrackUserLoginFailureEvent(string userId, bool exists, IDictionary<string, string> metadata, Tracer tracer)
147112
{
148113
TelemetryFactory.Metrics.RecordCountUserEventSdk(MetricTags.UserEventSdk.UserEventFailureSdkV1);
149114

@@ -180,29 +145,12 @@ internal static void TrackUserLoginFailureEvent(string userId, bool exists, IDic
180145
RunSecurityChecksAndReport(spanInternal, userId: userId, loginSuccess: false);
181146
}
182147

183-
/// <summary>
184-
/// Sets the details of a custom event the local root span
185-
/// </summary>
186-
/// <param name="eventName">the name of the event to be tracked</param>
187-
[PublicApi]
188-
public static void TrackCustomEvent(string eventName)
189-
{
190-
TelemetryFactory.Metrics.Record(PublicApiUsage.EventTrackingSdk_TrackCustomEvent);
191-
TrackCustomEvent(eventName, null, Tracer.Instance);
192-
}
193-
194148
/// <summary>
195149
/// Sets the details of a custom event the local root span
196150
/// </summary>
197151
/// <param name="eventName">the name of the event to be tracked</param>
198152
/// <param name="metadata">Metadata associated with the custom event</param>
199-
[PublicApi]
200-
public static void TrackCustomEvent(string eventName, IDictionary<string, string> metadata)
201-
{
202-
TelemetryFactory.Metrics.Record(PublicApiUsage.EventTrackingSdk_TrackCustomEvent_Metadata);
203-
TrackCustomEvent(eventName, metadata, Tracer.Instance);
204-
}
205-
153+
/// <param name="tracer">The tracer instance for retrieving the active scope</param>
206154
internal static void TrackCustomEvent(string eventName, IDictionary<string, string> metadata, Tracer tracer)
207155
{
208156
TelemetryFactory.Metrics.RecordCountUserEventSdk(MetricTags.UserEventSdk.UserEventCustomSdkV1);

tracer/src/Datadog.Trace/Ci/TestModule.cs

Lines changed: 7 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ internal TestModule(string name, string? framework, string? frameworkVersion, Da
153153
else
154154
{
155155
_testOptimization.Log.Information("A session cannot be found, creating a fake session as a parent of the module.");
156-
_fakeSession = TestSession.InternalGetOrCreate(System.Environment.CommandLine, System.Environment.CurrentDirectory, null, startDate, false);
156+
_fakeSession = TestSession.GetOrCreate(System.Environment.CommandLine, System.Environment.CurrentDirectory, null, startDate, false);
157157
if (_fakeSession.Tags is { } fakeSessionTags)
158158
{
159159
tags.SessionId = fakeSessionTags.SessionId;
@@ -249,56 +249,15 @@ internal static IReadOnlyCollection<TestModule> ActiveTestModules
249249

250250
internal TestModuleSpanTags Tags => (TestModuleSpanTags)_span.Tags;
251251

252-
/// <summary>
253-
/// Create a new Test Module
254-
/// </summary>
255-
/// <param name="name">Test module name</param>
256-
/// <returns>New test module instance</returns>
257-
[PublicApi]
258-
public static TestModule Create(string name)
259-
{
260-
TelemetryFactory.Metrics.RecordCountCIVisibilityManualApiEvent(MetricTags.CIVisibilityTestingEventType.Module);
261-
return InternalCreate(name, framework: null, frameworkVersion: null, startDate: null);
262-
}
263-
264-
/// <summary>
265-
/// Create a new Test Module
266-
/// </summary>
267-
/// <param name="name">Test module name</param>
268-
/// <param name="framework">Testing framework name</param>
269-
/// <param name="frameworkVersion">Testing framework version</param>
270-
/// <returns>New test module instance</returns>
271-
[PublicApi]
272-
public static TestModule Create(string name, string framework, string frameworkVersion)
273-
{
274-
TelemetryFactory.Metrics.RecordCountCIVisibilityManualApiEvent(MetricTags.CIVisibilityTestingEventType.Module);
275-
return InternalCreate(name, framework, frameworkVersion, startDate: null);
276-
}
277-
278-
/// <summary>
279-
/// Create a new Test Module
280-
/// </summary>
281-
/// <param name="name">Test module name</param>
282-
/// <param name="framework">Testing framework name</param>
283-
/// <param name="frameworkVersion">Testing framework version</param>
284-
/// <param name="startDate">Test session start date</param>
285-
/// <returns>New test module instance</returns>
286-
[PublicApi]
287-
public static TestModule Create(string name, string framework, string frameworkVersion, DateTimeOffset startDate)
288-
{
289-
TelemetryFactory.Metrics.RecordCountCIVisibilityManualApiEvent(MetricTags.CIVisibilityTestingEventType.Module);
290-
return InternalCreate(name, framework, frameworkVersion, startDate);
291-
}
292-
293252
/// <summary>
294253
/// Create a new Test Module
295254
/// </summary>
296255
/// <param name="name">Test module name</param>
297256
/// <param name="framework">Testing framework name</param>
298257
/// <param name="frameworkVersion">Testing framework version</param>
299258
/// <returns>New test module instance</returns>
300-
internal static TestModule InternalCreate(string name, string? framework, string? frameworkVersion)
301-
=> InternalCreate(name, framework, frameworkVersion, null);
259+
internal static TestModule Create(string name, string? framework, string? frameworkVersion)
260+
=> Create(name, framework, frameworkVersion, null);
302261

303262
/// <summary>
304263
/// Create a new Test Module
@@ -308,7 +267,7 @@ internal static TestModule InternalCreate(string name, string? framework, string
308267
/// <param name="frameworkVersion">Testing framework version</param>
309268
/// <param name="startDate">Test session start date</param>
310269
/// <returns>New test module instance</returns>
311-
internal static TestModule InternalCreate(string name, string? framework, string? frameworkVersion, DateTimeOffset? startDate)
270+
internal static TestModule Create(string name, string? framework, string? frameworkVersion, DateTimeOffset? startDate)
312271
{
313272
return new TestModule(name, framework, frameworkVersion, startDate);
314273
}
@@ -567,34 +526,9 @@ CoverageReporter.Handler is DefaultWithGlobalCoverageEventHandler coverageHandle
567526
/// </summary>
568527
/// <param name="name">Name of the test suite</param>
569528
/// <returns>Test suite instance</returns>
570-
[PublicApi]
571-
public TestSuite GetOrCreateSuite(string name)
572-
{
573-
TelemetryFactory.Metrics.RecordCountCIVisibilityManualApiEvent(MetricTags.CIVisibilityTestingEventType.Suite);
574-
return InternalGetOrCreateSuite(name, null);
575-
}
576-
577-
/// <summary>
578-
/// Create a new test suite for this session
579-
/// </summary>
580-
/// <param name="name">Name of the test suite</param>
581-
/// <returns>Test suite instance</returns>
582-
internal TestSuite InternalGetOrCreateSuite(string name)
583-
{
584-
return InternalGetOrCreateSuite(name, null);
585-
}
586-
587-
/// <summary>
588-
/// Create a new test suite for this session
589-
/// </summary>
590-
/// <param name="name">Name of the test suite</param>
591-
/// <param name="startDate">Test suite start date</param>
592-
/// <returns>Test suite instance</returns>
593-
[PublicApi]
594-
public TestSuite GetOrCreateSuite(string name, DateTimeOffset? startDate)
529+
internal TestSuite GetOrCreateSuite(string name)
595530
{
596-
TelemetryFactory.Metrics.RecordCountCIVisibilityManualApiEvent(MetricTags.CIVisibilityTestingEventType.Suite);
597-
return InternalGetOrCreateSuite(name, startDate);
531+
return GetOrCreateSuite(name, null);
598532
}
599533

600534
/// <summary>
@@ -603,7 +537,7 @@ public TestSuite GetOrCreateSuite(string name, DateTimeOffset? startDate)
603537
/// <param name="name">Name of the test suite</param>
604538
/// <param name="startDate">Test suite start date</param>
605539
/// <returns>Test suite instance</returns>
606-
internal TestSuite InternalGetOrCreateSuite(string name, DateTimeOffset? startDate)
540+
internal TestSuite GetOrCreateSuite(string name, DateTimeOffset? startDate)
607541
{
608542
lock (_suites)
609543
{

0 commit comments

Comments
 (0)