Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ internal void SetCloudRole(string serviceName, string serviceInstanceId = null,

internal FeatureMetricEmissionHelper InitializeFeatureReporter()
{
if (string.IsNullOrEmpty(this.connectionString))
{
return this.FeatureReporter;
}

var connectionString = Microsoft.ApplicationInsights.Internal.ConnectionString.Parse(this.ConnectionString);
var ciKey = connectionString.GetNonRequired("InstrumentationKey");
this.FeatureReporter = FeatureMetricEmissionHelper.GetOrCreate(ciKey, this.extensionVersion);
Expand All @@ -381,14 +386,27 @@ internal OpenTelemetrySdk Build()
return this.openTelemetrySdk;
}

// If no connection string was explicitly set, fall back to the environment variable.
if (string.IsNullOrEmpty(this.connectionString))
{
var envConnectionString = Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING");
if (!string.IsNullOrEmpty(envConnectionString))
{
this.connectionString = envConnectionString;
}
}

Environment.SetEnvironmentVariable("OTEL_SDK_DISABLED", this.disableTelemetry ? "true" : "false");

this.openTelemetrySdk = OpenTelemetrySdk.Create(builder =>
{
this.builderConfiguration(builder);
builder.SetAzureMonitorExporter(options =>
{
options.ConnectionString = this.connectionString;
if (!string.IsNullOrEmpty(this.connectionString))
{
options.ConnectionString = this.connectionString;
}

if (this.tracesPerSecond.HasValue)
{
Expand Down
5 changes: 5 additions & 0 deletions LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
base.InitializeTarget();

string connectionString = this.connectionStringLayout.Render(LogEventInfo.CreateNullEvent());
if (string.IsNullOrWhiteSpace(connectionString))
{
connectionString = Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING");
}

if (string.IsNullOrWhiteSpace(connectionString))
{
throw new NLogConfigurationException(ConnectionStringRequiredMessage);
Expand Down Expand Up @@ -187,7 +192,7 @@
/// <exception cref="ArgumentNullException">If <paramref name="logEvent"/> is null.</exception>
protected override void Write(LogEventInfo logEvent)
{
if (logEvent == null)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net10.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net10.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net9.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net9.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net480)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net480)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net481)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net481)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net462)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net462)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net472)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net472)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net8.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 195 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net8.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)
{
throw new ArgumentNullException(nameof(logEvent));
}
Expand Down Expand Up @@ -215,7 +220,7 @@
/// <param name="asyncContinuation">The asynchronous continuation.</param>
protected override void FlushAsync(AsyncContinuation asyncContinuation)
{
if (asyncContinuation == null)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net10.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net10.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net9.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net9.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net480)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net480)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net481)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net481)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net462)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net462)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net472)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net472)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net8.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 223 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs

View workflow job for this annotation

GitHub Actions / build-test-SHIM (windows-latest, net8.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)
{
throw new ArgumentNullException(nameof(asyncContinuation));
}
Expand Down
Loading