-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
distributedtracing: adding distributed tracing resource attributes #6947
distributedtracing: adding distributed tracing resource attributes #6947
Conversation
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
8ce9fed
to
e2a9443
Compare
9baba2d
to
f8ee0b3
Compare
You can add tests here. |
@@ -99,7 +101,13 @@ func Init(ctx context.Context, raw []byte, id string) (*otlptrace.Exporter, *tra | |||
tlsOption, | |||
) | |||
|
|||
attrs := make([]attribute.KeyValue, len(distributedTracingConfig.ResourceAttributes)) | |||
for key, value := range distributedTracingConfig.ResourceAttributes { | |||
attrs = append(attrs, attribute.String(key, value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can resource attributes be any key value pair or do we need to do some validation here? For example, they must follow some naming convention, only some defined keys like service.namespace
, service.version
, service.name
and service.instance.id
can be used etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be any key-value pair. The opentelemetry spec defines some well-known resource attributes, but any key is allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note I've updated to allow a variety of data types for value (int, float, string, bool)
@ashutosh-narkar I didn't find those tests useful for testing this feature, since the code in I did try altering |
if err == nil { | ||
attrs = append(attrs, attribute.Float64(key, num)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we return an error if we can't convert to float64 or int?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, done.
@brettmc I'm seeing unrelated changes included in your PR. Maybe something went wrong when you synced with |
588b7a0
to
ee1e25e
Compare
I was checking how other go-based apps with in-built OpenTelemetry do their config, and found https://docs.roadrunner.dev/docs/logging-and-observability/otel#configuration - this one only exposes a couple of the well-known attributes from the spec. |
I think that is a good approach to start. Just support the well-known ones for now. |
7436649
to
e14a593
Compare
Done. I think I'm happy with this PR now. |
@@ -5296,6 +5296,23 @@ func TestDistributedTracingEnabled(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestDistributedTracingResourceAttributes(t *testing.T) { | |||
c := []byte(`{"distributed_tracing": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to add "type": "grpc",
here. Otherwise if you look at the Init
method, this test currently is not exercising your new code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Adding a resource map to the distributed_tracing config. Entries in this map will be passed through to the OpenTelemetry SDK where they will be added as resource attributes. The available resource attributes are service.namespace, service.version and service.instance.id. see https://opentelemetry.io/docs/specs/semconv/resource/ Fixes: open-policy-agent#6492 Signed-off-by: Brett McBride <brett@deakin.edu.au>
Signed-off-by: Brett McBride <brett@deakin.edu.au>
Signed-off-by: Brett McBride <brett@deakin.edu.au>
909ab92
to
92b48d3
Compare
Adding a resource_attributes map to the distributed_tracing config. Entries in this map will be passed through to the OpenTelemetry SDK where they will be added as resource attributes. Resource attributes are typically service.namespace, service.version, service.name and service.instance.id, see https://opentelemetry.io/docs/specs/semconv/resource/
Fixes: #6942
Why the changes in this PR are needed?
Allows extra OpenTelemetry resource attributes to be added to a trace, such as service.namespace
What are the changes in this PR?
Adds an optional config
distributed_tracing.resource_attributes
, which is map of strings. Values here areadded via the opentelemetry SDK as resource attributes.
Notes to assist PR review:
I didn't find any tests which verify the telemetry (trace) output, but I did apply the following config and observe this output:
config:
output in opentelemetry collector:
NB resource attributes, and that service_name takes precedence over resource_attributes."service.name"