Allow customization of trace namespace during the entire trace lifetime #1007
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use nif module attribute in Span module
Ensure we use the
@nifmodule attribute everywhere, so that when we test something, to see if the Nif is called, we can actually verify it. I ran into this testing theset_attributefunction calls.Add namespace via attributes
In issue #972 it was reported it was difficult to override the default set namespace because our Absinthe instrumentation also sets the namespace to 'graphql', which is called later than some plugs. We have no 'only set namespace if not already set' logic, because the namespace is always set upon root span creation, so it would be difficult to determine when the namespace value was changed.
In the linked agent PR (private link) we added logic for the Node.js and Python OpenTelemetry integrations to set namespaces with the
appsignal.namespaceandappsignal.namespace_if_nilattributes. https://github.com/appsignal/appsignal-agent/pull/1274This implementation also works for the Elixir integration, because they all use the Span API.
If the
appsignal.namespaceattribute is set, it will use the value as the namespace, overwriting the (default) namespace. If only theappsignal.namespace_if_nilattribute is set, it will use the value as the namespace, overwriting the default namespace. If both are set, it will use theappsignal.namespaceattribute value.Since this uses the internal hoisting mechanism, it means the namespace doesn't need to be set on the root span, but any span in the trace will work. Not sure if we want to update the docs on this, or just keep recommending to use the
Span.set_namespacehelper on the root span.The Absinthe instrumentation (and potentially others) need to be updated to use the
set_namespace_if_nilhelper so that it is easier to overwrite the namespace for our users.Allow customization of Absinthe trace namespace
Previously, it was not possible to customize the namespace of an Absinthe trace as detailed in issue #972. This was because the plug that set the namespace was run before our Absinthe instrumentation, which would then overwrite the namespace again.
We now use the new
Span.set_namespace_if_nilhelper in our Absinthe instrumentation, so that it only set the namespace from the instrumentation if it's not already set by the app (using theSpan.set_namespacehelper).Closes #972