sentry-go icon indicating copy to clipboard operation
sentry-go copied to clipboard

SetContext is under documented

Open rkuska opened this issue 3 years ago • 0 comments

Summary

SetContext function signature can be improved to make it clear to users that it only accept maps. Unless it is not a case and there is a bug to be fixed.

I searched the repository for usage but it seems the same (the tests are using the same approach as mine above). In online documentation there is a following statement:

The best practice to attach custom data is via structured contexts. A context must always be a dictionary or map, and its values can be arbitrary.

Why the function doesn't have in its signature that it accepts only map[string]interface{} but instead there is interface{}? Current signature seems counter-intuitive.

Also, is there a way to enrich the context under a given key later? Right now the object under the key is being overwritten so the namespace can't be enriched.

Steps To Reproduce

hub := sentry.CurrentHub().Clone()
hub.ConfigureScope(func(scope *sentry.Scope) {
	scope.SetContext("tx_type", batch.ttype)
	scope.SetContext("strategy", batch.strategy)
})
_ = hub.CaptureMessage("Message")

Expected Behavior

Values to be rendered correctly.

Screenshots

Screenshot 2022-03-31 at 16 44 18

Environment

SDK

  • sentry-go version: github.com/getsentry/sentry-go v0.12.0
  • Go version: 1.16
  • Using Go Modules? yes

Sentry

  • Using hosted Sentry in sentry.io? Yes
  • Using your own Sentry installation? Version:
  • Anything particular to your environment that could be related to this issue?

Additional context

rkuska avatar Mar 31 '22 15:03 rkuska