-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sampler to be used by the Azure endpoints (#195)
* Sampler to be used by the Azure endpoints * Fix local variable * Sampler to be used by the Azure endpoints * Filter Azure URLs * Bump azure-monitor-opentelemetry-exporter * Rollback Azure exporter bump * Add test about the issue and fix the implemenation * Don't instrument stats beat endpoints --------- Co-authored-by: Jean Bisutti <[email protected]>
- Loading branch information
1 parent
8dd6a78
commit 8da3553
Showing
5 changed files
with
167 additions
and
14 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
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
67 changes: 67 additions & 0 deletions
67
...c/main/java/io/quarkiverse/opentelemetry/exporter/azure/runtime/AzureEndpointSampler.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,67 @@ | ||
package io.quarkiverse.opentelemetry.exporter.azure.runtime; | ||
|
||
import java.util.List; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.trace.data.LinkData; | ||
import io.opentelemetry.sdk.trace.samplers.Sampler; | ||
import io.opentelemetry.sdk.trace.samplers.SamplingResult; | ||
import io.opentelemetry.semconv.SemanticAttributes; | ||
|
||
/** | ||
* Sampler that drops spans based on the target of the request. | ||
* Inspired by {@link io.quarkus.opentelemetry.runtime.tracing.DropTargetsSampler} | ||
*/ | ||
public class AzureEndpointSampler implements Sampler { | ||
|
||
private final List<String> dropTargets; | ||
|
||
public AzureEndpointSampler(final List<String> dropTargets) { | ||
this.dropTargets = dropTargets; | ||
} | ||
|
||
@Override | ||
public SamplingResult shouldSample(Context context, | ||
String s, | ||
String s1, | ||
SpanKind spanKind, | ||
Attributes attributes, | ||
List<LinkData> list) { | ||
if (spanKind.equals(SpanKind.CLIENT)) { | ||
String target = attributes.get(SemanticAttributes.HTTP_URL); | ||
if (target == null) { | ||
target = attributes.get(SemanticAttributes.URL_FULL); | ||
} | ||
if (shouldDrop(target)) { | ||
return SamplingResult.drop(); | ||
} | ||
} | ||
return Sampler.alwaysOn().shouldSample(context, s, s1, spanKind, attributes, list); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "azure-endpoint-sampler"; | ||
} | ||
|
||
private boolean shouldDrop(String target) { | ||
if ((target == null) || target.isEmpty()) { | ||
return false; | ||
} | ||
if (safeContains(target)) { // check exact match | ||
return true; | ||
} | ||
if (target.charAt(target.length() - 1) == '/') { // check if the path without the ending slash matched | ||
if (safeContains(target.substring(0, target.length() - 1))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private boolean safeContains(String target) { | ||
return dropTargets.contains(target); | ||
} | ||
} |
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