-
Notifications
You must be signed in to change notification settings - Fork 15
Add ability to set Global tags using code and environment variables #30
Conversation
@brianashby-sfx - I updated the readme if you want to take a look. |
README.md
Outdated
`SIGNALFX_ACCESS_TOKEN` / [WithAccessToken](https://godoc.org/github.com/signalfx/signalfx-go-tracing/tracing/#WithAccessToken) (no default) | ||
| Code | Environment Variable | Default Value | Notes | | ||
| --- | --- | --- | --- | | ||
| [WithServiceName](https://godoc.org/github.com/signalfx/signalfx-go-tracing/tracing/#WithServiceName) | `SIGNALFX_SERVICE_NAME` | `SignalFx-Tracing` | Name identifying the service as a whole | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use this for the description:
The name of the service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ignoring all circle CI stuff :) but a related Q: since there will be a go.mod for CI isn't better to add it to the project as a whole? Are trying to avoid changes that will conflict with upstream?
tracing/tracing.go
Outdated
@@ -65,16 +94,30 @@ func WithEndpointURL(url string) StartOption { | |||
} | |||
} | |||
|
|||
// WithGlobalTag sets a key/value pair which will be set as a tag on all spans |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// WithGlobalTag sets a key/value pair which will be set as a tag on all spans | |
// WithGlobalTag sets a tag with the given key/value on all spans |
tracing/tracing.go
Outdated
// key1:value1, | ||
func envGlobalTags() []tracer.StartOption { | ||
var globalTags []tracer.StartOption | ||
if val := os.Getenv(signalfxSpanTags); val != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: in golang is more idiomatic to check for val == ""
empty and bail instead of nesting the for inside the if.
tracing/tracing.go
Outdated
if len(pair) == 2 { | ||
key := strings.TrimSpace(pair[0]) | ||
value := strings.TrimSpace(pair[1]) | ||
if key != "" && value != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really necessary to enforce non-empty values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - in testing if the value was empty it would add an entry to the map with the key and the empty value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but having a key with an empty value is different from the key not being present...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it just seem like bad practice to have an empty value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tracers will remove existing tags if they are set w/ an empty value. We definitely shouldn't be using them in zipkin encoding at the least, so this is a good todo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not OTel but fwiw the OTel spec says: "Attribute values expressing a numerical value of zero or an empty string are considered meaningful and MUST be stored and passed on to span processors/exporters. Attribute values of null are considered to be not set and get discarded as if that SetAttribute call had never been made."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm good to know about the spec.
@rmfitzpatrick - do you know which tracers remove tags that are set with empty values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh - so i found this in the zipkin api https://github.com/openzipkin/zipkin-api/blob/master/zipkin-jsonv2.proto#L50-L51
it says that empty values are valid but empty keys are not. Since this is only for the SFx tracer, i'm going to remove the check for value being empty.
README.md
Outdated
| Code | Environment Variable | Default Value | Notes | | ||
| --- | --- | --- | --- | | ||
| [WithServiceName](https://godoc.org/github.com/signalfx/signalfx-go-tracing/tracing/#WithServiceName) | `SIGNALFX_SERVICE_NAME` | `SignalFx-Tracing` | Name identifying the service as a whole | | ||
| [WithEndpointURL](https://godoc.org/github.com/signalfx/signalfx-go-tracing/tracing/#WithEndpointURL) | `SIGNALFX_ENDPOINT_URL` | `http://localhost:9080/v1/trace` | URL to send traces to | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm, can this be a Smart Agent, SignalFx endpoint, or OpenTelemetry Collector? If so, let's specify here.
Suggestion for existing text:
The URL to send traces to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can send it to all of those backends.
README.md
Outdated
| [WithServiceName](https://godoc.org/github.com/signalfx/signalfx-go-tracing/tracing/#WithServiceName) | `SIGNALFX_SERVICE_NAME` | `SignalFx-Tracing` | Name identifying the service as a whole | | ||
| [WithEndpointURL](https://godoc.org/github.com/signalfx/signalfx-go-tracing/tracing/#WithEndpointURL) | `SIGNALFX_ENDPOINT_URL` | `http://localhost:9080/v1/trace` | URL to send traces to | | ||
| [WithAccessToken](https://godoc.org/github.com/signalfx/signalfx-go-tracing/tracing/#WithAccessToken) | `SIGNALFX_ACCESS_TOKEN` | none | | | ||
| [WithGlobalTag](https://godoc.org/github.com/signalfx/signalfx-go-tracing/tracing/#WithGlobalTag) | `SIGNALFX_SPAN_TAGS` | none | If specifying as an environment variable, the format is `key:value` with multiple values separated by commas. Ex.`"a:b, c:d"`| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion for description:
Comma-separated list of tags included in every reported span. For example,
"key1:val1,key2:val2"
.
| [WithAccessToken](https://godoc.org/github.com/signalfx/signalfx-go-tracing/tracing/#WithAccessToken) | `SIGNALFX_ACCESS_TOKEN` | none | | | ||
| [WithGlobalTag](https://godoc.org/github.com/signalfx/signalfx-go-tracing/tracing/#WithGlobalTag) | `SIGNALFX_SPAN_TAGS` | none | If specifying as an environment variable, the format is `key:value` with multiple values separated by commas. Ex.`"a:b, c:d"`| | ||
|
||
Note: The current transport format is Zipkin which only supports string values for tags. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is for SIGNALFX_SPAN_TAGS
, let's move it to the note for that config value.
@pjanotti I pulled in @owais changes to make the tests pass. I'll sync with him tomorrow to see if he has any strong preferences. |
@ccaraman sounds good regarding CircleCI |
// envGlobalTags extract global tags from the environment variable and parses the value in the expected format | ||
// key1:value1, | ||
func envGlobalTags() []tracer.StartOption { | ||
var globalTags []tracer.StartOption |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a good opportunity to tag the library and version by default:
signalfx.tracing.library: "go-tracing"
*
signalfx.tracing.version: someNewConstantWeUpdateWithEachGitTag
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that in a separate PR.
We don't want to add the libraries we instrument as dependencies so other projects that use this library don't need to pull in everything we support. At the same time we need all the dependencies to run unit and integration tests so we keep the go.mod/sum files in .circleci/ directory and copy them to root on CI before running the tests. I think with Go modules, each instrumentation could be an independent Go module. We still wouldn't add the libraries we instrument as deps but it would allow adding other 3rd party libs. I'll think more about it. We should move to Go modules anyway at some point. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to prefer <key>:<value>:
over <key>=<value>
? I think :
is more likely to be in a string than =
. It is often used to separate namespaces and values for example.
Also OpenCensus used the equal to sign for OC_RESOURCE_LABELS which was a very similar feature.
This is what is used in other SFx libraries, but I didn't know about Oc having this feature as well. Let me start a thread offline. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💣
TestEmptyContext
for operation name to besession
.