Skip to content

Commit 1608fb9

Browse files
authoredNov 23, 2020
Add OPA result tag to custom OPA impl (#134)
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
1 parent 775c39f commit 1608fb9

File tree

1 file changed

+4
-0
lines changed
  • filter-custom-opa/src/main/java/org/hypertrace/agent/filter/opa/custom

1 file changed

+4
-0
lines changed
 

‎filter-custom-opa/src/main/java/org/hypertrace/agent/filter/opa/custom/CustomOpaLib.java

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.hypertrace.agent.filter.opa.custom;
1818

1919
import com.google.auto.service.AutoService;
20+
import io.opentelemetry.api.common.AttributeKey;
2021
import io.opentelemetry.api.trace.Span;
2122
import java.util.HashSet;
2223
import java.util.Map;
@@ -40,6 +41,8 @@
4041
public class CustomOpaLib implements Filter {
4142
private static final Logger log = LoggerFactory.getLogger(CustomOpaLib.class);
4243

44+
private static AttributeKey<String> OPA_RESULT = AttributeKey.stringKey("traceableai.opa.result");
45+
4346
private final OpaCommunicator opaCommunicator = new OpaCommunicator();
4447
private final Set<ICustomPolicyEvaluator> policyEvaluators = new HashSet<>();
4548

@@ -95,6 +98,7 @@ public FilterResult evaluateRequestHeaders(Span span, Map<String, String> header
9598
policyEvaluator ->
9699
policyEvaluator.allow(opaCommunicator.getBlockingData(), headers))
97100
.anyMatch(Boolean::booleanValue);
101+
span.setAttribute(OPA_RESULT, String.valueOf(allow));
98102
return allow ? ExecutionNotBlocked.INSTANCE : ExecutionBlocked.INSTANCE;
99103
}
100104

0 commit comments

Comments
 (0)