How to send OPA Decision Logs to OpenTelemetry #447
Replies: 2 comments 3 replies
-
Hi @awalmsley! There's no support for that in OPA currently. If you'd want to implement that you could either write a custom plugin as you suggest, or write a proxy server that receives the decision logs from OPAs HTTP client, and then forwards (and possibly transforms) the messages to whatever backend you desire. The latter has the benefit of not having to maintain a custom version of OPA, but OTOH it obviously adds another component too. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for the advice. I'm trying the Custom Decision Log Plugin approach. I'm using the OpenTelemetry-Go SDK to send the decision log events to OTel. I couldn't find a way to send the logs without attaching the log entries to trace spans. There must be a simpler way (??). The spans add a lot of unnecessary detail.. import (
...
"go.opentelemetry.io/otel"
)
...
// Log is called by the decision logger when a record (event) should be emitted. The logs.EventV1 fields
// map 1:1 to those described in https://www.openpolicyagent.org/docs/latest/management-decision-logs
func (d *DecisionLogger) Log(ctx context.Context, event logs.EventV1) error {
jsonData, err := json.MarshalIndent(event, "", " ")
if err != nil {
fmt.Printf("Could not marshal json: %s\n", err)
return err
}
...
tracer := otel.Tracer("decision-log-tracer")
ctx, span := tracer.Start(ctx, "decision-log-span")
defer span.End()
attrs := []attribute.KeyValue{
attribute.String("decision-log", string(jsonData)),
}
span.AddEvent("decision-log-event", trace.WithAttributes(attrs...))
... The traces are sent to an OpenTelemetry collector, using an OLTP receiver. Here's what the decsion logs look like in the OTel container logs. Haven't had to add any translation logic yet..
|
Beta Was this translation helpful? Give feedback.
-
Hello, I want to send OPA Decision logs to AWS CloudWatch via OpenTelemetry, looking for suggestions to implement this. Is there any support built in to OPA, or would it be necessary to implement a custom plugin. Are there any examples of doing this? any suggestions welcome
Beta Was this translation helpful? Give feedback.
All reactions