Skip to content

Commit

Permalink
[AzureMonitorDistro] Remove logs sampling. (Azure#44745)
Browse files Browse the repository at this point in the history
* Remove logs sampling.

* changelog update

* pr feedback - changelog
  • Loading branch information
rajkumar-rangaraj authored and tejasm-microsoft committed Jul 21, 2024
1 parent 1421307 commit 571a815
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
(This feature was originally introduced in 1.2.0-beta.2)
([#44511](https://github.com/Azure/azure-sdk-for-net/pull/44511))

* Added an experimental feature for logs emitted within an active tracing context to follow the Activity's sampling decision.
The feature can be enabled by setting `OTEL_DOTNET_AZURE_MONITOR_EXPERIMENTAL_ENABLE_LOG_SAMPLING` environment variable to `true`.
(This feature was originally introduced in 1.2.0-beta.1)
([#44511](https://github.com/Azure/azure-sdk-for-net/pull/44511))

* Update OpenTelemetry dependencies.
([#44650](https://github.com/Azure/azure-sdk-for-net/pull/44650))
- OpenTelemetry 1.9.0
Expand All @@ -35,6 +30,10 @@
Code has been updated to [1.0.0-beta.8](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/Resources.Azure-1.0.0-beta.8/src/OpenTelemetry.Resources.Azure).
([#44682](https://github.com/Azure/azure-sdk-for-net/pull/44682))

* Removed an experimental feature for logs emitted within an active tracing context to follow the Activity's sampling decision.
(This feature was originally introduced in 1.2.0-beta.1)
([#44745](https://github.com/Azure/azure-sdk-for-net/pull/44745))

## 1.2.0 (2024-06-11)

### Other Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,11 @@ public void ConfigureFailed(System.Exception ex)
[Event(4, Message = "Vendor instrumentation added for: {0}.", Level = EventLevel.Verbose)]
public void VendorInstrumentationAdded(string packageName) => WriteEvent(4, packageName);

[NonEvent]
public void GetEnvironmentVariableFailed(string envVarName, System.Exception ex)
{
if (IsEnabled(EventLevel.Error))
{
GetEnvironmentVariableFailed(envVarName, ex.FlattenException().ToInvariantString());
}
}

[Event(5, Message = "Failed to Read environment variable {0}, exception: {1}", Level = EventLevel.Error)]
public void GetEnvironmentVariableFailed(string envVarName, string exceptionMessage) => WriteEvent(5, envVarName, exceptionMessage);

[Event(6, Message = "Failed to map unknown EventSource log level in AzureEventSourceLogForwarder {0}", Level = EventLevel.Warning)]
public void MapLogLevelFailed(string level) => WriteEvent(6, level);
[Event(5, Message = "Failed to map unknown EventSource log level in AzureEventSourceLogForwarder {0}", Level = EventLevel.Warning)]
public void MapLogLevelFailed(string level) => WriteEvent(5, level);

[Event(7, Message = "Found existing Microsoft.Extensions.Azure.AzureEventSourceLogForwarder registration.", Level = EventLevel.Informational)]
public void LogForwarderIsAlreadyRegistered() => WriteEvent(7);
[Event(6, Message = "Found existing Microsoft.Extensions.Azure.AzureEventSourceLogForwarder registration.", Level = EventLevel.Informational)]
public void LogForwarderIsAlreadyRegistered() => WriteEvent(6);

[NonEvent]
public void FailedToParseConnectionString(System.Exception ex)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public static class OpenTelemetryBuilderExtensions
{
private const string SqlClientInstrumentationPackageName = "OpenTelemetry.Instrumentation.SqlClient";

private const string EnableLogSamplingEnvVar = "OTEL_DOTNET_AZURE_MONITOR_EXPERIMENTAL_ENABLE_LOG_SAMPLING";

/// <summary>
/// Configures Azure Monitor for logging, distributed tracing, and metrics.
/// </summary>
Expand Down Expand Up @@ -135,39 +133,24 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
builder.WithLogging(
logging => logging.AddProcessor(sp =>
{
bool enableLogSampling = false;
try
{
var enableLogSamplingEnvVar = Environment.GetEnvironmentVariable(EnableLogSamplingEnvVar);
bool.TryParse(enableLogSamplingEnvVar, out enableLogSampling);
}
catch (Exception ex)
{
AzureMonitorAspNetCoreEventSource.Log.GetEnvironmentVariableFailed(EnableLogSamplingEnvVar, ex);
}

var azureMonitorOptions = sp.GetRequiredService<IOptionsMonitor<AzureMonitorOptions>>().CurrentValue;
var azureMonitorExporterOptions = new AzureMonitorExporterOptions();
azureMonitorOptions.SetValueToExporterOptions(azureMonitorExporterOptions);

var exporter = new AzureMonitorLogExporter(azureMonitorExporterOptions);
var logProcessor = enableLogSampling
? new LogFilteringProcessor(exporter)
: new BatchLogRecordExportProcessor(exporter);

if (azureMonitorOptions.EnableLiveMetrics)
{
var manager = sp.GetRequiredService<Manager>();
var liveMetricsProcessor = new LiveMetricsLogProcessor(manager);

return new CompositeProcessor<LogRecord>(new BaseProcessor<LogRecord>[]
{
liveMetricsProcessor,
logProcessor
new LiveMetricsLogProcessor(manager),
new BatchLogRecordExportProcessor(exporter)
});
}

return logProcessor;
return new BatchLogRecordExportProcessor(exporter);
}),
options => options.IncludeFormattedMessage = true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
using System.Collections.Generic;
using System.Linq;
using Xunit.Abstractions;
using OpenTelemetry.Logs;
using OpenTelemetry;
using System.Reflection;

namespace Azure.Monitor.OpenTelemetry.AspNetCore.Tests
{
Expand Down Expand Up @@ -80,45 +77,6 @@ public async Task ValidateTelemetryExport()
// TODO: This test needs to assert telemetry content. (ie: sample rate)
}

[Theory(Skip = "TODO: Ordering needs to be fixed for processor in this test.")]
[InlineData(null)]
[InlineData("true")]
[InlineData("True")]
[InlineData("False")]
[InlineData("false")]
public void ValidateLogFilteringProcessorIsAddedToLoggerProvider(string enableLogSampling)
{
try
{
Environment.SetEnvironmentVariable("OTEL_DOTNET_AZURE_MONITOR_EXPERIMENTAL_ENABLE_LOG_SAMPLING", enableLogSampling);

var sv = new ServiceCollection();
sv.AddOpenTelemetry().UseAzureMonitor(o => o.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000");

var sp = sv.BuildServiceProvider();
var loggerProvider = sp.GetRequiredService<ILoggerProvider>();
var sdkProvider = typeof(OpenTelemetryLoggerProvider).GetField("Provider", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(loggerProvider);
var processor = sdkProvider?.GetType().GetProperty("Processor", BindingFlags.Instance | BindingFlags.Public)?.GetMethod?.Invoke(sdkProvider, null);

Assert.NotNull(processor);

if (enableLogSampling != null && enableLogSampling.Equals("true" , StringComparison.OrdinalIgnoreCase))
{
Assert.True(processor is LogFilteringProcessor);
Assert.True(processor is BatchLogRecordExportProcessor);
}
else
{
Assert.True(processor is not LogFilteringProcessor);
Assert.True(processor is BatchLogRecordExportProcessor);
}
}
finally
{
Environment.SetEnvironmentVariable("OTEL_DOTNET_AZURE_MONITOR_EXPERIMENTAL_ENABLE_LOG_SAMPLING", null);
}
}

private void WaitForRequest(MockTransport transport)
{
SpinWait.SpinUntil(
Expand Down

0 comments on commit 571a815

Please # to comment.