tag: add func MustNewKey to wrap NewKey with panic#1141
tag: add func MustNewKey to wrap NewKey with panic#1141rghetia merged 1 commit intocensus-instrumentation:masterfrom
Conversation
|
@dolmen this wrapper is not useful for most users of the library. Hence it should not be added. |
|
As an OpenCensus beginner it made sense to me to declare tags as global (const-like) variables, and panicing on tag name validation error appeared to be future proof, especially as OpenCensus is not yet at v1. I now see how var KeyClientMethod, _ = tag.NewKey("http_client_method")Is it the idiom we are supposed to use in external code? This doesn't seem as safe as this: var KeyClientMethod = tag.MustNewKey("http_client_method") |
I agree it is safe to use MustNewKey. In most cases tag Key will be created during init and MustNewKey is more appropriate. However, when tags are received over the wire from remote one should use NewKey as we don't want to raise panic for malformed tags. @rakyll do you have any comments?. |
|
I'm in favor of adding a MustX API. We discussed this before but haven't done it. The current suggested usage where we ignore the error is not ideal. |
For conveniency when creating
tag.Key, provide aMustwrapper oftag.NewKeythat panic if the key is invalid:func MustNewKey(name string) Key.