googleapis / googleapis/google-cloud-go
datastore: add attribute to trace
- Dominant language
- Go
- Stars
- 4.5k
- Forks
- 1.6k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 109
Description
**Is your feature request related to a problem? Please describe.**
When use [stackdriver exporter](https://pkg.go.dev/contrib.go.opencensus.io/exporter/stackdriver?tab=doc) and call datastore client public func (like datastore [*Client.Get](https://github.com/googleapis/google-cloud-go/blob/master/datastore/datastore.go#L330) ),
child span ( like `cloud.google.com/go/datastore.*`) added to our parent context(span).
But, added child span has no information like called `datastore.Key`, `datastore.Query`, etc...
It's more convenient if we can know which key or query related to child span.
**Describe the solution you'd like**
How about calling [*Span.AddAttributes](https://godoc.org/go.opencensus.io/trace#Span.AddAttributes) when child span started in datastore package?
**Describe alternatives you've considered**
- Is there any reason (like security reason) that google-cloud-go can't add attribute to stackdriver trace automaticaly?
- If answer is yes, how about adding explicitly interface to add attribute?
**Additional context**
- Similarly, I have same feature request for other storage (like spanner)
- I tried to execute local test that I modified datastore.go to use [trace.TracePrintf](https://github.com/googleapis/google-cloud-go/blob/master/internal/trace/trace.go#L90) ( internal used [trace.Annotatef](https://godoc.org/go.opencensus.io/trace#Span.Annotatef) ),
but nothing changed at stackdriver trace label's output.
```diff
func (c *Client) Get(ctx context.Context, key *Key, dst interface{}) (err error) {
ctx = trace.StartSpan(ctx, "cloud.google.com/go/datastore.Get")
defer func() { trace.EndSpan(ctx, err) }()
+ trace.TracePrintf(ctx, map[string]interface{}{"Key": key.String()}, "my test")
```
- I found [attribute size limits](https://cloud.google.com/trace/docs/quotas#trace-api-limit ) , so it's difficult to add long attribute text like query string .
Contributor guide
Assessment
This issue has not been assessed yet.