Skip to content

Commit d61ae4f

Browse files
committed
Merge remote-tracking branch 'upstream/main' into RichardChukwu-main
2 parents cdf58de + bb83222 commit d61ae4f

File tree

111 files changed

+386
-443
lines changed

Some content is hidden

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

111 files changed

+386
-443
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,6 @@ analysis](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/overview
308308
[Common.props](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/build/Common.props)
309309
new projects must NOT manually override these settings.
310310

311-
## New code
312-
313-
New code files MUST enable [nullable reference
314-
types](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/nullable-reference-types)
315-
manually in projects where it is not automatically enabled project-wide. This is
316-
done by specifying `#nullable enable` towards the top of the file (usually after
317-
the copyright header). We are currently working towards enabling nullable
318-
context in every project by updating code as it is worked on, this requirement
319-
is to make sure the surface area of code needing updates is shrinking and not
320-
expanding.
321-
322-
> [!NOTE]
323-
> The first time a project is updated to use nullable context in public APIs
324-
some housekeeping needs to be done in public API definitions (`.publicApi`
325-
folder). This can be done automatically via a code fix offered by the public API
326-
analyzer.
327-
328311
## License requirements
329312

330313
OpenTelemetry .NET is licensed under the [Apache License, Version

docs/logs/redaction/MyRedactionProcessor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,33 @@ public override void OnEnd(LogRecord logRecord)
1515
}
1616
}
1717

18-
internal sealed class MyClassWithRedactionEnumerator : IReadOnlyList<KeyValuePair<string, object>>
18+
internal sealed class MyClassWithRedactionEnumerator : IReadOnlyList<KeyValuePair<string, object?>>
1919
{
20-
private readonly IReadOnlyList<KeyValuePair<string, object>> state;
20+
private readonly IReadOnlyList<KeyValuePair<string, object?>> state;
2121

22-
public MyClassWithRedactionEnumerator(IReadOnlyList<KeyValuePair<string, object>> state)
22+
public MyClassWithRedactionEnumerator(IReadOnlyList<KeyValuePair<string, object?>> state)
2323
{
2424
this.state = state;
2525
}
2626

2727
public int Count => this.state.Count;
2828

29-
public KeyValuePair<string, object> this[int index]
29+
public KeyValuePair<string, object?> this[int index]
3030
{
3131
get
3232
{
3333
var item = this.state[index];
3434
var entryVal = item.Value?.ToString();
3535
if (entryVal != null && entryVal.Contains("<secret>"))
3636
{
37-
return new KeyValuePair<string, object>(item.Key, "newRedactedValueHere");
37+
return new KeyValuePair<string, object?>(item.Key, "newRedactedValueHere");
3838
}
3939

4040
return item;
4141
}
4242
}
4343

44-
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
44+
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
4545
{
4646
for (var i = 0; i < this.Count; i++)
4747
{

docs/logs/redaction/redaction.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<!-- this is temporary. will remove in future PR. -->
4-
<Nullable>disable</Nullable>
5-
</PropertyGroup>
62
<ItemGroup>
73
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Console\OpenTelemetry.Exporter.Console.csproj" />
84
</ItemGroup>

docs/trace/customizing-the-sdk/customizing-the-sdk.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<!-- this is temporary. will remove in future PR. -->
4-
<Nullable>disable</Nullable>
5-
</PropertyGroup>
62
<ItemGroup>
73
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Console\OpenTelemetry.Exporter.Console.csproj" />
84
</ItemGroup>

examples/Console/Examples.Console.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>$(DefaultTargetFrameworkForExampleApps)</TargetFramework>
66
<NoWarn>$(NoWarn),CS0618</NoWarn>
7-
8-
<!-- this is temporary. will remove in future PR. -->
9-
<Nullable>disable</Nullable>
107
</PropertyGroup>
118

129
<ItemGroup>

examples/Console/InstrumentationWithActivitySource.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public void Start(string url)
4747
var context = this.listener.GetContext();
4848

4949
using var activity = source.StartActivity(
50-
$"{context.Request.HttpMethod}:{context.Request.Url.AbsolutePath}",
50+
$"{context.Request.HttpMethod}:{context.Request.Url!.AbsolutePath}",
5151
ActivityKind.Server);
5252

5353
var headerKeys = context.Request.Headers.AllKeys;
5454
foreach (var headerKey in headerKeys)
5555
{
56-
string headerValue = context.Request.Headers[headerKey];
56+
string? headerValue = context.Request.Headers[headerKey];
5757
activity?.SetTag($"http.header.{headerKey}", headerValue);
5858
}
5959

@@ -62,7 +62,7 @@ public void Start(string url)
6262
using (var reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding))
6363
{
6464
requestContent = reader.ReadToEnd();
65-
childSpan.AddEvent(new ActivityEvent("StreamReader.ReadToEnd"));
65+
childSpan?.AddEvent(new ActivityEvent("StreamReader.ReadToEnd"));
6666
}
6767

6868
activity?.SetTag("request.content", requestContent);
@@ -90,8 +90,8 @@ public void Dispose()
9090

9191
private class SampleClient : IDisposable
9292
{
93-
private CancellationTokenSource cts;
94-
private Task requestTask;
93+
private CancellationTokenSource? cts;
94+
private Task? requestTask;
9595

9696
public void Start(string url)
9797
{
@@ -154,7 +154,7 @@ public void Dispose()
154154
if (this.cts != null)
155155
{
156156
this.cts.Cancel();
157-
this.requestTask.Wait();
157+
this.requestTask!.Wait();
158158
this.requestTask.Dispose();
159159
this.cts.Dispose();
160160
}

examples/Console/Program.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ public static void Main(string[] args)
3333
{
3434
Parser.Default.ParseArguments<ZipkinOptions, PrometheusOptions, MetricsOptions, LogsOptions, GrpcNetClientOptions, HttpClientOptions, ConsoleOptions, OpenTelemetryShimOptions, OpenTracingShimOptions, OtlpOptions, InMemoryOptions>(args)
3535
.MapResult(
36-
(ZipkinOptions options) => TestZipkinExporter.Run(options.Uri),
37-
(PrometheusOptions options) => TestPrometheusExporter.Run(options.Port),
36+
(ZipkinOptions options) => TestZipkinExporter.Run(options),
37+
(PrometheusOptions options) => TestPrometheusExporter.Run(options),
3838
(MetricsOptions options) => TestMetrics.Run(options),
3939
(LogsOptions options) => TestLogs.Run(options),
40-
(GrpcNetClientOptions options) => TestGrpcNetClient.Run(),
41-
(HttpClientOptions options) => TestHttpClient.Run(),
40+
(GrpcNetClientOptions options) => TestGrpcNetClient.Run(options),
41+
(HttpClientOptions options) => TestHttpClient.Run(options),
4242
(ConsoleOptions options) => TestConsoleExporter.Run(options),
4343
(OpenTelemetryShimOptions options) => TestOTelShimWithConsoleExporter.Run(options),
4444
(OpenTracingShimOptions options) => TestOpenTracingShim.Run(options),
45-
(OtlpOptions options) => TestOtlpExporter.Run(options.Endpoint, options.Protocol),
45+
(OtlpOptions options) => TestOtlpExporter.Run(options),
4646
(InMemoryOptions options) => TestInMemoryExporter.Run(options),
4747
errs => 1);
4848
}
@@ -54,7 +54,7 @@ public static void Main(string[] args)
5454
internal class ZipkinOptions
5555
{
5656
[Option('u', "uri", HelpText = "Please specify the uri of Zipkin backend", Required = true)]
57-
public string Uri { get; set; }
57+
public required string Uri { get; set; }
5858
}
5959

6060
[Verb("prometheus", HelpText = "Specify the options required to test Prometheus")]
@@ -83,10 +83,10 @@ internal class MetricsOptions
8383
public int DefaultCollectionPeriodMilliseconds { get; set; }
8484

8585
[Option("useExporter", Default = "console", HelpText = "Options include otlp or console.", Required = false)]
86-
public string UseExporter { get; set; }
86+
public string? UseExporter { get; set; }
8787

8888
[Option('e', "endpoint", HelpText = "Target to which the exporter is going to send metrics (default value depends on protocol).", Default = null)]
89-
public string Endpoint { get; set; }
89+
public string? Endpoint { get; set; }
9090

9191
[Option('p', "useGrpc", HelpText = "Use gRPC or HTTP when using the OTLP exporter", Required = false, Default = true)]
9292
public bool UseGrpc { get; set; }
@@ -121,26 +121,26 @@ internal class OpenTracingShimOptions
121121
internal class OtlpOptions
122122
{
123123
[Option('e', "endpoint", HelpText = "Target to which the exporter is going to send traces (default value depends on protocol).", Default = null)]
124-
public string Endpoint { get; set; }
124+
public string? Endpoint { get; set; }
125125

126126
[Option('p', "protocol", HelpText = "Transport protocol used by exporter. Supported values: grpc and http/protobuf.", Default = "grpc")]
127-
public string Protocol { get; set; }
127+
public string? Protocol { get; set; }
128128
}
129129

130130
[Verb("logs", HelpText = "Specify the options required to test Logs")]
131131
internal class LogsOptions
132132
{
133133
[Option("useExporter", Default = "otlp", HelpText = "Options include otlp or console.", Required = false)]
134-
public string UseExporter { get; set; }
134+
public string? UseExporter { get; set; }
135135

136136
[Option('e', "endpoint", HelpText = "Target to which the OTLP exporter is going to send logs (default value depends on protocol).", Default = null)]
137-
public string Endpoint { get; set; }
137+
public string? Endpoint { get; set; }
138138

139139
[Option('p', "protocol", HelpText = "Transport protocol used by OTLP exporter. Supported values: grpc and http/protobuf. Only applicable if Exporter is OTLP", Default = "grpc")]
140-
public string Protocol { get; set; }
140+
public string? Protocol { get; set; }
141141

142142
[Option("processorType", Default = "batch", HelpText = "export processor type. Supported values: simple and batch", Required = false)]
143-
public string ProcessorType { get; set; }
143+
public string? ProcessorType { get; set; }
144144

145145
[Option("scheduledDelay", Default = 5000, HelpText = "The delay interval in milliseconds between two consecutive exports.", Required = false)]
146146
public int ScheduledDelayInMilliseconds { get; set; }

examples/Console/TestConsoleExporter.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ internal class TestConsoleExporter
1515
// (eg: C:\repos\opentelemetry-dotnet\examples\Console\)
1616
//
1717
// dotnet run console
18-
internal static object Run(ConsoleOptions options)
18+
internal static int Run(ConsoleOptions options)
1919
{
2020
return RunWithActivitySource();
2121
}
2222

23-
private static object RunWithActivitySource()
23+
private static int RunWithActivitySource()
2424
{
2525
// Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
2626
// and use Console exporter.
2727
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
28-
.AddSource("Samples.SampleClient", "Samples.SampleServer")
29-
.ConfigureResource(res => res.AddService("console-test"))
30-
.AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter
31-
.AddConsoleExporter()
32-
.Build();
28+
.AddSource("Samples.SampleClient", "Samples.SampleServer")
29+
.ConfigureResource(res => res.AddService("console-test"))
30+
.AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter
31+
.AddConsoleExporter()
32+
.Build();
3333

3434
// The above line is required only in applications
3535
// which decide to use OpenTelemetry.
@@ -43,7 +43,7 @@ private static object RunWithActivitySource()
4343
System.Console.ReadLine();
4444
}
4545

46-
return null;
46+
return 0;
4747
}
4848

4949
/// <summary>

examples/Console/TestGrpcNetClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ namespace Examples.Console;
1212

1313
internal class TestGrpcNetClient
1414
{
15-
internal static object Run()
15+
internal static int Run(GrpcNetClientOptions options)
1616
{
17+
Debug.Assert(options != null, "options was null");
18+
1719
// Prerequisite for running this example.
1820
// In a separate console window, start the example
1921
// ASP.NET Core gRPC service by running the following command
@@ -55,6 +57,6 @@ internal static object Run()
5557
System.Console.WriteLine("Press Enter key to exit.");
5658
System.Console.ReadLine();
5759

58-
return null;
60+
return 0;
5961
}
6062
}

examples/Console/TestHttpClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ internal class TestHttpClient
1515
// (eg: C:\repos\opentelemetry-dotnet\examples\Console\)
1616
//
1717
// dotnet run httpclient
18-
internal static object Run()
18+
internal static int Run(HttpClientOptions options)
1919
{
20+
Debug.Assert(options != null, "options was null");
21+
2022
System.Console.WriteLine("Hello World!");
2123

2224
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
@@ -36,6 +38,6 @@ internal static object Run()
3638
System.Console.WriteLine("Press Enter key to exit.");
3739
System.Console.ReadLine();
3840

39-
return null;
41+
return 0;
4042
}
4143
}

0 commit comments

Comments
 (0)