Skip to content

Commit

Permalink
renamed LogRecordLabelSupplier to LogRecordLabelExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Boshier committed Oct 4, 2024
1 parent ec64e17 commit 8cc5ab7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/logging.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ By default, this will also be set on the Google Cloud Operations log entry as a

=== Custom Labels

In order to include additional labels in the log, you must bind a `LogRecordLabelSupplier` to the CDI context, e.g.:
In order to include additional labels in the log, you must bind a `LogRecordLabelExtractor` to the CDI context, e.g.:

[source,java]
----
Expand All @@ -155,14 +155,14 @@ import javax.enterprise.context.ApplicationScoped;
import org.jboss.logmanager.ExtLogRecord;
import io.quarkiverse.googlecloudservices.logging.runtime.LogRecordLabelSupplier;
import io.quarkiverse.googlecloudservices.logging.runtime.LogRecordLabelExtractor;
@ApplicationScoped
public class LogLabelSupplier implements LogRecordLabelSupplier {
public class LogLabelExtractor implements LogRecordLabelExtractor {
@Override
public Map<String, String> getCustomLabels(ExtLogRecord extLogRecord) {
return Map.of(/* something, something */);
return Map.of(/* some label, some value */);
}
}
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import io.quarkiverse.googlecloudservices.logging.runtime.LogRecordLabelSupplier;
import io.quarkiverse.googlecloudservices.logging.runtime.LogRecordLabelExtractor;
import io.quarkiverse.googlecloudservices.logging.runtime.LoggingConfiguration;
import io.quarkiverse.googlecloudservices.logging.runtime.TraceInfoExtractor;
import io.quarkiverse.googlecloudservices.logging.runtime.cdi.LoggingProducer;
Expand Down Expand Up @@ -36,7 +36,7 @@ public UnremovableBeanBuildItem helperClasses() {
return UnremovableBeanBuildItem.beanTypes(
TraceInfoExtractor.class,
LoggingConfiguration.class,
LogRecordLabelSupplier.class);
LogRecordLabelExtractor.class);
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

/**
* Bind an instance of this interface to include additional labels
* in the log record. You should only bind one supplier in the CDI context.
* in the log record. You should only bind one extractor in the CDI context.
*/
public interface LogRecordLabelSupplier {
public interface LogRecordLabelExtractor {

/**
* Supply additional labels for a log record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class LoggingHandler extends ExtHandler {
private WriteOption[] defaultWriteOptions;
private InternalHandler internalHandler;
private TraceInfoExtractor traceExtractor;
private LogRecordLabelSupplier logRecordLabelSupplier;
private LogRecordLabelExtractor logRecordLabelExtractor;

public LoggingHandler(LoggingConfiguration config) {
this.config = config;
Expand Down Expand Up @@ -85,7 +85,7 @@ private LogEntry transform(ExtLogRecord record, TraceInfo trace) {
.setSeverity(LevelTransformer.toSeverity(record.getLevel()))
.setTimestamp(record.getInstant());

final Map<String, String> customLabels = logRecordLabelSupplier.getCustomLabels(record);
final Map<String, String> customLabels = logRecordLabelExtractor.getCustomLabels(record);

if (customLabels != null) {
for (Map.Entry<String, String> entry : customLabels.entrySet()) {
Expand Down Expand Up @@ -130,18 +130,18 @@ private synchronized Logging initGetLogging() {
initInternalHandler();
// init trace extractor
initTraceExtractor();
// init log record label supplier
initLogRecordLabelSupplier();
// init log record label extractor
initLogRecordLabelExtractor();
}
return log;
}

private void initLogRecordLabelSupplier() {
InstanceHandle<LogRecordLabelSupplier> handle = Arc.container().instance(LogRecordLabelSupplier.class);
private void initLogRecordLabelExtractor() {
InstanceHandle<LogRecordLabelExtractor> handle = Arc.container().instance(LogRecordLabelExtractor.class);
if (handle.isAvailable()) {
this.logRecordLabelSupplier = handle.get();
this.logRecordLabelExtractor = handle.get();
} else {
this.logRecordLabelSupplier = s -> Collections.emptyMap();
this.logRecordLabelExtractor = s -> Collections.emptyMap();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ private ArcContainer createArcContainer(String traceId, String spanId) {
when(traceInfoInstanceHandler.isAvailable()).thenReturn(true);
when(container.instance(TraceInfoExtractor.class)).thenReturn(traceInfoInstanceHandler);

InstanceHandle<LogRecordLabelSupplier> logRecordLabelSupplierInstanceHandler = Mockito.mock(InstanceHandle.class);
when(logRecordLabelSupplierInstanceHandler.get()).thenReturn(x -> Map.of("label1", "value1", "label2", "value2"));
when(logRecordLabelSupplierInstanceHandler.isAvailable()).thenReturn(true);
when(container.instance(LogRecordLabelSupplier.class)).thenReturn(logRecordLabelSupplierInstanceHandler);
InstanceHandle<LogRecordLabelExtractor> logRecordLabelExtractorInstanceHandle = Mockito.mock(InstanceHandle.class);
when(logRecordLabelExtractorInstanceHandle.get()).thenReturn(x -> Map.of("label1", "value1", "label2", "value2"));
when(logRecordLabelExtractorInstanceHandle.isAvailable()).thenReturn(true);
when(container.instance(LogRecordLabelExtractor.class)).thenReturn(logRecordLabelExtractorInstanceHandle);

InstanceHandle<Logging> loggingInstanceHandler = Mockito.mock(InstanceHandle.class);
Logging logging = Mockito.mock(Logging.class);
Expand Down

0 comments on commit 8cc5ab7

Please sign in to comment.