Skip to content

Commit

Permalink
cleanup nullable in Exporter classes
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMothra committed Feb 7, 2023
1 parent 4c57525 commit b6eb01b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable disable // TODO: remove and fix errors

using System;
using System.Threading;
using Azure.Core;
Expand All @@ -18,10 +16,10 @@ internal class AzureMonitorLogExporter : BaseExporter<LogRecord>
{
private readonly ITransmitter _transmitter;
private readonly string _instrumentationKey;
private readonly AzureMonitorPersistentStorage _persistentStorage;
private AzureMonitorResource _resource;
private readonly AzureMonitorPersistentStorage? _persistentStorage;
private AzureMonitorResource? _resource;

public AzureMonitorLogExporter(AzureMonitorExporterOptions options, TokenCredential credential = null) : this(new AzureMonitorTransmitter(options, credential))
public AzureMonitorLogExporter(AzureMonitorExporterOptions options, TokenCredential? credential = null) : this(new AzureMonitorTransmitter(options, credential))
{
}

Expand All @@ -34,9 +32,13 @@ internal AzureMonitorLogExporter(ITransmitter transmitter)
{
_persistentStorage = new AzureMonitorPersistentStorage(transmitter);
}
else
{
_persistentStorage = null;
}
}

internal AzureMonitorResource LogResource => _resource ??= ParentProvider.GetResource().UpdateRoleNameAndInstance();
internal AzureMonitorResource? LogResource => _resource ??= ParentProvider?.GetResource().UpdateRoleNameAndInstance();

/// <inheritdoc/>
public override ExportResult Export(in Batch<LogRecord> batch)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable disable // TODO: remove and fix errors

using System;
using System.Threading;
using Azure.Core;
Expand All @@ -18,10 +16,10 @@ internal class AzureMonitorMetricExporter : BaseExporter<Metric>
{
private readonly ITransmitter _transmitter;
private readonly string _instrumentationKey;
private readonly AzureMonitorPersistentStorage _persistentStorage;
private AzureMonitorResource _resource;
private readonly AzureMonitorPersistentStorage? _persistentStorage;
private AzureMonitorResource? _resource;

public AzureMonitorMetricExporter(AzureMonitorExporterOptions options, TokenCredential credential = null) : this(new AzureMonitorTransmitter(options, credential))
public AzureMonitorMetricExporter(AzureMonitorExporterOptions options, TokenCredential? credential = null) : this(new AzureMonitorTransmitter(options, credential))
{
}

Expand All @@ -34,9 +32,13 @@ internal AzureMonitorMetricExporter(ITransmitter transmitter)
{
_persistentStorage = new AzureMonitorPersistentStorage(transmitter);
}
else
{
_persistentStorage = null;
}
}

internal AzureMonitorResource MetricResource => _resource ??= ParentProvider.GetResource().UpdateRoleNameAndInstance();
internal AzureMonitorResource? MetricResource => _resource ??= ParentProvider?.GetResource().UpdateRoleNameAndInstance();

/// <inheritdoc/>
public override ExportResult Export(in Batch<Metric> batch)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable disable // TODO: remove and fix errors

using System;
using System.Diagnostics;
using System.Threading;
Expand All @@ -18,10 +16,10 @@ internal class AzureMonitorTraceExporter : BaseExporter<Activity>
{
private readonly ITransmitter _transmitter;
private readonly string _instrumentationKey;
private readonly AzureMonitorPersistentStorage _persistentStorage;
private AzureMonitorResource _resource;
private readonly AzureMonitorPersistentStorage? _persistentStorage;
private AzureMonitorResource? _resource;

public AzureMonitorTraceExporter(AzureMonitorExporterOptions options, TokenCredential credential = null) : this(new AzureMonitorTransmitter(options, credential))
public AzureMonitorTraceExporter(AzureMonitorExporterOptions options, TokenCredential? credential = null) : this(new AzureMonitorTransmitter(options, credential))
{
}

Expand All @@ -34,9 +32,13 @@ internal AzureMonitorTraceExporter(ITransmitter transmitter)
{
_persistentStorage = new AzureMonitorPersistentStorage(transmitter);
}
else
{
_persistentStorage = null;
}
}

internal AzureMonitorResource TraceResource => _resource ??= ParentProvider.GetResource().UpdateRoleNameAndInstance();
internal AzureMonitorResource? TraceResource => _resource ??= ParentProvider?.GetResource().UpdateRoleNameAndInstance();

/// <inheritdoc/>
public override ExportResult Export(in Batch<Activity> batch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ public TelemetryItem (LogRecord logRecord, AzureMonitorResource resource, string
SetResourceSdkVersionAndIkey(resource, instrumentationKey);
}

public TelemetryItem(DateTime time, AzureMonitorResource resource, string instrumentationKey) : this("Metric", FormatUtcTimestamp(time))
public TelemetryItem(DateTime time, AzureMonitorResource? resource, string instrumentationKey) : this("Metric", FormatUtcTimestamp(time))
{
SetResourceSdkVersionAndIkey(resource, instrumentationKey);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetResourceSdkVersionAndIkey(AzureMonitorResource resource, string instrumentationKey)
private void SetResourceSdkVersionAndIkey(AzureMonitorResource? resource, string instrumentationKey)
{
InstrumentationKey = instrumentationKey;
Tags[ContextTagKeys.AiCloudRole.ToString()] = resource?.RoleName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class MetricHelper
{
private const int Version = 2;

internal static List<TelemetryItem> OtelToAzureMonitorMetrics(Batch<Metric> batch, AzureMonitorResource resource, string instrumentationKey)
internal static List<TelemetryItem> OtelToAzureMonitorMetrics(Batch<Metric> batch, AzureMonitorResource? resource, string instrumentationKey)
{
List<TelemetryItem> telemetryItems = new();
foreach (var metric in batch)
Expand Down

0 comments on commit b6eb01b

Please sign in to comment.