Skip to content
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

add config.InstrumentAttributesGetter to optionally append attrs to latency instrument #334

Merged
merged 4 commits into from
Aug 27, 2024

Conversation

krantideep95
Copy link
Contributor

This allows setting custom attributes from query context onto latency metric, like this:

otelsql.Register(databaseDriver,
	otelsql.WithInstrumentAttributesGetter(func(ctx context.Context, method otelsql.Method, query string, args []driver.NamedValue) []attribute.KeyValue {
	attrs := []attribute.KeyValue{
		semconv.DBNameKey.String(dbName),
	}

	operation, table := parseQuery(query)
	return append(attrs, semconv.DBSQLTableKey.String(table), semconv.DBOperationKey.String(operation))
  }),
)

resolves #333

@krantideep95 krantideep95 requested a review from XSAM as a code owner August 21, 2024 17:21
Copy link

codecov bot commented Aug 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.2%. Comparing base (7fe66d0) to head (918fd50).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##            main    #334     +/-   ##
=======================================
+ Coverage   84.1%   84.2%   +0.1%     
=======================================
  Files         13      13             
  Lines        605     611      +6     
=======================================
+ Hits         509     515      +6     
  Misses        72      72             
  Partials      24      24             

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@krantideep95 krantideep95 force-pushed the add-cfg.InstrumentAttributesGetter branch from 06290a4 to 54e0d55 Compare August 21, 2024 19:32
Copy link
Owner

@XSAM XSAM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krantideep95, thanks for the PR.

It looks good to me overall. Please also update the CHANGELOG.md file to reflect this new feature.

config.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
option.go Outdated Show resolved Hide resolved
@krantideep95 krantideep95 changed the title add config.InstrumentAttributesGetter to optionally append attrs to metrics add config.InstrumentAttributesGetter to optionally append attrs to latency instrument Aug 27, 2024
@krantideep95 krantideep95 requested a review from XSAM August 27, 2024 16:38
@krantideep95
Copy link
Contributor Author

Thanks for the review @XSAM I have updated CHANGELOG.md and accepted your suggestions.

@krantideep95 krantideep95 force-pushed the add-cfg.InstrumentAttributesGetter branch from 34e2731 to 918fd50 Compare August 27, 2024 16:44
Copy link
Owner

@XSAM XSAM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krantideep95 Thank you for the contribution!

@XSAM XSAM merged commit 5fb8ced into XSAM:main Aug 27, 2024
15 checks passed
@XSAM XSAM mentioned this pull request Aug 27, 2024
XSAM added a commit that referenced this pull request Aug 27, 2024
## 0.33.0 - 2024-08-27

### Added

- `WithInstrumentAttributesGetter` option provides additional attributes
when `latency` histogram is recorded. (#334)

### Changed

- Upgrade OTel to version `v1.29.0/v0.51.0`. (#336)
@krantideep95 krantideep95 deleted the add-cfg.InstrumentAttributesGetter branch September 12, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for query specific attributes in latency histogram
2 participants