Skip to content

Commit 3c9beb8

Browse files
[OpenTelemetry] enable analysis - part 2 - final (#6279)
Co-authored-by: Rajkumar Rangaraj <[email protected]>
1 parent 7abe983 commit 3c9beb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+152
-16
lines changed

src/OpenTelemetry/BaseExportProcessor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public enum ExportProcessorType
2929
/// Implements processor that exports telemetry objects.
3030
/// </summary>
3131
/// <typeparam name="T">The type of telemetry object to be exported.</typeparam>
32+
#pragma warning disable CA1708 // Identifiers should differ by more than case
3233
public abstract class BaseExportProcessor<T> : BaseProcessor<T>
34+
#pragma warning restore CA1708 // Identifiers should differ by more than case
3335
where T : class
3436
{
3537
/// <summary>
@@ -50,7 +52,9 @@ protected BaseExportProcessor(BaseExporter<T> exporter)
5052
{
5153
Guard.ThrowIfNull(exporter);
5254

55+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
5356
this.friendlyTypeName = $"{this.GetType().Name}{{{exporter.GetType().Name}}}";
57+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
5458
this.exporter = exporter;
5559
}
5660

src/OpenTelemetry/BaseProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ namespace OpenTelemetry;
99
/// Base processor base class.
1010
/// </summary>
1111
/// <typeparam name="T">The type of object to be processed.</typeparam>
12+
#pragma warning disable CA1012 // Abstract types should not have public constructors
1213
public abstract class BaseProcessor<T> : IDisposable
14+
#pragma warning restore CA1012 // Abstract types should not have public constructors
1315
{
1416
private readonly string typeName;
1517
private int shutdownCount;
1618

1719
/// <summary>
1820
/// Initializes a new instance of the <see cref="BaseProcessor{T}"/> class.
1921
/// </summary>
20-
#pragma warning disable CA1012 // Abstract types should not have public constructors
2122
public BaseProcessor()
22-
#pragma warning restore CA1012 // Abstract types should not have public constructors
2323
{
2424
this.typeName = this.GetType().Name;
2525
}

src/OpenTelemetry/Batch.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ namespace OpenTelemetry;
2929
public Batch(T[] items, int count)
3030
{
3131
Guard.ThrowIfNull(items);
32+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
3233
Guard.ThrowIfOutOfRange(count, min: 0, max: items.Length);
34+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
3335

3436
this.items = items;
3537
this.Count = this.targetCount = count;

src/OpenTelemetry/BatchExportProcessor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ protected BatchExportProcessor(
6060
this.exporterThread = new Thread(this.ExporterProc)
6161
{
6262
IsBackground = true,
63+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
6364
Name = $"OpenTelemetry-{nameof(BatchExportProcessor<T>)}-{exporter.GetType().Name}",
65+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
6466
};
6567
this.exporterThread.Start();
6668
}

src/OpenTelemetry/CompositeProcessor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public CompositeProcessor(IEnumerable<BaseProcessor<T>> processors)
2424
{
2525
Guard.ThrowIfNull(processors);
2626

27+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
2728
using var iter = processors.GetEnumerator();
29+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
2830
if (!iter.MoveNext())
2931
{
3032
throw new ArgumentException($"'{iter}' is null or empty", nameof(processors));

src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ internal class SelfDiagnosticsConfigRefresher : IDisposable
3535

3636
// Once the configuration file is valid, an eventListener object will be created.
3737
private SelfDiagnosticsEventListener? eventListener;
38+
#pragma warning disable CA2213 // Disposable fields should be disposed
3839
private volatile FileStream? underlyingFileStreamForMemoryMappedFile;
3940
private volatile MemoryMappedFile? memoryMappedFile;
41+
#pragma warning restore CA2213 // Disposable fields should be disposed
4042
private string? logDirectory; // Log directory for log files
4143
private int logFileSize; // Log file size in bytes
4244
private long logFilePosition; // The logger will write into the byte at this position

src/OpenTelemetry/Internal/SelfDiagnosticsEventListener.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ internal void WriteEvent(string? eventMessage, ReadOnlyCollection<object?>? payl
249249

250250
buffer[pos++] = (byte)'\n';
251251
int byteCount = pos - 0;
252+
#pragma warning disable CA2000 // Dispose objects before losing scope
252253
if (this.configRefresher.TryGetLogStream(byteCount, out Stream? stream, out int availableByteCount))
254+
#pragma warning restore CA2000 // Dispose objects before losing scope
253255
{
254256
if (availableByteCount >= byteCount)
255257
{
@@ -283,7 +285,9 @@ protected override void OnEventSourceCreated(EventSource eventSource)
283285
{
284286
lock (this.lockObj)
285287
{
288+
#pragma warning disable CA1508 // Avoid dead conditional code - see previous comment
286289
if (this.eventSourcesBeforeConstructor != null)
290+
#pragma warning restore CA1508 // Avoid dead conditional code - see previous comment
287291
{
288292
this.eventSourcesBeforeConstructor.Add(eventSource);
289293
return;

src/OpenTelemetry/Internal/WildcardHelper.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public static bool ContainsWildcard(
1818
return false;
1919
}
2020

21+
#if NET || NETSTANDARD2_1_OR_GREATER
22+
return value.Contains('*', StringComparison.Ordinal) || value.Contains('?', StringComparison.Ordinal);
23+
#else
2124
return value.Contains('*') || value.Contains('?');
25+
#endif
2226
}
2327

2428
public static Regex GetWildcardRegex(IEnumerable<string> patterns)
@@ -27,7 +31,11 @@ public static Regex GetWildcardRegex(IEnumerable<string> patterns)
2731

2832
var convertedPattern = string.Join(
2933
"|",
34+
#if NET || NETSTANDARD2_1_OR_GREATER
35+
from p in patterns select "(?:" + Regex.Escape(p).Replace("\\*", ".*", StringComparison.Ordinal).Replace("\\?", ".", StringComparison.Ordinal) + ')');
36+
#else
3037
from p in patterns select "(?:" + Regex.Escape(p).Replace("\\*", ".*").Replace("\\?", ".") + ')');
38+
#endif
3139

3240
return new Regex("^(?:" + convertedPattern + ")$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
3341
}

src/OpenTelemetry/Logs/ILogger/OpenTelemetryLoggerProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public OpenTelemetryLoggerProvider(IOptionsMonitor<OpenTelemetryLoggerOptions> o
3737
{
3838
Guard.ThrowIfNull(options);
3939

40+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
4041
var optionsInstance = options.CurrentValue;
42+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
4143

4244
this.Provider = Sdk
4345
.CreateLoggerProviderBuilder()
@@ -77,7 +79,9 @@ internal OpenTelemetryLoggerProvider(
7779
internal IExternalScopeProvider? ScopeProvider { get; private set; }
7880

7981
/// <inheritdoc/>
82+
#pragma warning disable CA1033 // Interface methods should be callable by child types
8083
void ISupportExternalScope.SetScopeProvider(IExternalScopeProvider scopeProvider)
84+
#pragma warning restore CA1033 // Interface methods should be callable by child types
8185
{
8286
this.ScopeProvider = scopeProvider;
8387

src/OpenTelemetry/Logs/ILogger/OpenTelemetryLoggingExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public static class OpenTelemetryLoggingExtensions
4242
[Obsolete("Call UseOpenTelemetry instead this method will be removed in a future version.")] */
4343
public static ILoggingBuilder AddOpenTelemetry(
4444
this ILoggingBuilder builder)
45+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
4546
=> AddOpenTelemetryInternal(builder, configureBuilder: null, configureOptions: null);
47+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
4648

4749
/// <summary>
4850
/// Adds an OpenTelemetry logger named 'OpenTelemetry' to the <see cref="ILoggerFactory"/>.
@@ -58,7 +60,9 @@ public static ILoggingBuilder AddOpenTelemetry(
5860
public static ILoggingBuilder AddOpenTelemetry(
5961
this ILoggingBuilder builder,
6062
Action<OpenTelemetryLoggerOptions>? configure)
63+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
6164
=> AddOpenTelemetryInternal(builder, configureBuilder: null, configureOptions: configure);
65+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
6266

6367
#if EXPOSE_EXPERIMENTAL_FEATURES
6468
/// <summary>
@@ -80,7 +84,9 @@ public static ILoggingBuilder AddOpenTelemetry(
8084
#endif
8185
static ILoggingBuilder UseOpenTelemetry(
8286
this ILoggingBuilder builder)
87+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
8388
=> AddOpenTelemetryInternal(builder, configureBuilder: null, configureOptions: null);
89+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
8490

8591
#if EXPOSE_EXPERIMENTAL_FEATURES
8692
/// <summary>
@@ -103,7 +109,9 @@ static ILoggingBuilder UseOpenTelemetry(
103109
{
104110
Guard.ThrowIfNull(configure);
105111

112+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
106113
return AddOpenTelemetryInternal(builder, configureBuilder: configure, configureOptions: null);
114+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
107115
}
108116

109117
#if EXPOSE_EXPERIMENTAL_FEATURES
@@ -126,7 +134,9 @@ static ILoggingBuilder UseOpenTelemetry(
126134
this ILoggingBuilder builder,
127135
Action<LoggerProviderBuilder>? configureBuilder,
128136
Action<OpenTelemetryLoggerOptions>? configureOptions)
137+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
129138
=> AddOpenTelemetryInternal(builder, configureBuilder, configureOptions);
139+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
130140

131141
private static ILoggingBuilder AddOpenTelemetryInternal(
132142
ILoggingBuilder builder,

0 commit comments

Comments
 (0)