Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix processor ordering #3795

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Changes from 1 commit
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 @@ -56,7 +56,7 @@
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
import io.opentelemetry.sdk.logs.LogRecordProcessor;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import io.opentelemetry.sdk.metrics.Aggregation;
import io.opentelemetry.sdk.metrics.InstrumentSelector;
Expand All @@ -75,6 +75,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -236,6 +237,8 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
}
telemetryClient.setQuickPulse(quickPulse);

AtomicBoolean firstLogRecordProcessor = new AtomicBoolean(true);

autoConfiguration
.addPropertiesSupplier(
() -> {
Expand All @@ -258,6 +261,18 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
return props;
})
.addPropertiesCustomizer(new AiConfigCustomizer())
.addLogRecordProcessorCustomizer(
trask marked this conversation as resolved.
Show resolved Hide resolved
(logRecordProcessor, configProperties) -> {
if (firstLogRecordProcessor.getAndSet(false)) {
// hack to register log record processors in front of the batch log processor
heyams marked this conversation as resolved.
Show resolved Hide resolved
trask marked this conversation as resolved.
Show resolved Hide resolved
List<LogRecordProcessor> logRecordProcessors =
getLogRecordProcessors(configuration);
logRecordProcessors.add(logRecordProcessor);
return LogRecordProcessor.composite(
logRecordProcessors.toArray(new LogRecordProcessor[0]));
}
return logRecordProcessor;
})
.addSpanExporterCustomizer(
(spanExporter, configProperties) -> {
if (spanExporter instanceof AzureMonitorSpanExporterProvider.MarkerSpanExporter) {
Expand Down Expand Up @@ -286,9 +301,7 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
.addTracerProviderCustomizer(
(builder, otelConfig) -> configureTracing(builder, configuration))
.addMeterProviderCustomizer(
(builder, otelConfig) -> configureMetrics(builder, configuration))
.addLoggerProviderCustomizer(
(builder, otelConfig) -> configureLogging(builder, configuration));
(builder, otelConfig) -> configureMetrics(builder, configuration));

AiContextCustomizerHolder.setInstance(
new AiContextCustomizer<>(
Expand Down Expand Up @@ -617,28 +630,28 @@ private static List<ProcessorConfig> getSpanProcessorConfigs(Configuration confi
// QuickPulse is injected into the logging pipeline because QuickPulse displays exception
// telemetry and exception telemetry can be reported as either span events or as log records with
// an exception stack traces
private static SdkLoggerProviderBuilder configureLogging(
SdkLoggerProviderBuilder builder, Configuration configuration) {
private static List<LogRecordProcessor> getLogRecordProcessors(Configuration configuration) {
heyams marked this conversation as resolved.
Show resolved Hide resolved
List<LogRecordProcessor> logRecordProcessors = new ArrayList<>();

builder.addLogRecordProcessor(new AzureMonitorLogProcessor());
logRecordProcessors.add(new AzureMonitorLogProcessor());

if (ConfigurationBuilder.inAzureFunctionsWorker(System::getenv)) {
builder.addLogRecordProcessor(new AzureFunctionsLogProcessor());
logRecordProcessors.add(new AzureFunctionsLogProcessor());
}

if (!configuration.preview.inheritedAttributes.isEmpty()) {
builder.addLogRecordProcessor(
logRecordProcessors.add(
new InheritedAttributesLogProcessor(configuration.preview.inheritedAttributes));
}
// adding this even if there are no connectionStringOverrides, in order to support
// "ai.preview.connection_string" being set programmatically on CONSUMER spans
// (or "ai.preview.instrumentation_key" for backwards compatibility)
builder.addLogRecordProcessor(new InheritedConnectionStringLogProcessor());
logRecordProcessors.add(new InheritedConnectionStringLogProcessor());
// adding this even if there are no roleNameOverrides, in order to support
// "ai.preview.service_name" being set programmatically on CONSUMER spans
builder.addLogRecordProcessor(new InheritedRoleNameLogProcessor());
logRecordProcessors.add(new InheritedRoleNameLogProcessor());

return builder;
return logRecordProcessors;
}

private static LogRecordExporter createLogExporter(
Expand Down
Loading