-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
880 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.microsoft.applicationinsights.agent.internal.processors; | ||
|
||
import com.microsoft.applicationinsights.agent.internal.processors.AgentProcessor.IncludeExclude; | ||
import com.microsoft.applicationinsights.agent.internal.wasbootstrap.configuration.Configuration.ProcessorConfig; | ||
import com.microsoft.applicationinsights.customExceptions.FriendlyException; | ||
import io.opentelemetry.sdk.common.CompletableResultCode; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.opentelemetry.sdk.trace.export.SpanExporter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class ExporterWithLogProcessor implements SpanExporter { | ||
|
||
private final SpanExporter delegate; | ||
private final SpanProcessor logProcessor; | ||
|
||
// caller should check config.isValid before creating | ||
public ExporterWithLogProcessor(ProcessorConfig config, SpanExporter delegate) throws FriendlyException { | ||
config.validate(); | ||
logProcessor = SpanProcessor.create(config); | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public CompletableResultCode export(Collection<SpanData> spans) { | ||
// we need to filter attributes before passing on to delegate | ||
|
||
List<SpanData> copy = new ArrayList<>(); | ||
for (SpanData span : spans) { | ||
copy.add(process(span)); | ||
} | ||
return delegate.export(copy); | ||
|
||
} | ||
|
||
private SpanData process(SpanData span) { | ||
IncludeExclude include = logProcessor.getInclude(); | ||
if(!ProcessorUtil.isSpanOfTypeLog(span)) { | ||
return span; | ||
} | ||
if (include != null && !include.isMatch(span, true)) { | ||
//If Not included we can skip further processing | ||
return span; | ||
} | ||
IncludeExclude exclude = logProcessor.getExclude(); | ||
if (exclude != null && exclude.isMatch(span, true)) { | ||
return span; | ||
} | ||
|
||
SpanData updatedSpan = logProcessor.processFromAttributes(span); | ||
return logProcessor.processToAttributes(updatedSpan); | ||
} | ||
|
||
@Override | ||
public CompletableResultCode flush() { | ||
return delegate.flush(); | ||
} | ||
|
||
@Override | ||
public CompletableResultCode shutdown() { | ||
return delegate.shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
.../main/java/com/microsoft/applicationinsights/agent/internal/processors/ProcessorUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.microsoft.applicationinsights.agent.internal.processors; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
|
||
public class ProcessorUtil { | ||
private static final AttributeKey<Boolean> AI_LOG_KEY = AttributeKey.booleanKey("applicationinsights.internal.log"); | ||
public static boolean isSpanOfTypeLog(SpanData span) { | ||
Boolean isLog = span.getAttributes().get(AI_LOG_KEY); | ||
return isLog != null && isLog; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.