Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

tag: add func MustNewKey to wrap NewKey with panic #1141

Merged
merged 1 commit into from
May 29, 2019

Conversation

dolmen
Copy link
Contributor

@dolmen dolmen commented May 27, 2019

For conveniency when creating tag.Key, provide a Must wrapper of tag.NewKey that panic if the key is invalid: func MustNewKey(name string) Key.

@dolmen dolmen requested review from rakyll, rghetia and a team as code owners May 27, 2019 09:20
@rghetia
Copy link
Contributor

rghetia commented May 28, 2019

@dolmen this wrapper is not useful for most users of the library. Hence it should not be added.

@dolmen
Copy link
Contributor Author

dolmen commented May 29, 2019

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 plugin/ochttp defines its tags:

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")

@rghetia
Copy link
Contributor

rghetia commented May 29, 2019

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 plugin/ochttp defines its tags:

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?.

@rakyll
Copy link
Contributor

rakyll commented May 29, 2019

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.

@rghetia rghetia merged commit 9c37759 into census-instrumentation:master May 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants